From b80f99dad349509dfb95c159c24988e130862f69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lex=20Ruiz?= Date: Wed, 29 Nov 2023 15:45:23 +0100 Subject: [PATCH] Update Docker environment - Remove build.md which was included by mistake. - Improve dev.sh script. - Update .gitignore to exclude artifacts folder. - Create .dockerignore file. - Replace get_version.sh script with inline command. - Reduce image size by using alpine as base image. --- .gitignore | 1 + docker/dev.sh | 40 ++++++++---- docker/get_version.sh | 5 -- docker/images/.dockerignore | 67 ++++++++++++++++++++ docker/images/wi-dev.Dockerfile | 6 +- scripts/build.md | 104 -------------------------------- 6 files changed, 99 insertions(+), 124 deletions(-) delete mode 100755 docker/get_version.sh create mode 100644 docker/images/.dockerignore delete mode 100644 scripts/build.md diff --git a/.gitignore b/.gitignore index 82914fb4fc1e7..058a889d5f239 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +artifacts/ # intellij files .idea/ diff --git a/docker/dev.sh b/docker/dev.sh index 3e67ce3fdf39c..991ed42de29e7 100755 --- a/docker/dev.sh +++ b/docker/dev.sh @@ -2,41 +2,57 @@ # Attaches the project as a volume to a JDK 17 container # Requires Docker -# Script usage: bash ./docker.sh +# Script usage: bash ./dev.sh set -e -# Change working directory to the root of the repository -cd "${0%/*}/.." +# ==== +# Checks that the script is run from the intended location +# ==== +function check_project_root_folder () { + 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 # ==== -main() { - COMPOSE_FILE=docker/dev.yml +function main() { + check_project_root_folder "$@" + compose_file=docker/dev.yml + compose_cmd="docker compose -f $compose_file" REPO_PATH=$(pwd) - VERSION=$(bash "$REPO_PATH/docker/get_version.sh") - COMPOSE_CMD="docker compose -f $COMPOSE_FILE" + VERSION=$(cat VERSION) export REPO_PATH export VERSION case $1 in up) - $COMPOSE_CMD up -d + $compose_cmd up -d ;; down) - $COMPOSE_CMD down + $compose_cmd down ;; stop) - $COMPOSE_CMD stop + $compose_cmd stop ;; *) - echo "Usage: $0 {up|down|stop} [security]" + usage exit 1 ;; esac } - main "$@" \ No newline at end of file diff --git a/docker/get_version.sh b/docker/get_version.sh deleted file mode 100755 index 1e2efae9e9d3e..0000000000000 --- a/docker/get_version.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash - -set -e - -cat VERSION \ No newline at end of file diff --git a/docker/images/.dockerignore b/docker/images/.dockerignore new file mode 100644 index 0000000000000..058a889d5f239 --- /dev/null +++ b/docker/images/.dockerignore @@ -0,0 +1,67 @@ +artifacts/ + +# 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/images/wi-dev.Dockerfile b/docker/images/wi-dev.Dockerfile index 9ffcfdc6ca9b1..7e7f16fbba42c 100644 --- a/docker/images/wi-dev.Dockerfile +++ b/docker/images/wi-dev.Dockerfile @@ -5,9 +5,9 @@ COPY --chown=gradle:gradle . /home/wazuh-indexer/app RUN gradle clean -FROM eclipse-temurin:17 -RUN groupadd -g 1000 wazuh-indexer && \ - adduser --uid 1000 --gid 1000 --home /home/wazuh-indexer wazuh-indexer && \ +FROM eclipse-temurin:17-jdk-alpine +RUN 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 diff --git a/scripts/build.md b/scripts/build.md deleted file mode 100644 index b862db746ba4b..0000000000000 --- a/scripts/build.md +++ /dev/null @@ -1,104 +0,0 @@ - -Lista Build: - - PR Dockerfile - - Hacer script (builder + runner) - - PR GH Action - - Actualizar jvm.prod.options - - Añadir VERSION - - Nombre de paquetes - -Posible problema: - el build min llama a la carpeta de seguridad `security`, pero en los - paquete de producción se llama `opensearch-security`. A resolver en `Assembly` - - -```bash -bash scripts/build.sh -v 2.11.0 -s false -p linux -a x64 -d rpm -``` - -Deja los paquetes en `artifacts/` - -```bash -Usage: scripts/build.sh [args] - - -Arguments: --v VERSION [Required] OpenSearch version. --q QUALIFIER [Optional] Version qualifier. --s SNAPSHOT [Optional] Build a snapshot, default is 'false'. --p PLATFORM [Optional] Platform, default is 'uname -s'. --a ARCHITECTURE [Optional] Build architecture, default is 'uname -m'. --d DISTRIBUTION [Optional] Distribution, default is 'tar'. --o OUTPUT [Optional] Output path, default is 'artifacts'. --h help -``` - - -Soporte: - -```bash - linux-tar-x64|darwin-tar-x64) - PACKAGE="tar" - EXT="tar.gz" - TYPE="archives" - TARGET="$PLATFORM-$PACKAGE" - SUFFIX="$PLATFORM-x64" - ;; - linux-tar-arm64|darwin-tar-arm64) - PACKAGE="tar" - EXT="tar.gz" - TYPE="archives" - TARGET="$PLATFORM-arm64-$PACKAGE" - SUFFIX="$PLATFORM-arm64" - ;; - linux-deb-x64) - PACKAGE="deb" - EXT="deb" - TYPE="packages" - TARGET="deb" - SUFFIX="amd64" - ;; - linux-deb-arm64) - PACKAGE="deb" - EXT="deb" - TYPE="packages" - TARGET="arm64-deb" - SUFFIX="arm64" - ;; - linux-rpm-x64) - PACKAGE="rpm" - EXT="rpm" - TYPE="packages" - TARGET="rpm" - SUFFIX="x86_64" - ;; - linux-rpm-arm64) - PACKAGE="rpm" - EXT="rpm" - TYPE="packages" - TARGET="arm64-rpm" - SUFFIX="aarch64" - ;; - windows-zip-x64) - PACKAGE="zip" - EXT="zip" - TYPE="archives" - TARGET="$PLATFORM-$PACKAGE" - SUFFIX="$PLATFORM-x64" - ;; - windows-zip-arm64) - PACKAGE="zip" - EXT="zip" - TYPE="archives" - TARGET="$PLATFORM-arm64-$PACKAGE" - SUFFIX="$PLATFORM-arm64" -``` - - -Probando workflow en act: - -``` -act -j build -W .github/workflows/build.yml --artifact-server-path ./artifacts - -[Build slim packages/build] 🏁 Job succeeded -``` \ No newline at end of file