From 227bf4afd433cb010e13cbbac62e5a655a71107d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20S=C3=A1nchez?= Date: Fri, 14 Feb 2025 12:18:18 +0100 Subject: [PATCH] Migrate /docker to /build-scripts and delete unused files (#684) * Changed the references from the /docker directory to /build-scripts, relocated /docker/builder to /build-scripts/builder and /docker/prod to /build-scripts/docker, and deleted /docker/dev and /docker/readme.md * Included the content of the file /docker/README.md into /build-scripts/README.md, along with minor modifications to fix errors. * Add new line at end of file on builder/compose.yml Signed-off-by: Kevin Ledesma * Update build-scripts/README.md --------- Signed-off-by: Kevin Ledesma Co-authored-by: Kevin Ledesma Co-authored-by: Alex Ruiz --- .github/workflows/build-push-docker-image.yml | 2 +- build-scripts/README.md | 42 ++++++++++-- build-scripts/build-and-push-docker-image.sh | 7 +- .../builder/.dockerignore | 0 {docker => build-scripts}/builder/Dockerfile | 2 +- {docker => build-scripts}/builder/builder.sh | 2 +- {docker => build-scripts}/builder/compose.yml | 2 +- .../builder/entrypoint.sh | 0 .../prod => build-scripts/docker}/Dockerfile | 0 .../docker}/config/config.sh | 0 .../docker}/config/config.yml | 0 .../docker}/config/opensearch.yml | 0 .../docker}/config/securityadmin.sh | 0 .../docker}/entrypoint.sh | 0 docker/README.md | 62 ----------------- docker/dev/dev.sh | 60 ---------------- docker/dev/dev.yml | 17 ----- docker/dev/images/.dockerignore | 68 ------------------- docker/dev/images/Dockerfile | 20 ------ 19 files changed, 44 insertions(+), 240 deletions(-) rename {docker => build-scripts}/builder/.dockerignore (100%) rename {docker => build-scripts}/builder/Dockerfile (98%) rename {docker => build-scripts}/builder/builder.sh (98%) rename {docker => build-scripts}/builder/compose.yml (92%) rename {docker => build-scripts}/builder/entrypoint.sh (100%) rename {docker/prod => build-scripts/docker}/Dockerfile (100%) rename {docker/prod => build-scripts/docker}/config/config.sh (100%) rename {docker/prod => build-scripts/docker}/config/config.yml (100%) rename {docker/prod => build-scripts/docker}/config/opensearch.yml (100%) rename {docker/prod => build-scripts/docker}/config/securityadmin.sh (100%) rename {docker/prod => build-scripts/docker}/entrypoint.sh (100%) delete mode 100644 docker/README.md delete mode 100755 docker/dev/dev.sh delete mode 100644 docker/dev/dev.yml delete mode 100644 docker/dev/images/.dockerignore delete mode 100644 docker/dev/images/Dockerfile diff --git a/.github/workflows/build-push-docker-image.yml b/.github/workflows/build-push-docker-image.yml index b384775503ba8..02ac7c1dafdcf 100644 --- a/.github/workflows/build-push-docker-image.yml +++ b/.github/workflows/build-push-docker-image.yml @@ -93,7 +93,7 @@ jobs: needs: [call-build-workflow] runs-on: ubuntu-24.04 env: - docker_path: ./docker/prod + docker_path: ./build-scripts/docker steps: - uses: actions/checkout@v4 diff --git a/build-scripts/README.md b/build-scripts/README.md index 05667c31a0e85..908b5ea4cf642 100644 --- a/build-scripts/README.md +++ b/build-scripts/README.md @@ -16,9 +16,24 @@ The process to build packages requires Docker and Docker Compose. Before you get started, make sure to clean your environment by running `./gradlew clean`. +## Pre-requisites + +1. Install [Docker](https://docs.docker.com/engine/install/) as per its instructions. + +2. Your workstation must meet the minimum hardware requirements: + + - 8 GB of RAM (minimum) + - 4 cores + + The more resources the better ☺ + +3. Clone the [wazuh-indexer](https://github.com/wazuh/wazuh-indexer). + ## Building wazuh-indexer packages -Use the script under `wazuh-indexer/docker/builder/builder.sh` to build a package. +The `builder` image automates the build and assemble process for the Wazuh Indexer and its plugins, making it easy to create packages on any system. + +Use the script under `wazuh-indexer/build-scripts/builder/builder.sh` to build a package. ```bash ./builder.sh -h @@ -35,15 +50,34 @@ Arguments: -h Print help ``` +The example below it will generate a wazuh-indexer package for Debian based systems, for the x64 architecture, using 1 as revision number and using the production naming convention. + +```bash +# Wihtin wazuh-indexer/build-scripts/builder +bash builder.sh -d deb -a x64 -R 1 -s true +``` + The resulting package will be stored at `wazuh-indexer/artifacts/dist`. > The `STAGE` option defines the naming of the package. When set to `false`, the package will be unequivocally named with the commits' SHA of the `wazuh-indexer`, `wazuh-indexer-plugins` and `wazuh-indexer-reporting` repositories, in that order. For example: `wazuh-indexer_5.0.0-0_x86_64_aff30960363-846f143-494d125.rpm`. ## Building wazuh-indexer Docker images -The `build-and-push-docker-image.sh` script automates the process to build and push Wazuh Indexer Docker images to our repository in quay.io. The script takes serveral parameters. Use the `-h` option to display them. +The [docker](./docker) folder contains the code to build Docker images. Below there is an example of the command needed to build the image. Set the build arguments and the image tag accordingly. + +The Docker image is built from a wazuh-indexer tarball (tar.gz), which must be present in the same folder as the Dockerfile in `wazuh-indexer/build-scripts/docker`. + +```bash +docker build --build-arg="VERSION=5.0.0" --build-arg="INDEXER_TAR_NAME=wazuh-indexer_5.0.0-0_linux-x64.tar.gz" --tag=wazuh-indexer:5.0.0-0 --progress=plain --no-cache . +``` -The Docker image is built from a wazuh-indexer tarball (tar.gz), which must be present in the same folder as the Dockerfile in `wazuh-indexer/docker/prod`. +Then, start a container with: + +```bash +docker run -p 9200:9200 -it --rm wazuh-indexer:5.0.0-0 +``` + +The `build-and-push-docker-image.sh` script automates the process to build and push Wazuh Indexer Docker images to our repository in quay.io. The script takes serveral parameters. Use the `-h` option to display them. To push images, credentials must be set at environment level: @@ -62,5 +96,3 @@ Arguments: The script will stop if the credentials are not set, or if any of the required parameters are not provided. This script is used in the `build-push-docker-image.yml` **GitHub Workflow**, which is used to automate the process even more. When possible, **prefer this method**. - -For manual building refer to [our Docker containers guide](../docker/README.md). diff --git a/build-scripts/build-and-push-docker-image.sh b/build-scripts/build-and-push-docker-image.sh index 9897eb674d992..a2083e47e6d81 100644 --- a/build-scripts/build-and-push-docker-image.sh +++ b/build-scripts/build-and-push-docker-image.sh @@ -2,9 +2,8 @@ # This script builds and pushes wazuh-indexer docker images to the quay.io registry. # The Docker image is built from a wazuh-indexer tarball (tar.gz), which must be -# present in the same folder as the Dockerfile in wazuh-indexer/docker/prod. -# For addtional information, read these documents: -# - wazuh-indexer/docker/README.md +# present in the same folder as the Dockerfile in wazuh-indexer/build-scripts/docker. +# For addtional information, read this document: # - wazuh-indexer/build-scripts/README.md # # To push images, credentials must be set at environment level: @@ -98,7 +97,7 @@ function main() { docker login -u="${QUAY_USERNAME}" -p="${QUAY_TOKEN}" "${DOCKER_REGISTRY}" # Build the Docker image. - local dockerfile_path="docker/prod" + local dockerfile_path="build-scripts/docker" cd ${dockerfile_path} docker build \ --build-arg="VERSION=${VERSION}" \ diff --git a/docker/builder/.dockerignore b/build-scripts/builder/.dockerignore similarity index 100% rename from docker/builder/.dockerignore rename to build-scripts/builder/.dockerignore diff --git a/docker/builder/Dockerfile b/build-scripts/builder/Dockerfile similarity index 98% rename from docker/builder/Dockerfile rename to build-scripts/builder/Dockerfile index 2e1c5051e926b..1bed09ba3883d 100644 --- a/docker/builder/Dockerfile +++ b/build-scripts/builder/Dockerfile @@ -80,7 +80,7 @@ RUN mkdir -p /repositories/wazuh-indexer-plugins && \ chown wazuh-indexer:wazuh-indexer /repositories/wazuh-indexer-reporting # Copy your build scripts into the container as root -COPY docker/builder/entrypoint.sh / +COPY build-scripts/builder/entrypoint.sh / # Change file permissions as root RUN chmod +x /entrypoint.sh diff --git a/docker/builder/builder.sh b/build-scripts/builder/builder.sh similarity index 98% rename from docker/builder/builder.sh rename to build-scripts/builder/builder.sh index 759ee2f449dc6..6136da238542e 100755 --- a/docker/builder/builder.sh +++ b/build-scripts/builder/builder.sh @@ -97,7 +97,7 @@ function usage() { # ==== function main() { check_project_root_folder $0 - compose_file="docker/${current}/compose.yml" + compose_file="build-scripts/${current}/compose.yml" compose_cmd="docker compose -f $compose_file" REPO_PATH=$(pwd) VERSION=$(cat VERSION) diff --git a/docker/builder/compose.yml b/build-scripts/builder/compose.yml similarity index 92% rename from docker/builder/compose.yml rename to build-scripts/builder/compose.yml index d14d7a3c8b0ee..7e7af98334bd8 100644 --- a/docker/builder/compose.yml +++ b/build-scripts/builder/compose.yml @@ -4,7 +4,7 @@ services: container_name: wazuh-indexer-builder_${VERSION} build: context: ./../.. - dockerfile: ${REPO_PATH}/docker/builder/Dockerfile + dockerfile: ${REPO_PATH}/build-scripts/builder/Dockerfile environment: - INDEXER_PLUGINS_BRANCH=${INDEXER_PLUGINS_BRANCH:-main} - INDEXER_REPORTING_BRANCH=${INDEXER_REPORTING_BRANCH:-main} diff --git a/docker/builder/entrypoint.sh b/build-scripts/builder/entrypoint.sh similarity index 100% rename from docker/builder/entrypoint.sh rename to build-scripts/builder/entrypoint.sh diff --git a/docker/prod/Dockerfile b/build-scripts/docker/Dockerfile similarity index 100% rename from docker/prod/Dockerfile rename to build-scripts/docker/Dockerfile diff --git a/docker/prod/config/config.sh b/build-scripts/docker/config/config.sh similarity index 100% rename from docker/prod/config/config.sh rename to build-scripts/docker/config/config.sh diff --git a/docker/prod/config/config.yml b/build-scripts/docker/config/config.yml similarity index 100% rename from docker/prod/config/config.yml rename to build-scripts/docker/config/config.yml diff --git a/docker/prod/config/opensearch.yml b/build-scripts/docker/config/opensearch.yml similarity index 100% rename from docker/prod/config/opensearch.yml rename to build-scripts/docker/config/opensearch.yml diff --git a/docker/prod/config/securityadmin.sh b/build-scripts/docker/config/securityadmin.sh similarity index 100% rename from docker/prod/config/securityadmin.sh rename to build-scripts/docker/config/securityadmin.sh diff --git a/docker/prod/entrypoint.sh b/build-scripts/docker/entrypoint.sh similarity index 100% rename from docker/prod/entrypoint.sh rename to build-scripts/docker/entrypoint.sh diff --git a/docker/README.md b/docker/README.md deleted file mode 100644 index 6d319cd1d1924..0000000000000 --- a/docker/README.md +++ /dev/null @@ -1,62 +0,0 @@ -# Docker environments - -Multipurpose Docker environments to run, test and build `wazuh-indexer`. - -## Pre-requisites - -1. Install [Docker][docker] as per its instructions. - -2. Your workstation must meet the minimum hardware requirements: - - - 8 GB of RAM (minimum) - - 4 cores - - The more resources the better ☺ - -3. Clone the [wazuh-indexer][wi-repo]. - -## Development environments - -Use the `dev/dev.sh` script to start a development environment. - -Example: - -```bash -Usage: ./dev.sh {up|down|stop} -``` - -Once the `wi-dev:x.y.z` container is up, attach a shell to it and run `./gradlew run` to start the application. - -## Containers to generate packages - -The `builder` image automates the build and assemble process for the Wazuh Indexer and its plugins, making it easy to create packages on any system. - -In the example below, it will generate a wazuh-indexer package for Debian based systems, for the x64 architecture, using 1 as revision number and using the production naming convention. - -```bash -# Wihtin wazu-indexer/docker/builder -bash builder.sh -d deb -a x64 -R 1 -s true -``` - -Refer to [build-scripts/README.md](../build-scripts/README.md) for details about how to build packages. - -## Building Docker images - -The [prod](./prod) folder contains the code to build Docker images. A tarball of `wazuh-indexer` needs to be located at the same level that the Dockerfile. Below there is an example of the command needed to build the image. Set the build arguments and the image tag accordingly. - -```bash -docker build --build-arg="VERSION=5.0.0" --build-arg="INDEXER_TAR_NAME=wazuh-indexer_5.0.0-0_linux-x64.tar.gz" --tag=wazuh-indexer:5.0.0-0 --progress=plain --no-cache . -``` - -Then, start a container with: - -```bash -docker run -p 9200:9200 -it --rm quay.io/wazuh/wazuh-indexer:5.0.0-latest -``` - -Refer to [build-scripts/README.md](../build-scripts/README.md) for details about how to build and push Wazuh Indexer Docker images. - - - -[docker]: https://docs.docker.com/engine/install -[wi-repo]: https://github.com/wazuh/wazuh-indexer diff --git a/docker/dev/dev.sh b/docker/dev/dev.sh deleted file mode 100755 index f20b7359c9206..0000000000000 --- a/docker/dev/dev.sh +++ /dev/null @@ -1,60 +0,0 @@ -#!/bin/bash - -# Attaches the project as a volume to a JDK 17 container -# Requires Docker -# Script usage: bash ./dev.sh - -set -e - -# ==== -# Checks that the script is run from the intended location -# ==== -function check_project_root_folder() { - current=$(basename "$(pwd)") - - if [[ "$0" != "./dev.sh" && "$0" != "dev.sh" ]]; then - echo "Run the script from its location" - usage - exit 1 - fi - # Change working directory to the root of the repository - cd ../.. -} - -# ==== -# Displays usage -# ==== -function usage() { - echo "Usage: ./dev.sh {up|down|stop}" -} - -# ==== -# Main function -# ==== -function main() { - check_project_root_folder "$@" - compose_file="docker/${current}/dev.yml" - compose_cmd="docker compose -f $compose_file" - REPO_PATH=$(pwd) - VERSION=$(cat VERSION) - export REPO_PATH - export VERSION - - case $1 in - up) - $compose_cmd up -d - ;; - down) - $compose_cmd down - ;; - stop) - $compose_cmd stop - ;; - *) - usage - exit 1 - ;; - esac -} - -main "$@" diff --git a/docker/dev/dev.yml b/docker/dev/dev.yml deleted file mode 100644 index b485c66f8fc71..0000000000000 --- a/docker/dev/dev.yml +++ /dev/null @@ -1,17 +0,0 @@ -services: - wi-dev: - image: wi-dev:${VERSION} - container_name: wi-dev_${VERSION} - build: - context: ${REPO_PATH} - dockerfile: ${REPO_PATH}/docker/dev/images/Dockerfile - ports: - # OpenSearch REST API - - 9200:9200 - expose: - - 9200 - volumes: - - ${REPO_PATH}:/home/wazuh-indexer - entrypoint: ["tail", "-f", "/dev/null"] - user: "1000:1000" - working_dir: /home/wazuh-indexer diff --git a/docker/dev/images/.dockerignore b/docker/dev/images/.dockerignore deleted file mode 100644 index 96d12ad527ea5..0000000000000 --- a/docker/dev/images/.dockerignore +++ /dev/null @@ -1,68 +0,0 @@ -artifacts/ -.git/ - -# intellij files -.idea/ -*.iml -*.ipr -*.iws -build-idea/ -out/ - -# include shared intellij config -!.idea/inspectionProfiles/Project_Default.xml -!.idea/runConfigurations/Debug_OpenSearch.xml -!.idea/vcs.xml - -# These files are generated in the main tree by annotation processors -benchmarks/src/main/generated/* -benchmarks/bin/* -benchmarks/build-eclipse-default/* -server/bin/* -server/build-eclipse-default/* -test/framework/build-eclipse-default/* - -# eclipse files -.project -.classpath -.settings -build-eclipse/ - -# netbeans files -nb-configuration.xml -nbactions.xml - -# gradle stuff -.gradle/ -build/ - -# vscode stuff -.vscode/ - -# testing stuff -**/.local* -.vagrant/ -/logs/ - -# osx stuff -.DS_Store - -# default folders in which the create_bwc_index.py expects to find old es versions in -/backwards -/dev-tools/backwards - -# needed in case docs build is run...maybe we can configure doc build to generate files under build? -html_docs - -# random old stuff that we should look at the necessity of... -/tmp/ -eclipse-build - -# projects using testfixtures -testfixtures_shared/ - -# These are generated from .ci/jobs.t -.ci/jobs/ - -# build files generated -doc-tools/missing-doclet/bin/ \ No newline at end of file diff --git a/docker/dev/images/Dockerfile b/docker/dev/images/Dockerfile deleted file mode 100644 index e34202688c492..0000000000000 --- a/docker/dev/images/Dockerfile +++ /dev/null @@ -1,20 +0,0 @@ -FROM gradle:8.7.0-jdk21-alpine AS builder -USER gradle -WORKDIR /home/wazuh-indexer -COPY --chown=gradle:gradle . /home/wazuh-indexer -RUN gradle clean - - -FROM eclipse-temurin:21-jdk-alpine -RUN apk add git && \ - apk add curl && \ - apk add bash && \ - addgroup -g 1000 wazuh-indexer && \ - adduser -u 1000 -G wazuh-indexer -D -h /home/wazuh-indexer wazuh-indexer && \ - chmod 0775 /home/wazuh-indexer && \ - chown -R 1000:0 /home/wazuh-indexer -USER wazuh-indexer -COPY --from=builder --chown=1000:0 /home/wazuh-indexer /home/wazuh-indexer -WORKDIR /home/wazuh-indexer -RUN git config --global --add safe.directory /home/wazuh-indexer -EXPOSE 9200 9300