From b38b3c7e598dd22e54d3a6290950aa345966e053 Mon Sep 17 00:00:00 2001 From: "JESUS D. GARCIA" Date: Wed, 11 Sep 2024 18:40:31 -0500 Subject: [PATCH 1/2] * Update the Procedure push docker images workflow file * Handle the build process exit code properly --- .../Procedure_push_docker_images.yml | 98 +++++++++++++++++-- build-docker-images/build-images.sh | 2 +- 2 files changed, 90 insertions(+), 10 deletions(-) diff --git a/.github/workflows/Procedure_push_docker_images.yml b/.github/workflows/Procedure_push_docker_images.yml index 7f7bb30d..4dc4d0d4 100644 --- a/.github/workflows/Procedure_push_docker_images.yml +++ b/.github/workflows/Procedure_push_docker_images.yml @@ -1,22 +1,17 @@ - run-name: Launch Push Docker Images - Executed by @${{ github.actor }} name: Push Docker Images on: workflow_dispatch: inputs: - JENKINS_REFERENCE: - description: 'wazuh-jenkins reference' - required: true - default: 'master' IMAGE_TAG: description: 'Docker image tag' - required: true default: '4.10.0' + required: true DOCKER_REFERENCE: description: 'wazuh-docker reference' + default: 'v4.10.0' required: true - default: '4.10.0' PRODUCTS: description: 'Comma-separated list of the image names to build and push' default: 'wazuh-manager,wazuh-dashboard,wazuh-indexer' @@ -26,9 +21,94 @@ on: required: true REVISION: description: 'Package revision' + default: '1' required: true PUSH_IMAGES: description: 'Push images' - required: true type: boolean - default: true \ No newline at end of file + default: true + required: true + +jobs: + build-and-push: + runs-on: ubuntu-latest + + steps: + - name: Print inputs + run: | + echo "---------------------------------------------" + echo "Running Procedure_push_docker_images workflow" + echo "---------------------------------------------" + echo "* BRANCH: ${{ github.ref }}" + echo "* COMMIT: ${{ github.sha }}" + echo "---------------------------------------------" + echo "Inputs provided:" + echo "---------------------------------------------" + echo "* IMAGE_TAG: ${{ inputs.IMAGE_TAG }}" + echo "* DOCKER_REFERENCE: ${{ inputs.DOCKER_REFERENCE }}" + echo "* PRODUCTS: ${{ inputs.PRODUCTS }}" + echo "* FILEBEAT_MODULE_VERSION: ${{ inputs.FILEBEAT_MODULE_VERSION }}" + echo "* REVISION: ${{ inputs.REVISION }}" + echo "* PUSH_IMAGES: ${{ inputs.PUSH_IMAGES }}" + echo "---------------------------------------------" + + - name: Checkout repository + uses: actions/checkout@v4 + with: + ref: ${{ inputs.DOCKER_REFERENCE }} + + - name: Log in to Docker Hub + uses: docker/login-action@v3 + with: + username: wazuh + password: ${{ secrets.DOCKERHUB_PASSWORD }} + + - name: Install Docker Compose + run: | + sudo apt-get update + sudo apt-get install -y docker-compose + echo "Installed Docker Compose version: $(docker-compose --version)" + + - name: Build Wazuh images + run: | + IMAGE_TAG=${{ inputs.IMAGE_TAG }} + FILEBEAT_MODULE_VERSION=${{ inputs.FILEBEAT_MODULE_VERSION }} + REVISION=${{ inputs.REVISION }} + PUSH_IMAGES=${{ inputs.PUSH_IMAGES }} + + if [[ "$IMAGE_TAG" == *"-"* ]]; then + IFS='-' read -r -a tokens <<< "$IMAGE_TAG" + if [ -z "${tokens[1]}" ]; then + echo "Invalid image tag: $IMAGE_TAG" + exit 1 + fi + DEV_STAGE=${tokens[1]} + WAZUH_VER=${tokens[0]} + ./build-docker-images/build-images.sh -v $WAZUH_VER -r $REVISION -d $DEV_STAGE -f $FILEBEAT_MODULE_VERSION + else + ./build-docker-images/build-images.sh -v $IMAGE_TAG -r $REVISION -f $FILEBEAT_MODULE_VERSION + fi + + ENV_FILE_PATH=".env" + # Save .env file contents to $GITHUB_ENV + if [ -f $ENV_FILE_PATH ]; then + while IFS= read -r line || [ -n "$line" ]; do + echo "$line" >> $GITHUB_ENV + done < $ENV_FILE_PATH + else + echo "The environment file $ENV_FILE_PATH does not exist!" + exit 1 + fi + + + - name: Tag and Push Wazuh images + if: ${{ inputs.PUSH_IMAGES }} + run: | + IMAGE_TAG=${{ inputs.IMAGE_TAG }} + IMAGE_NAMES=${{ inputs.PRODUCTS }} + IFS=',' read -r -a images <<< "$IMAGE_NAMES" + for image in "${images[@]}"; do + echo "Tagging and pushing wazuh/$image:${WAZUH_VERSION} to wazuh/$image:$IMAGE_TAG" + docker tag wazuh/$image:${WAZUH_VERSION} wazuh/$image:$IMAGE_TAG + docker push wazuh/$image:$IMAGE_TAG + done \ No newline at end of file diff --git a/build-docker-images/build-images.sh b/build-docker-images/build-images.sh index e37066a7..6a7b3f8a 100755 --- a/build-docker-images/build-images.sh +++ b/build-docker-images/build-images.sh @@ -70,7 +70,7 @@ build() { echo WAZUH_FILEBEAT_MODULE=$WAZUH_FILEBEAT_MODULE >> .env echo WAZUH_UI_REVISION=$WAZUH_UI_REVISION >> .env - docker-compose -f build-docker-images/build-images.yml --env-file .env build --no-cache + docker-compose -f build-docker-images/build-images.yml --env-file .env build --no-cache || clean 1 return 0 } From 471aedae5b926c86e7144c10c151da5cc54c5ee4 Mon Sep 17 00:00:00 2001 From: "JESUS D. GARCIA" Date: Fri, 13 Sep 2024 11:15:04 -0500 Subject: [PATCH 2/2] Update changelog --- .github/workflows/Procedure_push_docker_images.yml | 2 +- CHANGELOG.md | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/Procedure_push_docker_images.yml b/.github/workflows/Procedure_push_docker_images.yml index 4dc4d0d4..79a813df 100644 --- a/.github/workflows/Procedure_push_docker_images.yml +++ b/.github/workflows/Procedure_push_docker_images.yml @@ -111,4 +111,4 @@ jobs: echo "Tagging and pushing wazuh/$image:${WAZUH_VERSION} to wazuh/$image:$IMAGE_TAG" docker tag wazuh/$image:${WAZUH_VERSION} wazuh/$image:$IMAGE_TAG docker push wazuh/$image:$IMAGE_TAG - done \ No newline at end of file + done diff --git a/CHANGELOG.md b/CHANGELOG.md index 36a4abe8..6e268497 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ All notable changes to this project will be documented in this file. ## Wazuh Docker v4.10.0 ### Added +- Migrate the push docker images procedure to GitHub Actions ([#5651](https://github.com/wazuh/wazuh-qa/issues/5651)) - Update Wazuh to version [4.10.0](https://github.com/wazuh/wazuh/blob/v4.10.0/CHANGELOG.md#v4100) ## Wazuh Docker v4.9.1