From 74889ad91c71163ac9cb0ec3aa3f2e6fcd397d2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Correa=20Rodr=C3=ADguez?= Date: Tue, 24 Sep 2024 15:41:30 +0200 Subject: [PATCH 01/11] Adapted repository selection in local build --- ova/generate_ova.sh | 6 ------ ova/provision.sh | 6 ++++++ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/ova/generate_ova.sh b/ova/generate_ova.sh index 49c5463..71f9148 100755 --- a/ova/generate_ova.sh +++ b/ova/generate_ova.sh @@ -231,12 +231,6 @@ main() { WAZUH_INSTALLATION_ASSISTANT_URL="https://github.com/wazuh/${WAZUH_INSTALLATION_ASSISTANT}.git" BUILDER_ARGS="-i" - if [[ "${PACKAGES_REPOSITORY}" == "dev" ]]; then - BUILDER_ARGS+=" -d" - elif [[ "${PACKAGES_REPOSITORY}" == "staging" ]]; then - BUILDER_ARGS+=" -d staging" - fi - echo "Building Wazuh OVA version ${OVA_VERSION}" if git ls-remote ${REMOTE_TYPE} ${WAZUH_INSTALLATION_ASSISTANT_URL} ${INSTALLATION_ASSISTANT_BRANCH} | grep -q "${INSTALLATION_ASSISTANT_BRANCH}"; then echo "Cloning Wazuh installation assistant repository" diff --git a/ova/provision.sh b/ova/provision.sh index e91f873..b4118fa 100755 --- a/ova/provision.sh +++ b/ova/provision.sh @@ -13,6 +13,12 @@ ASSETS_PATH="${CURRENT_PATH}/assets" CUSTOM_PATH="${ASSETS_PATH}/custom" INSTALL_ARGS="-a" +if [[ "${PACKAGES_REPOSITORY}" == "dev" ]]; then + INSTALL_ARGS+=" -d pre-release" +elif [[ "${PACKAGES_REPOSITORY}" == "staging" ]]; then + INSTALL_ARGS+=" -d staging" +fi + if [[ "${DEBUG}" = "yes" ]]; then INSTALL_ARGS+=" -v" fi From 8e1677d5ba61b0d60bbd2766b57bb4f0723ce907 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Correa=20Rodr=C3=ADguez?= Date: Tue, 24 Sep 2024 15:46:15 +0200 Subject: [PATCH 02/11] Adapted repository selection in workflow build --- .github/workflows/builder_OVA.yaml | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/.github/workflows/builder_OVA.yaml b/.github/workflows/builder_OVA.yaml index 8d38478..b3f672c 100644 --- a/.github/workflows/builder_OVA.yaml +++ b/.github/workflows/builder_OVA.yaml @@ -159,13 +159,7 @@ jobs: - name: Run Ansible playbook to generate the OVA run: | - if [ "${{ inputs.WAZUH_PACKAGE_REPOSITORY }}" == "prod" ]; then - builder_args="-i" - elif [ "${{ inputs.WAZUH_PACKAGE_REPOSITORY }}" == "staging" ]; then - builder_args="-i -d staging" - elif [ "${{ inputs.WAZUH_PACKAGE_REPOSITORY }}" == "dev" ]; then - builder_args="-i -d" - fi + builder_args="-i" ansible-playbook -i ${{ env.INVENTORY_PATH }}/inventory .github/workflows/ansible_playbooks/ova_generator.yaml \ --extra-vars " \ wia_branch=${{ inputs.WAZUH_INSTALLATION_ASSISTANT_REFERENCE }} \ From d0c9e8d43cd611e6759b491609927d9e0dfe870e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Correa=20Rodr=C3=ADguez?= Date: Tue, 24 Sep 2024 15:51:27 +0200 Subject: [PATCH 03/11] Deleted WAZUH_VIRTUAL_MACHINES_REFERENCE parameter --- .github/workflows/builder_OVA.yaml | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/.github/workflows/builder_OVA.yaml b/.github/workflows/builder_OVA.yaml index b3f672c..e6418d7 100644 --- a/.github/workflows/builder_OVA.yaml +++ b/.github/workflows/builder_OVA.yaml @@ -1,13 +1,9 @@ -run-name: Build OVA - Wazuh virtual machines branch ${{ inputs.WAZUH_VIRTUAL_MACHINES_REFERENCE }} - Launched by @${{ github.actor }} +run-name: Build OVA - Wazuh virtual machines branch ${{ github.ref_name }} - Launched by @${{ github.actor }} name: Build OVA on: workflow_dispatch: inputs: - WAZUH_VIRTUAL_MACHINES_REFERENCE: - description: 'Branch or tag of the wazuh-virtual-machines repository' - required: true - default: '4.10.0' WAZUH_INSTALLATION_ASSISTANT_REFERENCE: description: 'Branch or tag of the wazuh-installation-assistant repository' required: true @@ -163,7 +159,6 @@ jobs: ansible-playbook -i ${{ env.INVENTORY_PATH }}/inventory .github/workflows/ansible_playbooks/ova_generator.yaml \ --extra-vars " \ wia_branch=${{ inputs.WAZUH_INSTALLATION_ASSISTANT_REFERENCE }} \ - ova_branch=${{ inputs.WAZUH_VIRTUAL_MACHINES_REFERENCE }} \ repository=${{ inputs.WAZUH_PACKAGE_REPOSITORY }} \ ova_path=${{ env.OVA_PATH }} \ wia_scripts=${{ env.WIA_DIR }} \ From ab16fb631c8e974d16c6cc5e8daa149eb8ce1619 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Correa=20Rodr=C3=ADguez?= Date: Tue, 24 Sep 2024 16:30:09 +0200 Subject: [PATCH 04/11] Changed S3 repository and path of upload --- .github/workflows/builder_OVA.yaml | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/.github/workflows/builder_OVA.yaml b/.github/workflows/builder_OVA.yaml index e6418d7..cddd0bd 100644 --- a/.github/workflows/builder_OVA.yaml +++ b/.github/workflows/builder_OVA.yaml @@ -16,13 +16,6 @@ on: - prod - dev - staging - S3_REPOSITORY: - type: choice - description: 'packages-dev repository to upload the OVA' - required: true - options: - - pre-release - - staging DEBUG: type: choice description: 'Debug mode' @@ -39,6 +32,7 @@ env: SUBNET: "subnet-0b6aea31fb32cffad" TEMPORAL_S3_BUCKET: "warehouse.wazuh.com" S3_BUCKET: "packages-dev.wazuh.com" + S3_PATH: "development/wazuh/4.x/secondary/OVA" OVA_ENVIRONMENT: "vmware" CONTAINER_FORMAT: "ova" TEMPORAL_S3_PATH: "trash/vm" @@ -201,12 +195,12 @@ jobs: - name: Exporting OVA to final repository run: | - aws s3 cp --quiet --acl public-read /tmp/${{ env.FILENAME_OVA }} s3://${{ env.S3_BUCKET }}/${{ inputs.S3_REPOSITORY }}/vm/${{ env.FILENAME_OVA }} + aws s3 cp --quiet --acl public-read /tmp/${{ env.FILENAME_OVA }} s3://${{ secrets.AWS_S3_BUCKET }}/${{ env.S3_PATH }}/${{ env.FILENAME_OVA }} - name: Generating sha512 file run: | sha512sum /tmp/${{ env.FILENAME_OVA }} > /tmp/${{ env.FILENAME_SHA }} - aws s3 cp --quiet --acl public-read /tmp/${{ env.FILENAME_SHA }} s3://${{ env.S3_BUCKET }}/${{ inputs.S3_REPOSITORY }}/checksums/wazuh/${{ env.WAZUH_VERSION }}/${{ env.FILENAME_SHA }} + aws s3 cp --quiet --acl public-read /tmp/${{ env.FILENAME_SHA }} s3://${{ secrets.AWS_S3_BUCKET }}/${{ env.S3_PATH }}/${{ env.FILENAME_SHA }} - name: Removing temporal files run: | From 795c0dbb463e90cfb44628387ac8275f8a5826c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Correa=20Rodr=C3=ADguez?= Date: Tue, 24 Sep 2024 16:44:05 +0200 Subject: [PATCH 05/11] Added revision logic --- .github/workflows/builder_OVA.yaml | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/.github/workflows/builder_OVA.yaml b/.github/workflows/builder_OVA.yaml index cddd0bd..96b066f 100644 --- a/.github/workflows/builder_OVA.yaml +++ b/.github/workflows/builder_OVA.yaml @@ -16,6 +16,15 @@ on: - prod - dev - staging + OVA_REVISION: + type: string + description: 'Revision of the OVA file. Use -1 for stage builds, -0 for development builds' + required: true + default: '-0' + is_stage: + description: "Is stage?" + type: boolean + default: false DEBUG: type: choice description: 'Debug mode' @@ -61,8 +70,14 @@ jobs: - name: Setting FILENAME var run: | WAZUH_VERSION=$(cat VERSION) + COMMIT_SHA=$(git rev-parse --short ${{ github.sha }}) echo "WAZUH_VERSION=$WAZUH_VERSION" >> $GITHUB_ENV - FILENAME="wazuh-${WAZUH_VERSION}" + FILENAME="wazuh-${WAZUH_VERSION}-${{ inputs.OVA_REVISION }}" + + if [ ${{ inputs.is_stage }} == false ]; then + FILENAME="${FILENAME}-${COMMIT_SHA}" + fi + echo "FILENAME=$FILENAME" >> $GITHUB_ENV FILENAME_OVA="${FILENAME}.ova" echo "FILENAME_OVA=$FILENAME_OVA" >> $GITHUB_ENV From 8196902e69da8425c6252b60a1d0ee6516274742 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Correa=20Rodr=C3=ADguez?= Date: Tue, 24 Sep 2024 16:49:21 +0200 Subject: [PATCH 06/11] Added ID logic --- .github/workflows/builder_OVA.yaml | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/.github/workflows/builder_OVA.yaml b/.github/workflows/builder_OVA.yaml index 96b066f..bd11bc3 100644 --- a/.github/workflows/builder_OVA.yaml +++ b/.github/workflows/builder_OVA.yaml @@ -1,9 +1,13 @@ -run-name: Build OVA - Wazuh virtual machines branch ${{ github.ref_name }} - Launched by @${{ github.actor }} +run-name: Build OVA ${{ inputs.is_stage && ' - is stage' || '' }} ${{ inputs.id }} - Wazuh virtual machines branch ${{ github.ref_name }} - Launched by @${{ github.actor }} name: Build OVA on: workflow_dispatch: inputs: + id: + description: "ID used to identify the workflow uniquely." + type: string + required: false WAZUH_INSTALLATION_ASSISTANT_REFERENCE: description: 'Branch or tag of the wazuh-installation-assistant repository' required: true @@ -33,6 +37,11 @@ on: - -v - -vv - -vvv + workflow_call: + inputs: + id: + type: string + required: false env: OVA_AMI: "ami-0d4bd55523ee67aa4" From 91534274d8666a206d16522a7430b9066b2d2b9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Correa=20Rodr=C3=ADguez?= Date: Tue, 24 Sep 2024 17:10:19 +0200 Subject: [PATCH 07/11] Added checksum logic --- .github/workflows/builder_OVA.yaml | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/.github/workflows/builder_OVA.yaml b/.github/workflows/builder_OVA.yaml index bd11bc3..b315bae 100644 --- a/.github/workflows/builder_OVA.yaml +++ b/.github/workflows/builder_OVA.yaml @@ -1,4 +1,4 @@ -run-name: Build OVA ${{ inputs.is_stage && ' - is stage' || '' }} ${{ inputs.id }} - Wazuh virtual machines branch ${{ github.ref_name }} - Launched by @${{ github.actor }} +run-name: Build OVA ${{ inputs.is_stage && ' - is stage' || '' }}${{ inputs.checksum && ' - checksum' || '' }} ${{ inputs.id }} - Wazuh virtual machines branch ${{ github.ref_name }} - Launched by @${{ github.actor }} name: Build OVA on: @@ -29,6 +29,12 @@ on: description: "Is stage?" type: boolean default: false + checksum: + type: boolean + description: | + Generate package checksum. + Default is 'false'. + required: false DEBUG: type: choice description: 'Debug mode' @@ -42,6 +48,9 @@ on: id: type: string required: false + checksum: + type: boolean + required: false env: OVA_AMI: "ami-0d4bd55523ee67aa4" @@ -222,6 +231,7 @@ jobs: aws s3 cp --quiet --acl public-read /tmp/${{ env.FILENAME_OVA }} s3://${{ secrets.AWS_S3_BUCKET }}/${{ env.S3_PATH }}/${{ env.FILENAME_OVA }} - name: Generating sha512 file + if: ${{ inputs.checksum == true }} run: | sha512sum /tmp/${{ env.FILENAME_OVA }} > /tmp/${{ env.FILENAME_SHA }} aws s3 cp --quiet --acl public-read /tmp/${{ env.FILENAME_SHA }} s3://${{ secrets.AWS_S3_BUCKET }}/${{ env.S3_PATH }}/${{ env.FILENAME_SHA }} From aa7fc55b7ac9b698aa80431746c860023ff9f40f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Correa=20Rodr=C3=ADguez?= Date: Wed, 25 Sep 2024 12:56:42 +0200 Subject: [PATCH 08/11] Fixed errors in OVA generation --- .github/workflows/builder_OVA.yaml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/builder_OVA.yaml b/.github/workflows/builder_OVA.yaml index b315bae..b8950bf 100644 --- a/.github/workflows/builder_OVA.yaml +++ b/.github/workflows/builder_OVA.yaml @@ -1,4 +1,4 @@ -run-name: Build OVA ${{ inputs.is_stage && ' - is stage' || '' }}${{ inputs.checksum && ' - checksum' || '' }} ${{ inputs.id }} - Wazuh virtual machines branch ${{ github.ref_name }} - Launched by @${{ github.actor }} +run-name: Build OVA ${{ inputs.id }} ${{ inputs.is_stage && ' - is stage' || '' }}${{ inputs.checksum && ' - checksum' || '' }} - Branch ${{ github.ref_name }} - Launched by @${{ github.actor }} name: Build OVA on: @@ -22,9 +22,9 @@ on: - staging OVA_REVISION: type: string - description: 'Revision of the OVA file. Use -1 for stage builds, -0 for development builds' + description: 'Revision of the OVA file. Use -0 for development builds' required: true - default: '-0' + default: '0' is_stage: description: "Is stage?" type: boolean @@ -228,13 +228,13 @@ jobs: - name: Exporting OVA to final repository run: | - aws s3 cp --quiet --acl public-read /tmp/${{ env.FILENAME_OVA }} s3://${{ secrets.AWS_S3_BUCKET }}/${{ env.S3_PATH }}/${{ env.FILENAME_OVA }} + aws s3 cp --quiet /tmp/${{ env.FILENAME_OVA }} s3://${{ secrets.AWS_S3_BUCKET }}/${{ env.S3_PATH }}/${{ env.FILENAME_OVA }} - name: Generating sha512 file if: ${{ inputs.checksum == true }} run: | sha512sum /tmp/${{ env.FILENAME_OVA }} > /tmp/${{ env.FILENAME_SHA }} - aws s3 cp --quiet --acl public-read /tmp/${{ env.FILENAME_SHA }} s3://${{ secrets.AWS_S3_BUCKET }}/${{ env.S3_PATH }}/${{ env.FILENAME_SHA }} + aws s3 cp --quiet /tmp/${{ env.FILENAME_SHA }} s3://${{ secrets.AWS_S3_BUCKET }}/${{ env.S3_PATH }}/${{ env.FILENAME_SHA }} - name: Removing temporal files run: | From 91eb924eab0ff6eaa291dd2908fa12398526d6db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Correa=20Rodr=C3=ADguez?= Date: Wed, 25 Sep 2024 13:32:57 +0200 Subject: [PATCH 09/11] Improved OVA generation log visualization --- .github/workflows/builder_OVA.yaml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/builder_OVA.yaml b/.github/workflows/builder_OVA.yaml index b8950bf..820035f 100644 --- a/.github/workflows/builder_OVA.yaml +++ b/.github/workflows/builder_OVA.yaml @@ -70,6 +70,7 @@ env: OVA_PATH: "/var/provision/wazuh-virtual-machines" WIA_DIR: "wazuh-installation-assistant" WIA_REPOSITORY: "https://github.com/wazuh/wazuh-installation-assistant" + ANSIBLE_CALLBACK: "yaml" permissions: id-token: write # This is required for requesting the JWT @@ -80,7 +81,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Install Ansible - run: sudo apt-get update && sudo apt install -y python3 jq sshpass && python3 -m pip install --user ansible-core==2.16 + run: sudo apt-get update && sudo apt install -y python3 jq sshpass && python3 -m pip install --user ansible-core==2.16 && pip install pyyaml && ansible-galaxy collection install community.general - name: Checkout code uses: actions/checkout@v4 @@ -183,7 +184,7 @@ jobs: - name: Run Ansible playbook to generate the OVA run: | builder_args="-i" - ansible-playbook -i ${{ env.INVENTORY_PATH }}/inventory .github/workflows/ansible_playbooks/ova_generator.yaml \ + ANSIBLE_STDOUT_CALLBACK=$ANSIBLE_CALLBACK ansible-playbook -i ${{ env.INVENTORY_PATH }}/inventory .github/workflows/ansible_playbooks/ova_generator.yaml \ --extra-vars " \ wia_branch=${{ inputs.WAZUH_INSTALLATION_ASSISTANT_REFERENCE }} \ repository=${{ inputs.WAZUH_PACKAGE_REPOSITORY }} \ From f04c6402d94d53b8230dedd653cb38c4e59cb1d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Correa=20Rodr=C3=ADguez?= Date: Thu, 26 Sep 2024 11:41:10 +0200 Subject: [PATCH 10/11] Fixed typo in revision description tag --- .github/workflows/builder_OVA.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/builder_OVA.yaml b/.github/workflows/builder_OVA.yaml index 820035f..ed8390c 100644 --- a/.github/workflows/builder_OVA.yaml +++ b/.github/workflows/builder_OVA.yaml @@ -22,7 +22,7 @@ on: - staging OVA_REVISION: type: string - description: 'Revision of the OVA file. Use -0 for development builds' + description: 'Revision of the OVA file. Use "0" for development builds' required: true default: '0' is_stage: From 9e8e79629533648b133617692edb19953b9c0f95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Correa=20Rodr=C3=ADguez?= Date: Thu, 26 Sep 2024 14:47:01 +0200 Subject: [PATCH 11/11] Updated CHANGELOG for #58 --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 583fc92..d850c48 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,7 +12,7 @@ All notable changes to this project will be documented in this file. - Added the OVA to the wazuh-virtual-machines repository without changes ([#30](https://github.com/wazuh/wazuh-virtual-machines/pull/30)) - (OVA) ### Changed - +- Adapted repository selection in OVA generation ([#58](https://github.com/wazuh/wazuh-virtual-machines/pull/58)) - Migrated the OVA construction files to the wazuh-virtual-machines repository ([#29](https://github.com/wazuh/wazuh-virtual-machines/pull/29)) - (OVA) ### Fixed