diff --git a/.github/workflows/build_base.yml b/.github/workflows/build_base.yml index 0fac06eaa850..665a7e4f69f8 100644 --- a/.github/workflows/build_base.yml +++ b/.github/workflows/build_base.yml @@ -10,6 +10,11 @@ on: required: true default: '' type: string + ARCHITECTURE: + description: 'The architecture to build the package for' + required: true + default: 'amd64' + type: string workflow_dispatch: inputs: @@ -17,10 +22,15 @@ on: description: 'The branch/tag/commit to checkout to' required: true default: '' + ARCHITECTURE: + description: 'The architecture to build the package for' + required: true + default: 'amd64' + type: string jobs: build: - runs-on: ubuntu-latest + runs-on: ${{ (inputs.ARCHITECTURE == 'x86_64' || inputs.ARCHITECTURE == 'amd64') && 'ubuntu-latest' || 'wz-linux-arm64' }} name: Build defaults: run: @@ -28,7 +38,6 @@ jobs: strategy: matrix: DISTRIBUTION: [tar.gz] - ARCHITECTURE: [x64] steps: - name: Checkout code @@ -69,21 +78,16 @@ jobs: - name: Get artifact build name run: | - echo "ARTIFACT_BUILD_NAME=wazuh-dashboard_${{ env.WZD_VERSION }}-${{ env.WZD_REVISION }}_${{ matrix.ARCHITECTURE }}.${{ matrix.DISTRIBUTION }}" >> $GITHUB_ENV + echo "ARTIFACT_BUILD_NAME=wazuh-dashboard_${{ env.WZD_VERSION }}-${{ env.WZD_REVISION }}_${{ (inputs.ARCHITECTURE == 'x86_64' || inputs.ARCHITECTURE == 'amd64') && 'x64' || 'arm64' }}.${{ matrix.DISTRIBUTION }}" >> $GITHUB_ENV - name: Run bootstrap run: yarn osd bootstrap - - name: Build linux-x64 - if: matrix.ARCHITECTURE == 'x64' - run: yarn build-platform --linux --skip-os-packages --release - - - name: Build linux-arm64 - if: matrix.ARCHITECTURE == 'arm64' - run: yarn build-platform --linux-arm --skip-os-packages --release + - name: Build + run: yarn build-platform --${{(inputs.ARCHITECTURE == 'x86_64' || inputs.ARCHITECTURE == 'amd64') && 'linux' || 'linux-arm'}} --skip-os-packages --release - name: Rename artifact - run: mv /home/runner/work/wazuh-dashboard/wazuh-dashboard/artifacts/target/opensearch-dashboards-${{ env.VERSION }}-linux-${{ matrix.ARCHITECTURE }}.${{ matrix.DISTRIBUTION }} /home/runner/work/wazuh-dashboard/wazuh-dashboard/artifacts/target/${{ env.ARTIFACT_BUILD_NAME }} + run: mv /home/runner/work/wazuh-dashboard/wazuh-dashboard/artifacts/target/opensearch-dashboards-${{ env.VERSION }}-linux-${{ (inputs.ARCHITECTURE == 'x86_64' || inputs.ARCHITECTURE == 'amd64') && 'x64' || 'arm64' }}.${{ matrix.DISTRIBUTION }} /home/runner/work/wazuh-dashboard/wazuh-dashboard/artifacts/target/${{ env.ARTIFACT_BUILD_NAME }} - uses: actions/upload-artifact@v3 if: success() diff --git a/.github/workflows/build_wazuh_dashboard_with_plugins.yml b/.github/workflows/build_wazuh_dashboard_with_plugins.yml index 221047008413..d7e8db48f3bd 100644 --- a/.github/workflows/build_wazuh_dashboard_with_plugins.yml +++ b/.github/workflows/build_wazuh_dashboard_with_plugins.yml @@ -1,4 +1,4 @@ -run-name: Build ${{ inputs.system }} wazuh-dashboard on ${{ inputs.architecture }} ${{ inputs.is_stage && '- is stage' || '' }} ${{ inputs.checksum && '- checksum' || '' }} ${{ inputs.debug && '- debug' || '' }} ${{ inputs.id }} +run-name: Build ${{ inputs.system }} wazuh-dashboard on ${{ inputs.architecture }} ${{ inputs.is_stage && '- is stage' || '' }} ${{ inputs.checksum && '- checksum' || '' }} ${{ inputs.id }} name: Build Wazuh dashboard with plugins on: @@ -19,6 +19,8 @@ on: options: - amd64 - x86_64 + - aarch64 + - arm64 default: amd64 revision: type: string @@ -101,53 +103,165 @@ on: required: false jobs: - validate-inputs: + setup-variables: runs-on: ubuntu-latest - name: Validate inputs + name: Setup variables + outputs: + CURRENT_DIR: ${{ steps.setup-variables.outputs.CURRENT_DIR }} + VERSION: ${{ steps.setup-variables.outputs.VERSION }} + REVISION: ${{ steps.setup-variables.outputs.REVISION }} + COMMIT_SHA: ${{ steps.setup-variables.outputs.COMMIT_SHA }} + PRODUCTION: ${{ steps.setup-variables.outputs.PRODUCTION }} + WAZUH_DASHBOARD_SLIM: ${{ steps.setup-variables.outputs.WAZUH_DASHBOARD_SLIM }} + WAZUH_SECURITY_PLUGIN: ${{ steps.setup-variables.outputs.WAZUH_SECURITY_PLUGIN }} + WAZUH_REPORT_PLUGIN: ${{ steps.setup-variables.outputs.WAZUH_REPORT_PLUGIN }} + WAZUH_PLUGINS: ${{ steps.setup-variables.outputs.WAZUH_PLUGINS }} + PACKAGE_NAME: ${{ steps.setup-variables.outputs.PACKAGE_NAME }} + FINAL_NAME: ${{ steps.setup-variables.outputs.FINAL_NAME }} + ARCHITECTURE_FLAG: ${{ steps.setup-variables.outputs.ARCHITECTURE_FLAG }} + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Get SHA of wazuh-dashboard-plugins + id: get-plugins-sha + run: | + git clone -b ${{ inputs.reference_wazuh_plugins }} --single-branch https://github.com/wazuh/wazuh-dashboard-plugins.git wzdp + cd wzdp + echo "WAZUH_PLUGINS_SHA=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT + - name: Get SHA of wazuh-security-dashboards-plugin + id: get-security-sha + run: | + git clone -b ${{ inputs.reference_security_plugins }} --single-branch https://github.com/wazuh/wazuh-security-dashboards-plugin.git wzsp + cd wzsp + echo "WAZUH_SECURITY_SHA=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT + - name: Get SHA of wazuh-dashboards-reporting + id: get-reporting-sha + run: | + git clone -b ${{ inputs.reference_report_plugins }} --single-branch https://github.com/wazuh/wazuh-dashboards-reporting.git wzrp + cd wzrp + echo "WAZUH_REPORTING_SHA=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT + + - name: Setup variables + id: setup-variables + run: | + CURRENT_DIR=$(pwd -P) + VERSION=$(tail -c +2 VERSION) + REVISION=$(yarn --silent wzd-revision) + COMMIT_SHA=$(git rev-parse --short HEAD) + PLUGINS_SHA=${{steps.get-plugins-sha.outputs.WAZUH_PLUGINS_SHA}} + SECURITY_SHA=${{steps.get-security-sha.outputs.WAZUH_SECURITY_SHA}} + REPORTING_SHA=${{steps.get-reporting-sha.outputs.WAZUH_REPORTING_SHA}} + if [ "${{ inputs.is_stage }}" = "true" ]; then + PRODUCTION=--production + else + PRODUCTION="" + fi + WAZUH_DASHBOARD_SLIM=wazuh-dashboard_${VERSION}-${REVISION}_${{ (inputs.ARCHITECTURE == 'x86_64' || inputs.ARCHITECTURE == 'amd64') && 'x64' || 'arm64' }}.tar.gz + WAZUH_SECURITY_PLUGIN=wazuh-security-dashboards-plugin_${VERSION}-${REVISION}_${{ inputs.reference_security_plugins }}.zip + WAZUH_REPORT_PLUGIN=reports-dashboards_${VERSION}-${REVISION}_${{ inputs.reference_report_plugins }}.zip + WAZUH_PLUGINS=wazuh-dashboard-plugins_${VERSION}-${REVISION}_${{ inputs.reference_wazuh_plugins }}.zip + if [ "${{ inputs.system }}" = "deb" ]; then + if [ "${{ inputs.is_stage }}" = "true" ]; then + PACKAGE_NAME=wazuh-dashboard_${VERSION}-${{ inputs.revision }}_${{ inputs.architecture }}.deb + FINAL_NAME=wazuh-dashboard_${VERSION}-${{ inputs.revision }}_${{ inputs.architecture }}.deb + else + PACKAGE_NAME=wazuh-dashboard_${VERSION}-${{ inputs.revision }}_${{ inputs.architecture }}_${COMMIT_SHA}.deb + FINAL_NAME=wazuh-dashboard_${VERSION}-${{ inputs.revision }}_${{ inputs.architecture }}_${COMMIT_SHA}-${PLUGINS_SHA}-${SECURITY_SHA}-${REPORTING_SHA}.deb + fi + else + if [ "${{ inputs.is_stage }}" = "true" ]; then + PACKAGE_NAME=wazuh-dashboard-${VERSION}-${{ inputs.revision }}.${{ inputs.architecture }}.rpm + FINAL_NAME=wazuh-dashboard-${VERSION}-${{ inputs.revision }}.${{ inputs.architecture }}.rpm + else + PACKAGE_NAME=wazuh-dashboard_${VERSION}-${{ inputs.revision }}_${{ inputs.architecture }}_${COMMIT_SHA}.rpm + FINAL_NAME=wazuh-dashboard_${VERSION}-${{ inputs.revision }}_${{ inputs.architecture }}_${COMMIT_SHA}-${PLUGINS_SHA}-${SECURITY_SHA}-${REPORTING_SHA}.rpm + fi + fi + if [[ "${{ inputs.architecture }}" == "x86_64" || "${{ inputs.architecture }}" == "amd64" ]]; then + ARCHITECTURE_FLAG="" + else + ARCHITECTURE_FLAG=--arm + fi + echo "CURRENT_DIR=$CURRENT_DIR" >> $GITHUB_OUTPUT + echo "VERSION=$VERSION" >> $GITHUB_OUTPUT + echo "REVISION=$REVISION" >> $GITHUB_OUTPUT + echo "COMMIT_SHA=$COMMIT_SHA" >> $GITHUB_OUTPUT + echo "PRODUCTION=$PRODUCTION" >> $GITHUB_OUTPUT + echo "WAZUH_DASHBOARD_SLIM=$WAZUH_DASHBOARD_SLIM" >> $GITHUB_OUTPUT + echo "WAZUH_SECURITY_PLUGIN=$WAZUH_SECURITY_PLUGIN" >> $GITHUB_OUTPUT + echo "WAZUH_REPORT_PLUGIN=$WAZUH_REPORT_PLUGIN" >> $GITHUB_OUTPUT + echo "WAZUH_PLUGINS=$WAZUH_PLUGINS" >> $GITHUB_OUTPUT + echo "PACKAGE_NAME=$PACKAGE_NAME" >> $GITHUB_OUTPUT + echo "FINAL_NAME=$FINAL_NAME" >> $GITHUB_OUTPUT + echo "ARCHITECTURE_FLAG=$ARCHITECTURE_FLAG" >> $GITHUB_OUTPUT + + validate-job: + runs-on: ubuntu-latest + needs: setup-variables + name: Validate job steps: - name: Validate inputs run: | - if [ "${{ inputs.architecture }}" = "amd64" ] && [ "${{ inputs.system }}" = "rpm" ]; then + if [[ "${{ inputs.architecture }}" == "amd64" || "${{ inputs.architecture }}" == "arm64" ]] && [[ "${{ inputs.system }}" == "rpm" ]]; then echo "Invalid combination of architecture and system" exit 1 fi - if [ "${{ inputs.architecture }}" = "x86_64" ] && [ "${{ inputs.system }}" = "deb" ]; then + if [[ "${{ inputs.architecture }}" == "x86_64" || "${{ inputs.architecture }}" == "aarch64" ]] && [[ "${{ inputs.system }}" == "deb" ]]; then echo "Invalid combination of architecture and system" exit 1 fi + - name: Set up AWS CLI + uses: aws-actions/configure-aws-credentials@v4 + with: + aws-access-key-id: ${{ secrets.CI_INTERNAL_DEVELOPMENT_BUCKET_USER_ACCESS_KEY }} + aws-secret-access-key: ${{ secrets.CI_INTERNAL_DEVELOPMENT_BUCKET_USER_SECRET_KEY }} + aws-region: ${{ secrets.CI_AWS_REGION }} + + - name: Verify if package is already built + run: | + set +e + echo "Verifying package" + PACKAGE_NAME=${{ needs.setup-variables.outputs.FINAL_NAME }} + exists=$(aws s3 ls s3://packages-dev.internal.wazuh.com/development/wazuh/5.x/main/packages/$PACKAGE_NAME) + if [ -n "$exists" ]; then + echo "Package already exists" + exit 1 + fi + set -e build-base: - needs: [validate-inputs] + needs: [validate-job] name: Build dashboard - uses: wazuh/wazuh-dashboard/.github/workflows/build_base.yml@master + uses: wazuh/wazuh-dashboard/.github/workflows/build_base.yml@4.10.2 with: CHECKOUT_TO: ${{ github.head_ref || github.ref_name }} + ARCHITECTURE: ${{ inputs.architecture }} build-main-plugins: - needs: [validate-inputs] + needs: [validate-job] name: Build plugins - uses: wazuh/wazuh-dashboard-plugins/.github/workflows/manual-build.yml@master + uses: wazuh/wazuh-dashboard-plugins/.github/workflows/manual-build.yml@4.10.2 with: reference: ${{ inputs.reference_wazuh_plugins }} build-security-plugin: - needs: [validate-inputs] + needs: [validate-job] name: Build security plugin - uses: wazuh/wazuh-security-dashboards-plugin/.github/workflows/manual-build.yml@master + uses: wazuh/wazuh-security-dashboards-plugin/.github/workflows/manual-build.yml@4.10.2 with: reference: ${{ inputs.reference_security_plugins }} build-report-plugin: - needs: [validate-inputs] + needs: [validate-job] name: Build reporting plugin uses: wazuh/wazuh-dashboards-reporting/.github/workflows/manual-build.yml@master with: reference: ${{ inputs.reference_report_plugins }} - build-and-test-package: - needs: [build-main-plugins, build-base, build-security-plugin, build-report-plugin] - runs-on: ubuntu-latest + needs: [setup-variables, build-main-plugins, build-base, build-security-plugin, build-report-plugin] + runs-on: ${{ (inputs.architecture == 'arm64' || inputs.architecture == 'aarch64') && 'wz-linux-arm64' || 'ubuntu-22.04' }} name: Generate packages steps: - name: Checkout code @@ -159,125 +273,68 @@ jobs: node-version-file: '.nvmrc' registry-url: 'https://registry.npmjs.org' - - name: Setup variables - run: | - echo "CURRENT_DIR=$(pwd -P)" >> $GITHUB_ENV - echo "VERSION=$(tail -c +2 VERSION)" >> $GITHUB_ENV - echo "REVISION=$(yarn --silent wzd-revision)" >> $GITHUB_ENV - echo "COMMIT_SHA=$(git rev-parse --short HEAD)" >> $GITHUB_ENV - if [ "${{ inputs.is_stage }}" = "true" ]; then - echo "PRODUCTION=--production" >> $GITHUB_ENV - fi - - - name: Get SHA of wazuh-dashboard-plugins - id: get-plugins-sha - run: | - git clone -b ${{ inputs.reference_wazuh_plugins }} --single-branch https://github.com/wazuh/wazuh-dashboard-plugins.git wzdp - cd wzdp - echo "WAZUH_PLUGINS_SHA=$(git rev-parse --short HEAD)" >> $GITHUB_ENV - - name: Get SHA of wazuh-security-dashboards-plugin - id: get-security-sha - run: | - git clone -b ${{ inputs.reference_security_plugins }} --single-branch https://github.com/wazuh/wazuh-security-dashboards-plugin.git wzsp - cd wzsp - echo "WAZUH_SECURITY_SHA=$(git rev-parse --short HEAD)" >> $GITHUB_ENV - - name: Get SHA of wazuh-dashboards-reporting - id: get-reporting-sha - run: | - git clone -b ${{ inputs.reference_report_plugins }} --single-branch https://github.com/wazuh/wazuh-dashboards-reporting.git wzrp - cd wzrp - echo "WAZUH_REPORTING_SHA=$(git rev-parse --short HEAD)" >> $GITHUB_ENV - - - name: Setup packages names - run: | - echo "WAZUH_DASHBOARD_SLIM=wazuh-dashboard_${{ env.VERSION }}-${{ env.REVISION }}_x64.tar.gz" >> $GITHUB_ENV - echo "WAZUH_SECURITY_PLUGIN=wazuh-security-dashboards-plugin_${{ env.VERSION }}-${{ env.REVISION }}_${{ inputs.reference_security_plugins }}.zip" >> $GITHUB_ENV - echo "WAZUH_PLUGINS=wazuh-dashboard-plugins_${{ env.VERSION }}-${{ env.REVISION }}_${{ inputs.reference_wazuh_plugins }}.zip" >> $GITHUB_ENV - echo "WAZUH_REPORT_PLUGIN=reports-dashboards_${{ env.VERSION }}-${{ env.REVISION }}_${{ inputs.reference_report_plugins }}.zip" >> $GITHUB_ENV - if [ "${{ inputs.system }}" = "deb" ]; then - if [ "${{ inputs.is_stage }}" = "true" ]; then - echo "PACKAGE_NAME=wazuh-dashboard_${{ env.VERSION }}-${{ inputs.revision }}_${{ inputs.architecture }}.deb" >> $GITHUB_ENV - echo "FINAL_NAME=wazuh-dashboard_${{ env.VERSION }}-${{ inputs.revision }}_${{ inputs.architecture }}.deb" >> $GITHUB_ENV - else - echo "PACKAGE_NAME=wazuh-dashboard_${{ env.VERSION }}-${{ inputs.revision }}_${{ inputs.architecture }}_${{ env.COMMIT_SHA}}.deb" >> $GITHUB_ENV - echo "FINAL_NAME=wazuh-dashboard_${{ env.VERSION }}-${{ inputs.revision }}_${{ inputs.architecture }}_${{ env.COMMIT_SHA}}-${{ env.WAZUH_PLUGINS_SHA}}-${{ env.WAZUH_SECURITY_SHA}}-${{ env.WAZUH_REPORTING_SHA}}.deb" >> $GITHUB_ENV - fi - else - if [ "${{ inputs.is_stage }}" = "true" ]; then - echo "PACKAGE_NAME=wazuh-dashboard-${{ env.VERSION }}-${{ inputs.revision }}.${{ inputs.architecture }}.rpm" >> $GITHUB_ENV - echo "FINAL_NAME=wazuh-dashboard-${{ env.VERSION }}-${{ inputs.revision }}.${{ inputs.architecture }}.rpm" >> $GITHUB_ENV - else - echo "PACKAGE_NAME=wazuh-dashboard_${{ env.VERSION }}-${{ inputs.revision }}_${{ inputs.architecture }}_${{ env.COMMIT_SHA}}.rpm" >> $GITHUB_ENV - echo "FINAL_NAME=wazuh-dashboard_${{ env.VERSION }}-${{ inputs.revision }}_${{ inputs.architecture }}_${{ env.COMMIT_SHA}}-${{ env.WAZUH_PLUGINS_SHA}}-${{ env.WAZUH_SECURITY_SHA}}-${{ env.WAZUH_REPORTING_SHA}}.rpm" >> $GITHUB_ENV - fi - fi - - name: Download dashboard artifact uses: actions/download-artifact@v3 with: - name: ${{ env.WAZUH_DASHBOARD_SLIM }} - path: ${{ env.CURRENT_DIR }}/artifacts/dashboard + name: ${{ needs.setup-variables.outputs.WAZUH_DASHBOARD_SLIM }} + path: ${{ needs.setup-variables.outputs.CURRENT_DIR }}/artifacts/dashboard - name: Download security plugin artifact uses: actions/download-artifact@v3 with: - name: ${{ env.WAZUH_SECURITY_PLUGIN }} - path: ${{ env.CURRENT_DIR }}/artifacts/security-plugin + name: ${{ needs.setup-variables.outputs.WAZUH_SECURITY_PLUGIN }} + path: ${{ needs.setup-variables.outputs.CURRENT_DIR }}/artifacts/security-plugin - name: Download plugins artifacts uses: actions/download-artifact@v3 with: - name: ${{ env.WAZUH_PLUGINS }} - path: ${{ env.CURRENT_DIR }}/artifacts/plugins - + name: ${{ needs.setup-variables.outputs.WAZUH_PLUGINS }} + path: ${{ needs.setup-variables.outputs.CURRENT_DIR }}/artifacts/plugins - name: Download report plugin artifact uses: actions/download-artifact@v3 with: - name: ${{ env.WAZUH_REPORT_PLUGIN }} - path: ${{ env.CURRENT_DIR }}/artifacts/report-plugin + name: ${{ needs.setup-variables.outputs.WAZUH_REPORT_PLUGIN }} + path: ${{ needs.setup-variables.outputs.CURRENT_DIR }}/artifacts/report-plugin - name: Zip plugins run: | - zip -r -j ${{ env.CURRENT_DIR }}/artifacts/wazuh-package.zip ${{ env.CURRENT_DIR }}/artifacts/plugins - zip -r -j ${{ env.CURRENT_DIR }}/artifacts/security-package.zip ${{ env.CURRENT_DIR }}/artifacts/security-plugin - zip -r -j ${{ env.CURRENT_DIR }}/artifacts/dashboard-package.zip ${{ env.CURRENT_DIR }}/artifacts/dashboard/${{ env.WAZUH_DASHBOARD_SLIM }} - zip -r -j ${{ env.CURRENT_DIR }}/artifacts/report-package.zip ${{ env.CURRENT_DIR }}/artifacts/report-plugin + zip -r -j ${{ needs.setup-variables.outputs.CURRENT_DIR }}/artifacts/wazuh-package.zip ${{ needs.setup-variables.outputs.CURRENT_DIR }}/artifacts/plugins + zip -r -j ${{ needs.setup-variables.outputs.CURRENT_DIR }}/artifacts/security-package.zip ${{ needs.setup-variables.outputs.CURRENT_DIR }}/artifacts/security-plugin + zip -r -j ${{ needs.setup-variables.outputs.CURRENT_DIR }}/artifacts/dashboard-package.zip ${{ needs.setup-variables.outputs.CURRENT_DIR }}/artifacts/dashboard/${{ needs.setup-variables.outputs.WAZUH_DASHBOARD_SLIM }} + zip -r -j ${{ needs.setup-variables.outputs.CURRENT_DIR }}/artifacts/report-package.zip ${{ needs.setup-variables.outputs.CURRENT_DIR }}/artifacts/report-plugin - name: Build package run: | - cd ${{ env.CURRENT_DIR }}/dev-tools/build-packages + cd ${{ needs.setup-variables.outputs.CURRENT_DIR }}/dev-tools/build-packages bash ./build-packages.sh \ - -v ${{ env.VERSION }} \ - -r ${{ inputs.revision }} \ - -a file://${{env.CURRENT_DIR}}/artifacts/wazuh-package.zip \ - -s file://${{env.CURRENT_DIR}}/artifacts/security-package.zip \ - -b file://${{env.CURRENT_DIR}}/artifacts/dashboard-package.zip \ - -rp file://${{env.CURRENT_DIR}}/artifacts/report-package.zip \ - --${{ inputs.system }} ${{ env.PRODUCTION }} + -v ${{ needs.setup-variables.outputs.VERSION }} \ + -r ${{ inputs.revision }} ${{ needs.setup-variables.outputs.ARCHITECTURE_FLAG }} \ + -a file://${{needs.setup-variables.outputs.CURRENT_DIR}}/artifacts/wazuh-package.zip \ + -s file://${{needs.setup-variables.outputs.CURRENT_DIR}}/artifacts/security-package.zip \ + -b file://${{needs.setup-variables.outputs.CURRENT_DIR}}/artifacts/dashboard-package.zip \ + -rp file://${{needs.setup-variables.outputs.CURRENT_DIR}}/artifacts/report-package.zip \ + ${{ needs.setup-variables.outputs.PRODUCTION }} --${{ inputs.system }} --debug - name: Test package run: | - cd ${{ env.CURRENT_DIR }}/dev-tools/test-packages - ls -la ${{ env.CURRENT_DIR }}/dev-tools/build-packages/output/${{ inputs.system }} - cp ${{ env.CURRENT_DIR }}/dev-tools/build-packages/output/${{ inputs.system }}/${{env.PACKAGE_NAME}} ${{ env.CURRENT_DIR }}/dev-tools/test-packages/${{ inputs.system }} + cd ${{ needs.setup-variables.outputs.CURRENT_DIR }}/dev-tools/test-packages + cp ${{ needs.setup-variables.outputs.CURRENT_DIR }}/dev-tools/build-packages/output/${{needs.setup-variables.outputs.PACKAGE_NAME}} ${{ needs.setup-variables.outputs.CURRENT_DIR }}/dev-tools/test-packages/${{ inputs.system }} bash ./test-packages.sh \ - -p ${{env.PACKAGE_NAME}} + -p ${{needs.setup-variables.outputs.PACKAGE_NAME}} - name: Set package final name run: | - mv ${{ env.CURRENT_DIR }}/dev-tools/build-packages/output/${{ inputs.system }}/${{env.PACKAGE_NAME}} ${{ env.CURRENT_DIR }}/dev-tools/build-packages/output/${{ inputs.system }}/${{env.FINAL_NAME}} + mv ${{ needs.setup-variables.outputs.CURRENT_DIR }}/dev-tools/build-packages/output/${{needs.setup-variables.outputs.PACKAGE_NAME}} ${{ needs.setup-variables.outputs.CURRENT_DIR }}/dev-tools/build-packages/output/${{needs.setup-variables.outputs.FINAL_NAME}} - name: Set SHA final name if: ${{ inputs.checksum }} run: | - mv ${{ env.CURRENT_DIR }}/dev-tools/build-packages/output/${{ inputs.system }}/${{env.PACKAGE_NAME}}.sha512 ${{ env.CURRENT_DIR }}/dev-tools/build-packages/output/${{ inputs.system }}/${{env.FINAL_NAME}}.sha512 - - + mv ${{ needs.setup-variables.outputs.CURRENT_DIR }}/dev-tools/build-packages/output/${{needs.setup-variables.outputs.PACKAGE_NAME}}.sha512 ${{ needs.setup-variables.outputs.CURRENT_DIR }}/dev-tools/build-packages/output/${{needs.setup-variables.outputs.FINAL_NAME}}.sha512 - uses: actions/upload-artifact@v3 if: success() with: - name: ${{ env.PACKAGE_NAME }} - path: ${{ env.CURRENT_DIR }}/dev-tools/build-packages/output/${{ inputs.system }}/${{env.FINAL_NAME}} + name: ${{ needs.setup-variables.outputs.PACKAGE_NAME }} + path: ${{ needs.setup-variables.outputs.CURRENT_DIR }}/dev-tools/build-packages/output/${{needs.setup-variables.outputs.FINAL_NAME}} retention-days: 30 - name: Set up AWS CLI @@ -292,14 +349,14 @@ jobs: if: ${{ inputs.upload }} run: | echo "Uploading package" - aws s3 cp ${{ env.CURRENT_DIR }}/dev-tools/build-packages/output/${{ inputs.system }}/${{env.FINAL_NAME}} s3://packages-dev.internal.wazuh.com/development/wazuh/5.x/main/packages/ - s3uri="s3://packages-dev.internal.wazuh.com/development/wazuh/5.x/main/packages/${{env.FINAL_NAME}}" + aws s3 cp ${{ needs.setup-variables.outputs.CURRENT_DIR }}/dev-tools/build-packages/output/${{needs.setup-variables.outputs.FINAL_NAME}} s3://packages-dev.internal.wazuh.com/development/wazuh/5.x/main/packages/ + s3uri="s3://packages-dev.internal.wazuh.com/development/wazuh/5.x/main/packages/${{needs.setup-variables.outputs.FINAL_NAME}}" echo "S3 URI: ${s3uri}" - name: Upload SHA512 - if: ${{ inputs.upload && inputs.checksum }} + if: ${{ inputs.checksum }} run: | echo "Uploading checksum" - aws s3 cp ${{ env.CURRENT_DIR }}/dev-tools/build-packages/output/${{ inputs.system }}/${{env.FINAL_NAME}}.sha512 s3://packages-dev.internal.wazuh.com/development/wazuh/5.x/main/packages/ - s3uri="s3://packages-dev.internal.wazuh.com/development/wazuh/5.x/main/packages/${{env.FINAL_NAME}}.sha512" + aws s3 cp ${{ needs.setup-variables.outputs.CURRENT_DIR }}/dev-tools/build-packages/output/${{needs.setup-variables.outputs.FINAL_NAME}}.sha512 s3://packages-dev.internal.wazuh.com/development/wazuh/5.x/main/packages/ + s3uri="s3://packages-dev.internal.wazuh.com/development/wazuh/5.x/main/packages/${{needs.setup-variables.outputs.FINAL_NAME}}.sha512" echo "S3 sha512 URI: ${s3uri}" diff --git a/.gitignore b/.gitignore index 295516907c5d..7117a9591831 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,8 @@ .aws-config.json .signing-config.json .ackrc -/dev-tools/build-packages/*/output +/dev-tools/build-packages/output +/dev-tools/build-packages/tmp /.opensearch /.chromium /package.json.bak @@ -71,4 +72,7 @@ snapshots.js .yarn-local-mirror # Ignore the generated antlr files -/src/plugins/data/public/antlr/**/grammar/.antlr/ \ No newline at end of file +/src/plugins/data/public/antlr/opensearch_sql/grammar/.antlr + +# Ignore the generated packages +/dev-tools/build-packages/base-packages-to-base/packages diff --git a/dev-tools/build-packages/README.md b/dev-tools/build-packages/README.md index 16f085dde78f..d12169a404ba 100644 --- a/dev-tools/build-packages/README.md +++ b/dev-tools/build-packages/README.md @@ -1,70 +1,59 @@ # Package building -This folder contains tools used to create `rpm` and `deb` packages. + +This folder contains tools used to create `tar`, `rpm` and `deb` packages. ## Requirements - - A system with Docker. - - Internet connection (to download the docker images the first time). -## Builders +- A system with Docker. +- Internet connection (to download the docker images the first time). -### Tarball +## How to build packages -To system packages (deb and rpm), a tarball of Wazuh dashboard `.tar.gz` is required. -This tarball contains the [Wazuh plugin][wazuh-plugin], the [Wazuh Security plugin][wazuh-security-plugin], -a set of OpenSearch plugins and the default configuration for the app. +The script `build-packages.sh` is in charge of coordinating the different steps to build each type of packages. -The `generate_base.sh` script generates a `.tar.gz` file using the following inputs: -- `-a` | `--app`: URL to the zipped Wazuh plugin.* -- `-b` | `--base`: URL to the Wazuh dashboard `.tar.gz`, as generated with `yarn build --skip-os-packages --release`.* -- `-s` | `--security`: URL to the zipped Wazuh Security plugin, as generated with `yarn build`.* -- `-v` | `--version`: the Wazuh version of the package. -- `-r` | `--revision`: [Optional] Set the revision of the build. By default, it is set to 1. -- `-o` | `--output` [Optional] Set the destination path of package. By default, an output folder will be created in the same directory as the script. +### Pre-requisites -*Note:* use `file://` to indicate a local file. Otherwise, the script will try to download the file from the given URL. +The script needs 4 different zip files, containing the following respectively: -Example: -```bash -bash generate_base.sh \ - --app https://packages-dev.wazuh.com/pre-release/ui/dashboard/wazuh-4.6.0-1.zip \ - --base file:///home/user/wazuh-dashboard/target/opensearch-dashboards-2.4.1-linux-x64.tar.gz \ - --security file:///home/user/wazuh-security-dashboards-plugin/build/security-dashboards-2.4.1.0.zip \ - --version 4.6.0 -``` +- The base of Wazuh Dashboard, generated by running `yarn build --linux --skip-os-packages --release` or `yarn build --linux-arm --skip-os-packages --release` for arm packages +- The build of each plugin in `wazuh-dashboard-plugins` repo +- The build of the `wazuh-security-dashboards-plugin` repo +- The build of the `wazuh-dashboards-reporting ` repo -### DEB +### Building packages -The `launcher.sh` script generates a `.deb` package based on the previously generated `.tar.gz`. -A Docker container is used to generate the package. It takes the following inputs: -- `-v` | `--version`: the Wazuh version of the package. -- `-p` | `--package`: the location of the `.tar.gz` file. It can be a URL or a PATH, with the format `file://` -- `-r` | `--revision`: [Optional] Set the revision of the build. By default, it is set to 1. -- `-o` | `--output` [Optional] Set the destination path of package. By default, an output folder will be created in the same directory as the script. -- `--dont-build-docker`: [Optional] Locally built Docker image will be used instead of generating a new one. +The script can build a `.tar.gz` (former base), and `rpm` and `deb` packages. This can be for x64 and arm architectures (it is not cross-architecture building. You need to run the script in a machine of the same architecture that you are building). -Example: -```bash -bash launcher.sh \ - --version 4.6.0 \ - --package file:///home/user/wazuh-dashboard/dev_tools/build_packages/base/output/wazuh-dashboard-4.6.0-1-linux-x64.tar.gz -``` +The inputs are the following: + +- `-a`, `--app`: URL or path to the zip that contains the `wazuh-dashboard-plugins` plugins build. +- `-b`, `--base`: URL or path to the zip that contains the `wazuh-dashboard build`. +- `-s`, `--security`: URL or path to the zip that contains the `wazuh-security-dashboards-plugin` build. +- `-rp`, `--reportPlugin`: URL or path to the zip that contains the `wazuh-dashboards-reporting` build. +- `-v`, `--version`: Set the version of this build. +- `-r`, `--revision`: [Optional] Set the revision of this build. By default, it is set to 1. +- `--all-platforms`: Build all platforms. +- `--deb`: Build deb. +- `--rpm`: Build rpm. +- `--tar`: Build tar.gz. +- `--production`:[Optional] The naming of the package will be ready for production. Otherwise, it will include the hash of the current commit. +- `--arm`: [Optional] Build for arm64 instead of x64. +- `--debug`: [Optional] Enables debug mode, which will show detailed information during the script run. +- `--silent`: [Optional] Enables silent mode, which will show the minimum possible information during the script run. `--debug` has priority over this. -### RPM +> [!IMPORTANT] +> In the inputs where a local path is available, use `file://` to indicate it. -The `launcher.sh` script generates a `.rpm` package based on the previously generated `.tar.gz`. -A Docker container is used to generate the package. It takes the following inputs: -- `-v` | `--version`: the Wazuh version of the package. -- `-p` | `--package`: the location of the `.tar.gz` file. It can be a URL or a PATH, with the format `file://` -- `-r` | `--revision`: [Optional] Set the revision of the build. By default, it is set to 1. -- `-o` | `--output` [Optional] Set the destination path of package. By default, an output folder will be created in the same directory as the script. -- `--dont-build-docker`: [Optional] Locally built Docker image will be used instead of generating a new one. +> [!WARNING] +> To build `arm` packages, you need to run the script in an arm machine, and use an arm build of the wazuh-dashboard base with `-b` Example: + ```bash -bash launcher.sh \ - --version 4.6.0 \ - --package file:///home/user/wazuh-dashboard/dev_tools/build_packages/base/output/wazuh-dashboard-4.6.0-1-linux-x64.tar.gz +bash build-packages.sh \ + --app file:///home/user/packages/wazuh-package.zip \ + --base file:///home/user/packages/dashboard-package.zip \ + --security file:///home/user/packages/security-package.zip \ + --reportPlugin file:///home/user/packages/report-package.zip + --version 5.0.0 --revision 2 --deb --silent ``` - -[wazuh-plugin]: https://github.com/wazuh/wazuh-kibana-app -[wazuh-security-plugin]: https://github.com/wazuh/wazuh-security-dashboards-plugin \ No newline at end of file diff --git a/dev-tools/build-packages/base-packages-to-base/README.md b/dev-tools/build-packages/base-packages-to-base/README.md new file mode 100644 index 000000000000..da7ce1954294 --- /dev/null +++ b/dev-tools/build-packages/base-packages-to-base/README.md @@ -0,0 +1,39 @@ +# Package building + +This folder contains the tools used to create packages from the different repositories necessary for the creation of deb and rpm packages. + +## Requirements + +- A system with Docker. +- Internet connection (to download the docker images the first time). + +## How to build packages + +The script `run-docker-compose.sh` is in charge of coordinating the different steps to build each package. + +### Building packages + +The script can build a `.tar.gz` (former base), and `rpm` and `deb` packages. This can be for x64 and arm architectures (it is not cross-architecture building. You need to run the script in a machine of the same architecture that you are building). + +The inputs are the following: + +- `-a`, `--app`: Set the `wazuh-dashboard-plugins` branch. +- `-b`, `--base`: Set the `wazuh-dashboard` branch. +- `-s`, `--security`: Set the `wazuh-security-dashboards-plugin` branch. +- `-r`, `--reporting`: Set the `wazuh-dashboards-reporting` branch. +- `--node-version`: [Optional] Set the node version. +- `--arm`: [Optional] Build for arm64 instead of x64. + +Example: + +```bash +bash run-docker-compose.sh \ + --app master \ + --base master \ + --security master \ + --reporting master \ + --arm \ + --node-version 18.19.0 +``` + +This example will create a packages folder that inside will have the packages divided by repository of the master branch of each one. \ No newline at end of file diff --git a/dev-tools/build-packages/base-packages-to-base/base-packages.Dockerfile b/dev-tools/build-packages/base-packages-to-base/base-packages.Dockerfile new file mode 100644 index 000000000000..72a5dd28dadb --- /dev/null +++ b/dev-tools/build-packages/base-packages-to-base/base-packages.Dockerfile @@ -0,0 +1,33 @@ +# Usage: +# docker build \ +# --build-arg NODE_VERSION=18.19.0 \ +# --build-arg WAZUH_DASHBOARD_BRANCH=4.10.2 \ +# --build-arg WAZUH_DASHBOARD_SECURITY_BRANCH=4.10.2 \ +# --build-arg WAZUH_DASHBOARD_PLUGINS_BRANCH=4.10.2 \ +# --build-arg ARCHITECTURE=arm \ +# -t wazuh-packages-to-base:4.10.2 \ +# -f base-packages.Dockerfile . + +ARG NODE_VERSION=18.19.0 +FROM node:${NODE_VERSION} AS base +ARG ARCHITECTURE='amd' +ARG WAZUH_DASHBOARD_BRANCH +ARG WAZUH_DASHBOARD_SECURITY_BRANCH +ARG WAZUH_DASHBOARD_PLUGINS_BRANCH +ARG WAZUH_DASHBOARD_REPORTING_BRANCH +ENV OPENSEARCH_DASHBOARDS_VERSION=2.16.0 +ENV ENV_ARCHITECTURE=${ARCHITECTURE} +USER root +RUN apt-get update && apt-get install -y jq +USER node +ADD ./clone-plugins.sh /home/node/clone-plugins.sh +ADD ./repositories/wazuh-dashboard.sh /home/node/repositories/wazuh-dashboard.sh +ADD ./repositories/plugins/wazuh-security-dashboards-plugin.sh /home/node/repositories/plugins/wazuh-security-dashboards-plugin.sh +ADD ./repositories/plugins/wazuh-dashboard-reporting.sh /home/node/repositories/plugins/wazuh-dashboard-reporting.sh +ADD ./repositories/plugins/wazuh-dashboard-plugins.sh /home/node/repositories/plugins/wazuh-dashboard-plugins.sh +RUN bash /home/node/clone-plugins.sh + +FROM node:${NODE_VERSION} +USER node +COPY --chown=node:node --from=base /home/node/packages /home/node/packages +WORKDIR /home/node/packages diff --git a/dev-tools/build-packages/base-packages-to-base/clone-plugins.sh b/dev-tools/build-packages/base-packages-to-base/clone-plugins.sh new file mode 100644 index 000000000000..2a70c6f141fd --- /dev/null +++ b/dev-tools/build-packages/base-packages-to-base/clone-plugins.sh @@ -0,0 +1,16 @@ +base_path_plugins="/home/node/app/plugins" +base_path_repositories_scripts="/home/node/repositories" +base_path_repositories_plugins_scripts="/home/node/repositories/plugins" +plugins=$(ls $base_path_repositories_plugins_scripts) + +mkdir /home/node/packages +echo "Cloning Wazuh dashboards" +source $base_path_repositories_scripts/wazuh-dashboard.sh + +for plugin in $plugins; do + echo "Cloning $plugin" + source $base_path_repositories_plugins_scripts/$plugin +done + + + diff --git a/dev-tools/build-packages/base-packages-to-base/docker-compose.yml b/dev-tools/build-packages/base-packages-to-base/docker-compose.yml new file mode 100644 index 000000000000..cae02d0d36dd --- /dev/null +++ b/dev-tools/build-packages/base-packages-to-base/docker-compose.yml @@ -0,0 +1,23 @@ + +services: + base: + image: base-${WAZUH_DASHBOARD_BRANCH}-${WAZUH_SECURITY_PLUGIN_BRANCH}-${WAZUH_DASHBOARD_PLUGINS_BRANCH}-${ARCHITECTURE} + build: + context: . + dockerfile: base-packages.Dockerfile + args: + NODE_VERSION: ${NODE_VERSION} + WAZUH_DASHBOARD_BRANCH: ${WAZUH_DASHBOARD_BRANCH} + WAZUH_DASHBOARD_SECURITY_BRANCH: ${WAZUH_SECURITY_PLUGIN_BRANCH} + WAZUH_DASHBOARD_PLUGINS_BRANCH: ${WAZUH_DASHBOARD_PLUGINS_BRANCH} + WAZUH_DASHBOARD_REPORTING_BRANCH: ${WAZUH_DASHBOARD_REPORTING_BRANCH} + ARCHITECTURE: ${ARCHITECTURE} + container_name: base-${WAZUH_DASHBOARD_BRANCH}-${WAZUH_SECURITY_PLUGIN_BRANCH}-${WAZUH_DASHBOARD_PLUGINS_BRANCH}-${WAZUH_DASHBOARD_REPORTING_BRANCH}-${ARCHITECTURE} + environment: + OPENSEARCH_DASHBOARDS_VERSION: 2.16.0 + volumes: + - ./:/home/node/output + command: > + bash -c ' + cp -r /home/node/packages /home/node/output + ' diff --git a/dev-tools/build-packages/base-packages-to-base/repositories/plugins/wazuh-dashboard-plugins.sh b/dev-tools/build-packages/base-packages-to-base/repositories/plugins/wazuh-dashboard-plugins.sh new file mode 100644 index 000000000000..7bde0a71da4b --- /dev/null +++ b/dev-tools/build-packages/base-packages-to-base/repositories/plugins/wazuh-dashboard-plugins.sh @@ -0,0 +1,17 @@ +base_path_plugins="/home/node/app/plugins" +cd $base_path_plugins +git clone --depth 1 --branch ${WAZUH_DASHBOARD_PLUGINS_BRANCH} https://github.com/wazuh/wazuh-dashboard-plugins.git +wazuh_dashboard_plugins=$(ls $base_path_plugins/wazuh-dashboard-plugins/plugins) +mv wazuh-dashboard-plugins/plugins/* ./ +mkdir /home/node/packages/wazuh-dashboard-plugins +for wazuh_dashboard_plugin in $wazuh_dashboard_plugins; do + cd $base_path_plugins/$wazuh_dashboard_plugin + yarn install + echo "Building $wazuh_dashboard_plugin" + yarn build + echo "Copying $wazuh_dashboard_plugin" + package_name=$(jq -r '.id' ./opensearch_dashboards.json) + cp $base_path_plugins/$wazuh_dashboard_plugin/build/$package_name-$OPENSEARCH_DASHBOARDS_VERSION.zip /home/node/packages/wazuh-dashboard-plugins/$package_name-$OPENSEARCH_DASHBOARDS_VERSION.zip +done +cd $base_path_plugins +rm -rf wazuh-dashboard-plugins diff --git a/dev-tools/build-packages/base-packages-to-base/repositories/plugins/wazuh-dashboard-reporting.sh b/dev-tools/build-packages/base-packages-to-base/repositories/plugins/wazuh-dashboard-reporting.sh new file mode 100644 index 000000000000..9e35b09e378f --- /dev/null +++ b/dev-tools/build-packages/base-packages-to-base/repositories/plugins/wazuh-dashboard-reporting.sh @@ -0,0 +1,10 @@ +# Clone the Wazuh security plugin +cd /home/node/app/plugins +git clone --depth 1 --branch ${WAZUH_DASHBOARD_REPORTING_BRANCH} https://github.com/wazuh/wazuh-dashboards-reporting.git +cd wazuh-dashboards-reporting +yarn install +echo "Building Wazuh reporting plugin" +yarn build +echo "Copying Wazuh reporting plugin" +mkdir /home/node/packages/wazuh-dashboards-reporting +cp -r build/* /home/node/packages/wazuh-dashboards-reporting diff --git a/dev-tools/build-packages/base-packages-to-base/repositories/plugins/wazuh-security-dashboards-plugin.sh b/dev-tools/build-packages/base-packages-to-base/repositories/plugins/wazuh-security-dashboards-plugin.sh new file mode 100644 index 000000000000..6ccbb4c0a5b1 --- /dev/null +++ b/dev-tools/build-packages/base-packages-to-base/repositories/plugins/wazuh-security-dashboards-plugin.sh @@ -0,0 +1,10 @@ +# Clone the Wazuh security plugin +cd /home/node/app/plugins +git clone --depth 1 --branch ${WAZUH_DASHBOARD_SECURITY_BRANCH} https://github.com/wazuh/wazuh-security-dashboards-plugin.git +cd wazuh-security-dashboards-plugin +yarn install +echo "Building Wazuh security plugin" +yarn build +echo "Copying Wazuh security plugin" +mkdir /home/node/packages/wazuh-security-dashboards-plugin +cp -r build/* /home/node/packages/wazuh-security-dashboards-plugin diff --git a/dev-tools/build-packages/base-packages-to-base/repositories/wazuh-dashboard.sh b/dev-tools/build-packages/base-packages-to-base/repositories/wazuh-dashboard.sh new file mode 100644 index 000000000000..967dd36268de --- /dev/null +++ b/dev-tools/build-packages/base-packages-to-base/repositories/wazuh-dashboard.sh @@ -0,0 +1,13 @@ +git clone --depth 1 --branch ${WAZUH_DASHBOARD_BRANCH} https://github.com/wazuh/wazuh-dashboard.git /home/node/app +cd /home/node/app +yarn osd bootstrap --production +echo "Building Wazuh dashboards" +if [ $ENV_ARCHITECTURE == "arm" ]; then + yarn build-platform --linux-arm --skip-os-packages --release +else + yarn build-platform --linux --skip-os-packages --release +fi +mkdir /home/node/packages/wazuh-dashboard +echo "Copying Wazuh dashboards" +ls -la /home/node/app/target +cp -r /home/node/app/target/*.tar.gz /home/node/packages/wazuh-dashboard diff --git a/dev-tools/build-packages/base-packages-to-base/run-docker-compose.sh b/dev-tools/build-packages/base-packages-to-base/run-docker-compose.sh new file mode 100644 index 000000000000..478c0da5893f --- /dev/null +++ b/dev-tools/build-packages/base-packages-to-base/run-docker-compose.sh @@ -0,0 +1,105 @@ +#!/bin/bash + +export WAZUH_DASHBOARD_PLUGINS_BRANCH="" +export WAZUH_DASHBOARD_BRANCH="" +export WAZUH_SECURITY_PLUGIN_BRANCH="" +export WAZUH_DASHBOARD_REPORTING_BRANCH="" +export ARCHITECTURE="amd" +export NODE_VERSION="18.19.0" + + +run_docker_compose() { + echo "WAZUH_DASHBOARD_PLUGINS_BRANCH: $WAZUH_DASHBOARD_PLUGINS_BRANCH" + echo "WAZUH_SECURITY_PLUGIN_BRANCH: $WAZUH_SECURITY_PLUGIN_BRANCH" + echo "WAZUH_DASHBOARD_BRANCH: $WAZUH_DASHBOARD_BRANCH" + echo "WAZUH_DASHBOARD_REPORTING_BRANCH: $WAZUH_DASHBOARD_REPORTING_BRANCH" + echo "ARCHITECTURE: $ARCHITECTURE" + echo "NODE_VERSION: $NODE_VERSION" + docker-compose up -d +} + +help() { + echo + echo "Usage: $0 [OPTIONS]" + echo " -a, --app Set the Wazuh plugin branch." + echo " -b, --base Set the wazuh-dashboard branch." + echo " -s, --security Set the wazuh-security-dashboards-plugin branch." + echo " -r, --reporting Set the wazuh-dashboards-reporting branch." + echo " --arm [Optional] Build for arm64 instead of x64." + echo " --node-version [Optional] Set the node version." + echo " -h, --help Show this help." + echo + exit $1 +} + +# ----------------------------------------------------------------------------- + +main() { + while [ -n "${1}" ]; do + case "${1}" in + "-h" | "--help") + help 0 + ;; + "-a" | "--app") + if [ -n "$2" ]; then + WAZUH_DASHBOARD_PLUGINS_BRANCH="$2" + shift 2 + else + help 1 + fi + ;; + "-s" | "--security") + if [ -n "${2}" ]; then + WAZUH_SECURITY_PLUGIN_BRANCH="${2}" + shift 2 + else + help 0 + fi + ;; + "-b" | "--base") + if [ -n "${2}" ]; then + WAZUH_DASHBOARD_BRANCH="${2}" + shift 2 + else + help 0 + fi + ;; + "-r" | "--reporting") + if [ -n "${2}" ]; then + WAZUH_DASHBOARD_REPORTING_BRANCH="${2}" + shift 2 + else + help 0 + fi + ;; + "--arm") + ARCHITECTURE="arm" + shift 1 + ;; + "--node-version") + if [ -n "${2}" ]; then + NODE_VERSION="${2}" + shift 2 + else + help 0 + fi + ;; + *) + echo "help" + + help 1 + ;; + esac + done + + if [ -z "$WAZUH_DASHBOARD_PLUGINS_BRANCH" ] | [ -z "$WAZUH_DASHBOARD_BRANCH" ] | [ -z "$WAZUH_SECURITY_PLUGIN_BRANCH" ]; then + echo "You must specify the app, base, security." + help 1 + fi + + run_docker_compose || exit 1 + + exit 0 +} + +main "$@" diff --git a/dev-tools/build-packages/base/Docker/Dockerfile b/dev-tools/build-packages/base/Docker/Dockerfile new file mode 100644 index 000000000000..6614bda6ce49 --- /dev/null +++ b/dev-tools/build-packages/base/Docker/Dockerfile @@ -0,0 +1,35 @@ +FROM rockylinux:8.5 + +# Install all the necessary tools to build the packages +RUN yum clean all && yum update -y +RUN yum install -y \ + curl \ + tar \ + findutils \ + git \ + xz \ + gcc \ + make \ + bc \ + sed \ + gzip \ + autoconf \ + automake \ + libtool \ + python3-devel \ + python3-pip \ + jq \ + unzip + +RUN git clone https://github.com/google/brotli.git -b v1.0.9 + +RUN cd brotli && chmod +x ./bootstrap && ./bootstrap && ./configure --prefix=/usr --bindir=/usr/bin --sbindir=/usr/sbin --libexecdir=/usr/lib64/brotli --libdir=/usr/lib64/brotli --datarootdir=/usr/share --mandir=/usr/share/man/man1 --docdir=/usr/share/doc \ + && make && make install + +# Add the scripts to build the RPM package +ADD base-builder.sh /usr/local/bin/builder +ADD plugins /usr/local/bin/plugins +RUN chmod +x /usr/local/bin/builder + +# Set the entrypoint +ENTRYPOINT ["/usr/local/bin/builder"] diff --git a/dev-tools/build-packages/base/base-builder.sh b/dev-tools/build-packages/base/base-builder.sh new file mode 100755 index 000000000000..4a245af2aeef --- /dev/null +++ b/dev-tools/build-packages/base/base-builder.sh @@ -0,0 +1,162 @@ +#!/bin/bash + +# Wazuh package generator +# Copyright (C) 2022, Wazuh Inc. +# +# This program is a free software; you can redistribute it +# and/or modify it under the terms of the GNU General Public +# License (version 2) as published by the FSF - Free Software +# Foundation. + +set -e + +# Inputs +version="$1" +revision="$2" +architecture="$3" +verbose="$4" + +if [ "$verbose" = "debug" ]; then + set -x +fi + +trap clean INT +trap clean EXIT + +log() { + if [ "$verbose" = "info" ] || [ "$verbose" = "debug" ]; then + echo "$@" + fi +} + +clean() { + exit_code=$? + # Clean the files + rm -rf ${tmp_dir}/* + trap '' EXIT + exit ${exit_code} +} + +# Paths +current_path="$( cd $(dirname $0) ; pwd -P )" + +# Folders +tmp_dir="/tmp" +out_dir="/output" +config_path=$tmp_dir/config + + +# ----------------------------------------------------------------------------- +cd $tmp_dir + +log +log "Extracting packages" +log + +mkdir -p applications +mkdir -p base +packages_list=(app base security reportPlugin) +packages_names=("Wazuh plugins" "Wazuh Dashboard" "Security plugin" "Report plugin") + + +for i in "${!packages_list[@]}"; do + package_var="${packages_list[$i]}" + package_name="${packages_names[$i]}" + if [[ "$package_var" == "base" ]]; then + wzd_package_name=$(unzip -l "packages/${package_var}.zip" | awk 'NR==4 {print $4}') + unzip -o -q "packages/${package_var}.zip" -d base + else + unzip -o -q "packages/${package_var}.zip" -d applications + fi +done + +cd base + +log +log "Installing plugins" +log + +tar -zxf $wzd_package_name +directory_name=$(ls -td */ | head -1) +cd $directory_name +plugins=$(ls $tmp_dir/applications)' '$(cat $current_path/plugins) + for plugin in $plugins; do + if [[ $plugin =~ .*\.zip ]]; then + install="file://${tmp_dir}/applications/${plugin}" + else + install=$plugin + fi + log "Installing ${plugin} plugin" + if ! bin/opensearch-dashboards-plugin install $install 2>&1 --allow-root> /dev/null; then + echo "Plugin ${plugin} installation failed" + exit 1 + fi + log "Plugin ${plugin} installed successfully" + log + done + +log +log "Replacing application categories" +log + +category_explore='{id:"explore",label:"Explore",order:100,euiIconType:"search"}' +category_dashboard_management='{id:"management",label:"Indexer management",order:6e3,euiIconType:"managementApp"}' + +# Replace app category to Reporting app +sed -i -e "s|category:{id:\"opensearch\",label:_i18n.i18n.translate(\"opensearch.reports.categoryName\",{defaultMessage:\"OpenSearch Plugins\"}),order:2e3}|category:${category_explore}|" ./plugins/reportsDashboards/target/public/reportsDashboards.plugin.js + +# Replace app category to Alerting app +sed -i -e "s|category:{id:\"opensearch\",label:\"OpenSearch Plugins\",order:2e3}|category:${category_explore}|" ./plugins/alertingDashboards/target/public/alertingDashboards.plugin.js + +# Replace app category to Maps app +sed -i -e "s|category:{id:\"opensearch\",label:\"OpenSearch Plugins\",order:2e3}|category:${category_explore}|" ./plugins/customImportMapDashboards/target/public/customImportMapDashboards.plugin.js + +# Replace app category to Notifications app +sed -i -e "s|category:DEFAULT_APP_CATEGORIES.management|category:${category_explore}|" ./plugins/notificationsDashboards/target/public/notificationsDashboards.plugin.js + +# Replace app category to Index Management app +sed -i -e "s|category:DEFAULT_APP_CATEGORIES.management|category:${category_dashboard_management}|g" ./plugins/indexManagementDashboards/target/public/indexManagementDashboards.plugin.js + + +log +log "Recreating plugin files" +log + +# Generate compressed files +files_to_recreate=( + ./plugins/reportsDashboards/target/public/reportsDashboards.plugin.js + ./plugins/alertingDashboards/target/public/alertingDashboards.plugin.js + ./plugins/customImportMapDashboards/target/public/customImportMapDashboards.plugin.js + ./plugins/notificationsDashboards/target/public/notificationsDashboards.plugin.js + ./plugins/indexManagementDashboards/target/public/indexManagementDashboards.plugin.js +) + +for value in "${files_to_recreate[@]}" +do + gzip -c "$value" > "$value.gz" + brotli -c "$value" > "$value.br" +done + +log +log "Adding configuration files" +log + +cp -f $config_path/opensearch_dashboards.prod.yml config/opensearch_dashboards.yml +cp -f $config_path/node.options.prod config/node.options + +log +log "Fixing shebangs" +log +# TODO: investigate to remove this if possible +# Fix ambiguous shebangs (necessary for RPM building) +grep -rnwl './node_modules/' -e '#!/usr/bin/env python$' | xargs -I {} sed -i 's/#!\/usr\/bin\/env python/#!\/usr\/bin\/env python3/g' {} +grep -rnwl './node_modules/' -e '#!/usr/bin/python$' | xargs -I {} sed -i 's/#!\/usr\/bin\/python/#!\/usr\/bin\/python3/g' {} + +log +log "Compressing final package" +log + +mkdir -p $out_dir +tar -czf $out_dir/wazuh-dashboard-$version-$revision-linux-$architecture.tar.gz * + +log Done! diff --git a/dev-tools/build-packages/base/generate_base.sh b/dev-tools/build-packages/base/generate_base.sh deleted file mode 100755 index 8a4f7fab5a97..000000000000 --- a/dev-tools/build-packages/base/generate_base.sh +++ /dev/null @@ -1,315 +0,0 @@ -#!/bin/bash - -# Wazuh package generator -# Copyright (C) 2022, Wazuh Inc. -# -# This program is a free software; you can redistribute it -# and/or modify it under the terms of the GNU General Public -# License (version 2) as published by the FSF - Free Software -# Foundation. - -set -e - -# Inputs -app="" -base="" -revision="1" -security="" -version="" -reportPlugin="" - -# Paths -current_path="$( cd $(dirname $0) ; pwd -P )" -config_path=$(realpath $current_path/../../../config) - -# Folders -out_dir="${current_path}/output" -tmp_dir="${current_path}/tmp" - -trap ctrl_c INT - -clean() { - exit_code=$1 - echo - echo "Cleaning temporary files..." - echo - # Clean the files - rm -r $tmp_dir - - if [ $exit_code != 0 ]; then - rm $out_dir/*.tar.gz - rmdir $out_dir - fi - - exit ${exit_code} -} - -ctrl_c() { - clean 1 -} - -# ----------------------------------------------------------------------------- - -build() { - # Validate and download files to build the package - valid_url='(https?|ftp|file)://[-[:alnum:]\+&@#/%?=~_|!:,.;]*[-[:alnum:]\+&@#/%=~_|]' - echo - echo "Downloading plugins..." - echo - mkdir -p $tmp_dir - cd $tmp_dir - mkdir -p applications - mkdir -p dashboards - if [[ $app =~ $valid_url ]]; then - if ! curl --output applications/app.zip --silent --fail "${app}"; then - echo "The given URL or Path to the Wazuh Apps is not working: ${app}" - clean 1 - else - echo "Extracting applications from app.zip" - unzip -q applications/app.zip -d applications - rm applications/app.zip - fi - else - echo "The given URL or Path to the Wazuh App is not valid: ${app}" - clean 1 - fi - - echo - echo "Downloading dashboards..." - echo - if [[ $base =~ $valid_url ]]; then - if [[ $base =~ .*\.zip ]]; then - if ! curl --output wazuh-dashboard.zip --silent --fail "${base}"; then - echo "The given URL or Path to the Wazuh Dashboard base is not working: ${base}" - clean 1 - else - echo "Extracting Wazuh Dashboard base" - unzip -q wazuh-dashboard.zip -d ./dashboards/ - rm wazuh-dashboard.zip - mv ./dashboards/$(ls ./dashboards) wazuh-dashboard.tar.gz - fi - else - if ! curl --output wazuh-dashboard.tar.gz --silent --fail "${base}"; then - echo "The given URL or Path to the Wazuh Dashboard base is not working: ${base}" - clean 1 - fi - fi - else - echo "The given URL or Path to the Wazuh Dashboard base is not valid: ${base}" - clean 1 - fi - - echo - echo "Downloading security plugin..." - echo - - if [[ $security =~ $valid_url ]]; then - if ! curl --output applications/security.zip --silent --fail "${security}"; then - echo "The given URL or Path to the Wazuh Security Plugin is not working: ${security}" - clean 1 - else - echo "Extracting Security application" - unzip -q applications/security.zip -d applications - rm applications/security.zip - fi - else - echo "The given URL or Path to the Wazuh Security Plugin is not valid: ${security}" - clean 1 - fi - - echo - echo "Downloading report plugin.." - echo - - if [[ $reportPlugin =~ $valid_url ]]; then - if ! curl --output applications/reporting.zip --silent --fail "${reportPlugin}"; then - echo "The given URL or Path to the Wazuh Reporting Plugin is not working: ${reportPlugin}" - clean 1 - else - echo "Extracting Reporting application" - unzip -q applications/reporting.zip -d applications - rm applications/reporting.zip - fi - else - echo "The given URL or Path to the Wazuh Reporting Plugin is not valid: ${reportPlugin}" - clean 1 - fi - - tar -zxf wazuh-dashboard.tar.gz - directory_name=$(ls -td */ | head -1) - working_dir="wazuh-dashboard-$version-$revision-linux-x64" - mv $directory_name $working_dir - cd $working_dir - - echo - echo Building the package... - echo - - # Install Wazuh apps, Reporting app and Security app - - plugins=$(ls $tmp_dir/applications)' '$(cat $current_path/plugins) - for plugin in $plugins; do - if [[ $plugin =~ .*\.zip ]]; then - install='file:../applications/'$plugin - else - install=$plugin - fi - echo "Installing ${plugin%.*} plugin" - if ! bin/opensearch-dashboards-plugin install $install 2>&1 > /dev/null; then - echo "Plugin installation failed" - clean 1 - fi - done - - echo - echo Finished installing plugins - echo - - # Move installed plugins from categories after generating the package - category_explore='{id:"explore",label:"Explore",order:100,euiIconType:"search"}' - category_dashboard_management='{id:"management",label:"Indexer management",order:5e3,euiIconType:"managementApp"}' - - # Replace app category to Alerting app - sed -i -e "s|category:{id:\"opensearch\",label:\"OpenSearch Plugins\",order:2e3}|category:${category_explore}|" ./plugins/alertingDashboards/target/public/alertingDashboards.plugin.js - - # Replace app category to Maps app - sed -i -e "s|category:{id:\"opensearch\",label:\"OpenSearch Plugins\",order:2e3}|category:${category_explore}|" ./plugins/customImportMapDashboards/target/public/customImportMapDashboards.plugin.js - - # Replace app category to Notifications app - sed -i -e "s|category:DEFAULT_APP_CATEGORIES.management|category:${category_explore}|" ./plugins/notificationsDashboards/target/public/notificationsDashboards.plugin.js - - # Replace app category to Indexer Management app - sed -i -e "s|category:DEFAULT_APP_CATEGORIES.management|category:${category_dashboard_management}|g" ./plugins/indexManagementDashboards/target/public/indexManagementDashboards.plugin.js - - # Generate compressed files - files_to_recreate=( - ./plugins/alertingDashboards/target/public/alertingDashboards.plugin.js - ./plugins/customImportMapDashboards/target/public/customImportMapDashboards.plugin.js - ./plugins/notificationsDashboards/target/public/notificationsDashboards.plugin.js - ./plugins/indexManagementDashboards/target/public/indexManagementDashboards.plugin.js - ) - - for value in "${files_to_recreate[@]}" - do - gzip -c "$value" > "$value.gz" - brotli -c "$value" > "$value.br" - done - - # Enable the default configuration (renaming) - cp $config_path/opensearch_dashboards.prod.yml config/opensearch_dashboards.yml - cp $config_path/node.options.prod config/node.options - - # TODO: investigate to remove this if possible - # Fix ambiguous shebangs (necessary for RPM building) - grep -rnwl './node_modules/' -e '#!/usr/bin/env python$' | xargs -I {} sed -i 's/#!\/usr\/bin\/env python/#!\/usr\/bin\/env python3/g' {} - grep -rnwl './node_modules/' -e '#!/usr/bin/python$' | xargs -I {} sed -i 's/#!\/usr\/bin\/python/#!\/usr\/bin\/python3/g' {} - - # Compress - echo - echo Compressing the package... - echo - cd .. - if [ ! -d "$out_dir" ]; then - mkdir -p $out_dir - fi - tar -czf $out_dir/$working_dir.tar.gz $working_dir - - echo - echo DONE! - echo - clean 0 -} - -# ----------------------------------------------------------------------------- - -help() { - echo - echo "Usage: $0 [OPTIONS]" - echo " -a, --app Set the location of the .zip file containing the Wazuh plugin." - echo " -b, --base Set the location of the .tar.gz file containing the base wazuh-dashboard build." - echo " -s, --security Set the location of the .zip file containing the wazuh-security-dashboards-plugin." - echo " -v, --version Set the version of this build." - echo " -r, --revision [Optional] Set the revision of this build. By default, it is set to 1." - echo " -o, --output [Optional] Set the destination path of package. By default, an output folder will be created." - echo " -h, --help Show this help." - echo - exit $1 -} - -# ----------------------------------------------------------------------------- - -main() { - while [ -n "${1}" ]; do - case "${1}" in - "-h" | "--help") - help 0 - ;; - "-a" | "--app") - if [ -n "$2" ]; then - app="$2" - shift 2 - else - help 1 - fi - ;; - "-s" | "--security") - if [ -n "${2}" ]; then - security="${2}" - shift 2 - else - help 0 - fi - ;; - "-b" | "--base") - if [ -n "${2}" ]; then - base="${2}" - shift 2 - else - help 0 - fi - ;; - "-rp" | "--reportPlugin") - if [ -n "${2}" ]; then - reportPlugin="${2}" - shift 2 - else - help 0 - fi - ;; - "-v" | "--version") - if [ -n "${2}" ]; then - version="${2}" - shift 2 - else - help 0 - fi - ;; - "-r" | "--revision") - if [ -n "${2}" ]; then - revision="${2}" - shift 2 - fi - ;; - "-o" | "--output") - if [ -n "${2}" ]; then - output="${2}" - shift 2 - fi - ;; - *) - - help 1 - ;; - esac - done - - if [ -z "$app" ] | [ -z "$base" ] | [ -z "$security" ] | [ -z "$version" ]; then - help 1 - fi - - build || exit 1 - - exit 0 -} - -main "$@" diff --git a/dev-tools/build-packages/build-packages.sh b/dev-tools/build-packages/build-packages.sh index 662b59ad723d..15ff7dddcd56 100755 --- a/dev-tools/build-packages/build-packages.sh +++ b/dev-tools/build-packages/build-packages.sh @@ -1,4 +1,5 @@ #!/bin/bash +set -e app="" base="" @@ -10,59 +11,136 @@ all_platforms="no" deb="no" rpm="no" tar="no" -output="$( cd $(dirname $0) ; pwd -P )/output" -production="" +architecture="x64" +production="no" +commit_sha=$(git rev-parse --short HEAD) current_path="$( cd $(dirname $0) ; pwd -P )" +output_dir="${current_path}/output" +tmp_dir="${current_path}/tmp" +config_dir="${current_path}/../../config" +package_config_dir="${current_path}/config" +verbose="info" -build_tar() { - echo "Building tar package..." - cd ./base - bash ./generate_base.sh -a $app -b $base -s $security -rp $reportPlugin -v $version -r $revision +trap clean INT +trap clean EXIT - name_package_tar=$(ls ./output) +log() { + if [ "$verbose" = "info" ] || [ "$verbose" = "debug" ]; then + echo "$@" + fi +} - echo "Moving tar package to $output" - mv $current_path/base/output/$name_package_tar $output/$name_package_tar - cd ../ +clean() { + exit_code=$? + echo + echo "Cleaning temporary files..." + echo + # Clean the files + rm -rf ${tmp_dir} + rm -f ${current_path}/base/Docker/base-builder.sh + rm -f ${current_path}/base/Docker/plugins + rm -f ${current_path}/rpm/Docker/rpm-builder.sh + rm -f ${current_path}/rpm/Docker/wazuh-dashboard.spec + rm -f ${current_path}/deb/Docker/deb-builder.sh + rm -rf ${current_path}/deb/Docker/debian + trap '' EXIT + exit ${exit_code} } -build_deb() { - echo "Building deb package..." - name_package_tar=$(find $output -name "*.tar.gz") - cd ./deb - bash ./launcher.sh -v $version -r $revision -p file://$name_package_tar $production - name_package_tar=$(ls ./output) - echo "Moving deb package to $output/deb" - mv $current_path/deb/output $output/deb - cd ../ +ctrl_c() { + clean 1 +} + +get_packages(){ + packages_list=(app base security reportPlugin) + packages_names=("Wazuh plugins" "Wazuh Dashboard" "Security plugin" "Report plugin") + valid_url='(https?|ftp|file)://[-[:alnum:]\+&@#/%?=~_|!:,.;]*[-[:alnum:]\+&@#/%=~_|]' + mkdir -p ${tmp_dir} + cd ${tmp_dir} + mkdir -p packages + for i in "${!packages_list[@]}"; do + package_var="${packages_list[$i]}" + package_name="${packages_names[$i]}" + package_url="${!package_var}" + + log + log "Downloading ${package_name}" + + if [[ $package_url =~ $valid_url ]]; then + if ! curl --output "packages/${package_var}.zip" --silent --fail "${package_url}"; then + echo "The given URL or Path to the ${package_name} is not working: ${package_url}" + clean 1 + fi + else + echo "The given URL or Path to the ${package_name} is not valid: ${package_url}" + clean 1 + fi + log "Done!" + log + done + cd .. +} + +build_tar() { + log + log "Building base package..." + log + mkdir -p ${output_dir} + cp -r ${config_dir} ${tmp_dir} + cd ./base + dockerfile_path="${current_path}/base/Docker" + container_name="dashboard-base-builder" + cp ./base-builder.sh ${dockerfile_path} + cp ./plugins ${dockerfile_path} + docker build -t ${container_name} ${dockerfile_path} || return 1 + docker run -t --rm -v ${tmp_dir}/:/tmp:Z -v ${output_dir}/:/output:Z\ + ${container_name} ${version} ${revision} ${architecture} ${verbose}|| return 1 + cd .. } build_rpm() { - echo "Building rpm package..." - name_package_tar=$(find $output -name "*.tar.gz") + log "Building rpm package..." cd ./rpm - bash ./launcher.sh -v $version -r $revision -p file://$name_package_tar $production - echo "Moving rpm package to $output/rpm" - mv $current_path/rpm/output $output/rpm + dockerfile_path="${current_path}/rpm/Docker" + container_name="dashboard-rpm-builder" + cp -r ${package_config_dir} ${tmp_dir} + cp ./rpm-builder.sh ${dockerfile_path} + cp ./wazuh-dashboard.spec ${dockerfile_path} + docker build -t ${container_name} ${dockerfile_path} || return 1 + docker run -t --rm -v ${tmp_dir}/:/tmp:Z -v ${output_dir}/:/output:Z\ + ${container_name} ${version} ${revision} ${architecture}\ + ${commit_sha} ${production} ${verbose}|| return 1 cd ../ } -build() { - name_package_tar="wazuh-dashboard-$version-$revision-linux-x64.tar.gz" +build_deb() { + log "Building deb package..." + cd ./deb + dockerfile_path="${current_path}/deb/Docker" + container_name="dashboard-deb-builder" + cp -r ${package_config_dir} ${tmp_dir} + cp ./deb-builder.sh ${dockerfile_path} + cp -r ./debian ${dockerfile_path} + docker build -t ${container_name} ${dockerfile_path} || return 1 + docker run -t --rm -v ${tmp_dir}/:/tmp:Z -v ${output_dir}/:/output:Z \ + ${container_name} ${version} ${revision} ${architecture}\ + ${commit_sha} ${production} ${verbose}|| return 1 + cd .. +} - if [ ! -d "$output" ]; then - mkdir $output - fi + + +build(){ + log "Building package..." if [ "$all_platforms" == "yes" ]; then deb="yes" rpm="yes" tar="yes" fi - + get_packages build_tar - cd $current_path if [ $deb == "yes" ]; then echo "Building deb package..." @@ -76,7 +154,7 @@ build() { if [ "$tar" == "no" ]; then echo "Removing tar package..." - rm -r $(find $output -name "*.tar.gz") + rm -r $(find $output_dir -name "*.tar.gz") fi } @@ -86,14 +164,17 @@ help() { echo " -a, --app Set the location of the .zip file containing the Wazuh plugin." echo " -b, --base Set the location of the .tar.gz file containing the base wazuh-dashboard build." echo " -s, --security Set the location of the .zip file containing the wazuh-security-dashboards-plugin." + echo " -rp, --reportPlugin Set the location of the .zip file containing the wazuh-reporting-plugin." echo " -v, --version Set the version of this build." echo " --all-platforms Build for all platforms." echo " --deb Build for deb." echo " --rpm Build for rpm." echo " --tar Build for tar." echo " --production [Optional] The naming of the package will be ready for production." + echo " --arm [Optional] Build for arm64 instead of x64." + echo " --debug [Optional] Debug mode." + echo " --silent [Optional] Silent mode. Will not work if --debug is set." echo " -r, --revision [Optional] Set the revision of this build. By default, it is set to 1." - echo " -o, --output [Optional] Set the destination path of package. By default, an output folder will be created." echo " -h, --help Show this help." echo exit $1 @@ -154,7 +235,7 @@ main() { fi ;; "--production") - production="--production" + production="yes" shift 1 ;; "--all-platforms") @@ -173,6 +254,19 @@ main() { tar="yes" shift 1 ;; + "--arm") + architecture="arm64" + shift 1 + ;; + "--silent") + verbose="silent" + shift 1 + ;; + "--debug") + verbose="debug" + shift 1 + ;; + "-o" | "--output") if [ -n "${2}" ]; then output="${2}" @@ -197,6 +291,10 @@ main() { help 1 fi + if [ "$verbose" = "debug" ]; then + set -x + fi + build || exit 1 exit 0 diff --git a/dev-tools/build-packages/deb/docker/amd64/Dockerfile b/dev-tools/build-packages/deb/Docker/Dockerfile similarity index 63% rename from dev-tools/build-packages/deb/docker/amd64/Dockerfile rename to dev-tools/build-packages/deb/Docker/Dockerfile index f3ca3b981113..6289cd35d3ad 100644 --- a/dev-tools/build-packages/deb/docker/amd64/Dockerfile +++ b/dev-tools/build-packages/deb/Docker/Dockerfile @@ -1,16 +1,17 @@ FROM debian:10 -ENV DEBIAN_FRONTEND noninteractive +ENV DEBIAN_FRONTEND=noninteractive # Installing necessary packages RUN apt-get update && apt-get install -y --allow-change-held-packages apt-utils && \ apt-get install -y --allow-change-held-packages \ curl sudo wget expect gnupg build-essential \ - devscripts equivs selinux-basics procps gawk + devscripts equivs selinux-basics procps gawk jq # Add the script to build the Debian package -ADD builder.sh /usr/local/bin/builder +ADD deb-builder.sh /usr/local/bin/builder +ADD debian /usr/local/src/debian RUN chmod +x /usr/local/bin/builder # Set the entrypoint -ENTRYPOINT ["/usr/local/bin/builder"] \ No newline at end of file +ENTRYPOINT ["/usr/local/bin/builder"] diff --git a/dev-tools/build-packages/deb/builder.sh b/dev-tools/build-packages/deb/deb-builder.sh similarity index 53% rename from dev-tools/build-packages/deb/builder.sh rename to dev-tools/build-packages/deb/deb-builder.sh index 925997dd4b12..3e0e993d8c7a 100755 --- a/dev-tools/build-packages/deb/builder.sh +++ b/dev-tools/build-packages/deb/deb-builder.sh @@ -12,13 +12,58 @@ set -e # Script parameters to build the package target="wazuh-dashboard" -architecture=$1 +version=$1 revision=$2 -version=$3 +architecture=$3 commit_sha=$4 is_production=$5 +verbose=$6 + directory_base="/usr/share/wazuh-dashboard" +# Paths +current_path="$( cd $(dirname $0) ; pwd -P )" + +# Folders +tmp_dir="/tmp" +out_dir="/output" +config_path=$tmp_dir/config + +if [ "$verbose" = "debug" ]; then + set -x +fi +trap clean INT +trap clean EXIT + +log() { + if [ "$verbose" = "info" ] || [ "$verbose" = "debug" ]; then + echo "$@" + fi +} + +clean() { + exit_code=$? + # Clean the files + rm -rf ${tmp_dir}/* + trap '' EXIT + exit ${exit_code} +} + +mkdir -p ${tmp_dir}/wazuh-dashboard-base +cd ${tmp_dir}/wazuh-dashboard-base +log "Extracting base tar.gz..." +tar -zxf ${out_dir}/wazuh-dashboard-$version-$revision-linux-$architecture.tar.gz +log "Preparing the package..." +jq '.wazuh.revision="'${revision}'"' package.json > pkgtmp.json && mv pkgtmp.json package.json +cp $config_path/* . +echo ${version} > VERSION +cd .. +tar -czf wazuh-dashboard.tar.gz wazuh-dashboard-base + +log "Setting up parameters" +if [ "${architecture}" = "x64" ]; then + architecture="amd64" +fi # Build directories build_dir=/build pkg_name="${target}-${version}" @@ -29,8 +74,8 @@ final_name="${target}_${version}-${revision}_${architecture}_${commit_sha}.deb" mkdir -p ${source_dir}/debian -# Including spec file -cp -r /root/build-packages/deb/debian/* ${source_dir}/debian/ +# Including spec files +cp -r /usr/local/src/debian/* ${source_dir}/debian/ # Generating directory structure to build the .deb package cd ${build_dir}/${target} && tar -czf ${pkg_name}.orig.tar.gz "${pkg_name}" @@ -44,17 +89,18 @@ sed -i "s:export INSTALLATION_DIR=.*:export INSTALLATION_DIR=${directory_base}:g cd ${source_dir} mk-build-deps -ir -t "apt-get -o Debug::pkgProblemResolver=yes -y" +log "Building the package..." # Build package debuild --no-lintian -b -uc -us \ -eINSTALLATION_DIR="${directory_base}" \ -eVERSION="${version}" \ -eREVISION="${revision}" -cd ${pkg_path} && sha512sum ${deb_file} >/tmp/${deb_file}.sha512 +cd ${pkg_path} && sha512sum ${deb_file} >/${out_dir}/${deb_file}.sha512 if [ "${is_production}" = "no" ]; then - mv ${pkg_path}/${deb_file} /tmp/${final_name} - mv /tmp/${deb_file}.sha512 /tmp/${final_name}.sha512 + mv ${pkg_path}/${deb_file} /${out_dir}/${final_name} + mv /${out_dir}/${deb_file}.sha512 /${out_dir}/${final_name}.sha512 else - mv ${pkg_path}/${deb_file} /tmp/ + mv ${pkg_path}/${deb_file} /${out_dir}/ fi diff --git a/dev-tools/build-packages/deb/debian/rules b/dev-tools/build-packages/deb/debian/rules index 7fe98ddcc597..ac2087b35ef0 100644 --- a/dev-tools/build-packages/deb/debian/rules +++ b/dev-tools/build-packages/deb/debian/rules @@ -52,7 +52,7 @@ override_dh_auto_install: # ----------------------------------------------------------------------------- override_dh_install: - cp /opt/$(DASHBOARD_FILE) ./ + cp /tmp/$(DASHBOARD_FILE) ./ groupadd $(GROUP) useradd -g $(GROUP) $(USER) diff --git a/dev-tools/build-packages/deb/launcher.sh b/dev-tools/build-packages/deb/launcher.sh deleted file mode 100755 index dcab4b3653f0..000000000000 --- a/dev-tools/build-packages/deb/launcher.sh +++ /dev/null @@ -1,204 +0,0 @@ -#!/bin/bash - -# Wazuh package generator -# Copyright (C) 2021, Wazuh Inc. -# -# This program is a free software; you can redistribute it -# and/or modify it under the terms of the GNU General Public -# License (version 2) as published by the FSF - Free Software -# Foundation. - -# Inputs -package="" -version="" -revision="0" -architecture="amd64" -build_base="yes" -build_docker="yes" -is_production="no" - -# Constants -deb_amd64_builder="deb_dashboard_builder_amd64" -deb_builder_dockerfile="${current_path}/docker" -commit_sha=$(git rev-parse --short HEAD) - -# Paths -current_path="$( cd $(dirname $0) ; pwd -P )" -config_path=$(realpath $current_path/../config) - -# Folders -out_dir="${current_path}/output" -tmp_dir="${current_path}/tmp" - -trap ctrl_c INT - -clean() { - exit_code=$1 - echo - echo "Cleaning temporary files..." - echo - # Clean the files - rm -r $tmp_dir - rm $current_path/docker/amd64/*.sh - if [ $exit_code != 0 ]; then - rm $out_dir/* - rmdir $out_dir - fi - - exit ${exit_code} -} - -ctrl_c() { - clean 1 -} - -build_deb() { - container_name="$1" - dockerfile_path="$2" - - # Validate and download files to build the package - valid_url='(https?|ftp|file)://[-[:alnum:]\+&@#/%?=~_|!:,.;]*[-[:alnum:]\+&@#/%=~_|]' - - echo - echo "Downloading files..." - echo - - mkdir -p $tmp_dir - cd $tmp_dir - - if [[ $package =~ $valid_url ]]; then - if ! curl --output wazuh-dashboard.tar.gz --silent --fail "${package}"; then - echo "The given URL or Path to the Wazuh Dashboard package is not working: ${package}" - clean 1 - fi - else - echo "The given URL or Path to the Wazuh Dashboard package is not valid: ${package}" - clean 1 - fi - - echo - echo Building the package... - echo - - # Prepare the package - tar -zxf wazuh-dashboard.tar.gz - directory_name=$(ls -td */ | head -1) - rm wazuh-dashboard.tar.gz - mv $directory_name wazuh-dashboard-base - jq '.wazuh.revision="'${revision}'"' wazuh-dashboard-base/package.json > pkgtmp.json && mv pkgtmp.json wazuh-dashboard-base/package.json - cp $config_path/* wazuh-dashboard-base - echo ${version} >wazuh-dashboard-base/VERSION - tar -czf ./wazuh-dashboard.tar.gz wazuh-dashboard-base - - # Copy the necessary files - cp ${current_path}/builder.sh ${dockerfile_path} - - # Build the Docker image - if [[ ${build_docker} == "yes" ]]; then - docker build -t ${container_name} ${dockerfile_path} || return 1 - fi - # Build the Debian package with a Docker container - if [ ! -d "$out_dir" ]; then - mkdir -p $out_dir - fi - - volumes="-v ${out_dir}/:/tmp:Z -v ${tmp_dir}/wazuh-dashboard.tar.gz:/opt/wazuh-dashboard.tar.gz" - docker run -t --rm ${volumes} \ - -v ${current_path}/../..:/root:Z \ - ${container_name} ${architecture} \ - ${revision} ${version} ${commit_sha} ${is_production}\ - || return 1 - - echo "Package $(ls -Art ${out_dir} | tail -n 1) added to ${out_dir}." - - echo - echo DONE! - echo - - return 0 -} - -build() { - build_name="${deb_amd64_builder}" - file_path="../${deb_builder_dockerfile}/${architecture}" - build_deb ${build_name} ${file_path} ${commit_sha} ${is_production}|| return 1 - return 0 -} - -help() { - echo - echo "Usage: $0 [OPTIONS]" - echo - echo " -v, --version Wazuh version" - echo " -p, --package Set the location of the .tar.gz file containing the Wazuh Dashboard package." - echo " -r, --revision [Optional] Package revision. By default: 1." - echo " -o, --output [Optional] Set the destination path of package. By default, an output folder will be created." - echo " --dont-build-docker [Optional] Locally built Docker image will be used instead of generating a new one." - echo " --production [Optional] The naming of the package will be ready for production." - echo " -h, --help Show this help." - echo - exit $1 -} - -main() { - while [ -n "${1}" ]; do - case "${1}" in - "-h" | "--help") - help 0 - ;; - "-p" | "--package") - if [ -n "${2}" ]; then - package="${2}" - shift 2 - else - help 1 - fi - ;; - "-v" | "--version") - if [ -n "${2}" ]; then - version="${2}" - shift 2 - else - help 1 - fi - ;; - "-r" | "--revision") - if [ -n "${2}" ]; then - revision="${2}" - shift 2 - else - help 1 - fi - ;; - "--dont-build-docker") - build_docker="no" - shift 1 - ;; - "--production") - is_production="yes" - shift 1 - ;; - "-o" | "--output") - if [ -n "${2}" ]; then - out_dir="${2}" - shift 2 - else - help 1 - fi - ;; - *) - help 1 - ;; - esac - done - - if [ -z "$package" ] | [ -z "$version" ]; then - help 1 - fi - - build || clean 1 - - clean 0 -} - -main "$@" diff --git a/dev-tools/build-packages/rpm/docker/x86_64/Dockerfile b/dev-tools/build-packages/rpm/Docker/Dockerfile similarity index 80% rename from dev-tools/build-packages/rpm/docker/x86_64/Dockerfile rename to dev-tools/build-packages/rpm/Docker/Dockerfile index eb6493d15878..c62abf3820c1 100644 --- a/dev-tools/build-packages/rpm/docker/x86_64/Dockerfile +++ b/dev-tools/build-packages/rpm/Docker/Dockerfile @@ -5,16 +5,17 @@ RUN yum clean all && yum update -y RUN yum install -y openssh-clients sudo gnupg \ yum-utils epel-release redhat-rpm-config rpm-devel \ zlib zlib-devel rpm-build autoconf automake \ - glibc-devel libtool perl + glibc-devel libtool perl jq -#RUN yum install -y --nobest https://repo.ius.io/ius-release-el7.rpm +#RUN yum install -y --nobest https://repo.ius.io/ius-release-el7.rpm RUN yum update -y && yum install -y python3 RUN ln -fs /usr/bin/python3.6 /usr/bin/python # Add the scripts to build the RPM package -ADD builder.sh /usr/local/bin/builder +ADD rpm-builder.sh /usr/local/bin/builder +ADD wazuh-dashboard.spec /usr/local/src/wazuh-dashboard.spec RUN chmod +x /usr/local/bin/builder # Set the entrypoint diff --git a/dev-tools/build-packages/rpm/builder.sh b/dev-tools/build-packages/rpm/builder.sh deleted file mode 100755 index 63f5043a77b8..000000000000 --- a/dev-tools/build-packages/rpm/builder.sh +++ /dev/null @@ -1,57 +0,0 @@ -#!/bin/bash - -# Wazuh package builder -# Copyright (C) 2021, Wazuh Inc. -# -# This program is a free software; you can redistribute it -# and/or modify it under the terms of the GNU General Public -# License (version 2) as published by the FSF - Free Software -# Foundation. - -set -e - -# Script parameters to build the package -target="wazuh-dashboard" -architecture=$1 -revision=$2 -version=$3 -commit_sha=$4 -is_production=$5 -directory_base="/usr/share/wazuh-dashboard" - -# Build directories -build_dir=/build -rpm_build_dir=${build_dir}/rpmbuild -pkg_name=${target}-${version} -pkg_path="${rpm_build_dir}/RPMS/${architecture}" -file_name="${target}-${version}-${revision}" -rpm_file="${file_name}.${architecture}.rpm" -final_name="${target}_${version}-${revision}_${architecture}_${commit_sha}.rpm" - -mkdir -p ${rpm_build_dir}/{BUILD,BUILDROOT,RPMS,SOURCES,SPECS,SRPMS} - -# Prepare the sources directory to build the source tar.gz -mkdir ${build_dir}/${pkg_name} - -# Including spec file -cp /root/build-packages/rpm/${target}.spec ${rpm_build_dir}/SPECS/${pkg_name}.spec - -# Generating source tar.gz -cd ${build_dir} && tar czf "${rpm_build_dir}/SOURCES/${pkg_name}.tar.gz" "${pkg_name}" - -# Building RPM -/usr/bin/rpmbuild -v \ - --define "_topdir ${rpm_build_dir}" \ - --define "_version ${version}" \ - --define "_release ${revision}" \ - --define "_localstatedir ${directory_base}" \ - --target ${architecture} \ - -ba ${rpm_build_dir}/SPECS/${pkg_name}.spec - -cd ${pkg_path} && sha512sum ${rpm_file} >/tmp/${rpm_file}.sha512 - -find ${pkg_path}/ -maxdepth 3 -type f -name "${file_name}*" -exec mv {} /tmp/ \; -if [ "${is_production}" = "no" ]; then - mv /tmp/${rpm_file} /tmp/${final_name} - mv /tmp/${rpm_file}.sha512 /tmp/${final_name}.sha512 -fi diff --git a/dev-tools/build-packages/rpm/launcher.sh b/dev-tools/build-packages/rpm/launcher.sh deleted file mode 100755 index 9695f9e8c4df..000000000000 --- a/dev-tools/build-packages/rpm/launcher.sh +++ /dev/null @@ -1,207 +0,0 @@ -#!/bin/bash - -# Wazuh package generator -# Copyright (C) 2021, Wazuh Inc. -# -# This program is a free software; you can redistribute it -# and/or modify it under the terms of the GNU General Public -# License (version 2) as published by the FSF - Free Software -# Foundation. - -# Inputs -package="" -version="" -revision="0" -architecture="x86_64" -build_base="yes" -build_docker="yes" -is_production="no" - -# Constants -rpm_x86_builder="rpm_dashboard_builder_x86" -rpm_builder_dockerfile="${current_path}/docker" -commit_sha=$(git rev-parse --short HEAD) - -# Paths -current_path="$( cd $(dirname $0) ; pwd -P )" -config_path=$(realpath $current_path/../config) - -# Folders -out_dir="${current_path}/output" -tmp_dir="${current_path}/tmp" - -trap ctrl_c INT - -clean() { - exit_code=$1 - echo - echo "Cleaning temporary files..." - echo - # Clean the files - rm -r $tmp_dir - rm $current_path/docker/x86_64/*.sh - - if [ $exit_code != 0 ]; then - rm $out_dir/* - rmdir $out_dir - fi - - exit ${exit_code} -} - -ctrl_c() { - clean 1 -} - -build_rpm() { - container_name="$1" - dockerfile_path="$2" - - # Validate and download files to build the package - valid_url='(https?|ftp|file)://[-[:alnum:]\+&@#/%?=~_|!:,.;]*[-[:alnum:]\+&@#/%=~_|]' - - echo - echo "Downloading files..." - echo - - mkdir -p $tmp_dir - cd $tmp_dir - - if [[ $package =~ $valid_url ]]; then - if ! curl --output wazuh-dashboard.tar.gz --silent --fail "${package}"; then - echo "The given URL or Path to the Wazuh Dashboard package is not working: ${package}" - clean 1 - fi - else - echo "The given URL or Path to the Wazuh Dashboard package is not valid: ${package}" - clean 1 - fi - - echo - echo Building the package... - echo - - # Prepare the package - tar -zxf wazuh-dashboard.tar.gz - directory_name=$(ls -td */ | head -1) - rm wazuh-dashboard.tar.gz - mv $directory_name wazuh-dashboard-base - jq '.wazuh.revision="'${revision}'"' wazuh-dashboard-base/package.json > pkgtmp.json && mv pkgtmp.json wazuh-dashboard-base/package.json - mkdir -p wazuh-dashboard-base/etc/services - cp $config_path/* wazuh-dashboard-base/etc/services - echo ${version} >wazuh-dashboard-base/VERSION - tar -czf ./wazuh-dashboard.tar.gz wazuh-dashboard-base - - # Copy the necessary files - cp ${current_path}/builder.sh ${dockerfile_path} - - # Build the Docker image - if [[ ${build_docker} == "yes" ]]; then - docker build -t ${container_name} ${dockerfile_path} || return 1 - fi - - # Build the RPM package with a Docker container - - if [ ! -d "$out_dir" ]; then - mkdir -p $out_dir - fi - volumes="-v ${out_dir}/:/tmp:Z -v ${tmp_dir}/wazuh-dashboard.tar.gz:/opt/wazuh-dashboard.tar.gz" - docker run -t --rm ${volumes} \ - -v ${current_path}/../..:/root:Z \ - ${container_name} ${architecture} \ - ${revision} ${version} ${commit_sha} ${is_production}\ - || return 1 - - echo "Package $(ls -Art ${out_dir} | tail -n 1) added to ${out_dir}." - - echo - echo DONE! - echo - - return 0 -} - -build() { - build_name="${rpm_x86_builder}" - file_path="../${rpm_builder_dockerfile}/${architecture}" - build_rpm ${build_name} ${file_path} ${commit_sha} ${is_production}|| return 1 - return 0 -} - -help() { - echo - echo "Usage: $0 [OPTIONS]" - echo - echo " -v, --version Wazuh version" - echo " -p, --package Set the location of the .tar.gz file containing the Wazuh Dashboard package." - echo " -r, --revision [Optional] Package revision. By default: 1." - echo " -o, --output [Optional] Set the destination path of package. By default, an output folder will be created." - echo " --dont-build-docker [Optional] Locally built Docker image will be used instead of generating a new one." - echo " --production [Optional] The naming of the package will be ready for production." - echo " -h, --help Show this help." - echo - exit $1 -} - -main() { - while [ -n "${1}" ]; do - case "${1}" in - "-h" | "--help") - help 0 - ;; - "-p" | "--package") - if [ -n "${2}" ]; then - package="${2}" - shift 2 - else - help 1 - fi - ;; - "-v" | "--version") - if [ -n "${2}" ]; then - version="${2}" - shift 2 - else - help 1 - fi - ;; - "-r" | "--revision") - if [ -n "${2}" ]; then - revision="${2}" - shift 2 - else - help 1 - fi - ;; - "--dont-build-docker") - build_docker="no" - shift 1 - ;; - "--production") - is_production="yes" - shift 1 - ;; - "-o" | "--output") - if [ -n "${2}" ]; then - outdir="${2}" - shift 2 - else - help 1 - fi - ;; - *) - help 1 - ;; - esac - done - - if [ -z "$package" ] | [ -z "$version" ]; then - help 1 - fi - - build || clean 1 - - clean 0 -} - -main "$@" diff --git a/dev-tools/build-packages/rpm/rpm-builder.sh b/dev-tools/build-packages/rpm/rpm-builder.sh new file mode 100644 index 000000000000..180139b121ff --- /dev/null +++ b/dev-tools/build-packages/rpm/rpm-builder.sh @@ -0,0 +1,112 @@ +#!/bin/bash + +# Wazuh package builder +# Copyright (C) 2021, Wazuh Inc. +# +# This program is a free software; you can redistribute it +# and/or modify it under the terms of the GNU General Public +# License (version 2) as published by the FSF - Free Software +# Foundation. + +set -e + +# Script parameters to build the package +target="wazuh-dashboard" +version=$1 +revision=$2 +architecture=$3 +commit_sha=$4 +is_production=$5 +verbose=$6 + +# Paths +current_path="$( cd $(dirname $0) ; pwd -P )" + +# Folders +tmp_dir="/tmp" +out_dir="/output" +config_path=$tmp_dir/config + +if [ "$verbose" = "debug" ]; then + set -x +fi + +trap clean INT +trap clean EXIT + +log() { + if [ "$verbose" = "info" ] || [ "$verbose" = "debug" ]; then + echo "$@" + fi +} + +clean() { + exit_code=$? + # Clean the files + rm -rf ${tmp_dir}/* + trap '' EXIT + exit ${exit_code} +} + +mkdir -p ${tmp_dir}/wazuh-dashboard-base +cd ${tmp_dir}/wazuh-dashboard-base +log "Extracting base tar.gz..." +tar -zxf ${out_dir}/wazuh-dashboard-$version-$revision-linux-$architecture.tar.gz +log "Preparing the package..." +jq '.wazuh.revision="'${revision}'"' package.json > pkgtmp.json && mv pkgtmp.json package.json +mkdir -p etc/services +cp $config_path/* etc/services +echo ${version} > VERSION +cd .. +tar -czf wazuh-dashboard.tar.gz wazuh-dashboard-base + +log "Setting up parameters" + +if [ "${architecture}" = "x64" ]; then + architecture="x86_64" +else + architecture="aarch64" +fi + +build_dir=/build +rpm_build_dir=${build_dir}/rpmbuild +directory_base="/usr/share/wazuh-dashboard" + + +pkg_name=${target}-${version} +pkg_path="${rpm_build_dir}/RPMS/${architecture}" +file_name="${target}-${version}-${revision}" +rpm_file="${file_name}.${architecture}.rpm" + +if [ "$is_production" = "no" ]; then + final_name="${target}_${version}-${revision}_${architecture}_${commit_sha}.rpm" +else + final_name="${target}_${version}-${revision}_${architecture}.rpm" +fi + +mkdir -p ${rpm_build_dir}/{BUILD,BUILDROOT,RPMS,SOURCES,SPECS,SRPMS} + +mkdir ${build_dir}/${pkg_name} + +# Including spec file +cp /usr/local/src/${target}.spec ${rpm_build_dir}/SPECS/${pkg_name}.spec +cd ${build_dir} && tar czf "${rpm_build_dir}/SOURCES/${pkg_name}.tar.gz" "${pkg_name}" + +log "Building RPM..." +/usr/bin/rpmbuild -v \ + --define "_topdir ${rpm_build_dir}" \ + --define "_version ${version}" \ + --define "_release ${revision}" \ + --define "_localstatedir ${directory_base}" \ + --target ${architecture} \ + -ba ${rpm_build_dir}/SPECS/${pkg_name}.spec + +cd ${pkg_path} && sha512sum ${rpm_file} >/${out_dir}/${rpm_file}.sha512 + +find ${pkg_path}/ -maxdepth 3 -type f -name "${file_name}*" -exec mv {} /${out_dir}/ \; +if [ "${is_production}" = "no" ]; then + mv /${out_dir}/${rpm_file} /${out_dir}/${final_name} + mv /${out_dir}/${rpm_file}.sha512 /${out_dir}/${final_name}.sha512 +fi + + diff --git a/dev-tools/build-packages/rpm/wazuh-dashboard.spec b/dev-tools/build-packages/rpm/wazuh-dashboard.spec index 758e6ef7aa62..3addff105bde 100644 --- a/dev-tools/build-packages/rpm/wazuh-dashboard.spec +++ b/dev-tools/build-packages/rpm/wazuh-dashboard.spec @@ -44,7 +44,7 @@ Wazuh dashboard is a user interface and visualization tool for security-related %prep -cp /opt/%{DASHBOARD_FILE} ./ +cp /tmp/%{DASHBOARD_FILE} ./ groupadd %{GROUP} useradd -g %{GROUP} %{USER} diff --git a/dev-tools/build-packages/wazuh-dashboard.Dockerfile b/dev-tools/build-packages/wazuh-dashboard.Dockerfile deleted file mode 100644 index 48c0ef50d95e..000000000000 --- a/dev-tools/build-packages/wazuh-dashboard.Dockerfile +++ /dev/null @@ -1,30 +0,0 @@ -# Usage: docker build --build-arg NODE_VERSION=18.19.0 --build-arg WAZUH_DASHBOARDS_BRANCH=4.10.0 --build-arg WAZUH_DASHBOARDS_REPORTING_BRANCH=4.10.0 --build-arg WAZUH_DASHBOARDS_PLUGINS=4.10.0 --build-arg WAZUH_SECURITY_DASHBOARDS_PLUGIN_BRANCH=4.10.0 --build-arg OPENSEARCH_DASHBOARDS_VERSION=2.13.0 -t wzd:4.10.0 -f wazuh-dashboard.Dockerfile . - -ARG NODE_VERSION -FROM node:${NODE_VERSION} AS base -ARG OPENSEARCH_DASHBOARDS_VERSION -ARG WAZUH_DASHBOARDS_BRANCH -ARG WAZUH_DASHBOARDS_PLUGINS -ARG WAZUH_SECURITY_DASHBOARDS_PLUGIN_BRANCH -ARG WAZUH_DASHBOARDS_REPORTING_BRANCH -ENV OPENSEARCH_DASHBOARDS_VERSION=${OPENSEARCH_DASHBOARDS_VERSION} -USER root -RUN apt-get update && apt-get install -y git zip unzip curl brotli jq -USER node - -COPY ./config-dockerfile/entrypoint.sh /entrypoint.sh -ENTRYPOINT ["/entrypoint.sh"] - -RUN bash /entrypoint.sh - -WORKDIR /home/node/wzd/dev-tools/build-packages/base -RUN ./generate_base.sh -v 4.10.0 -r 1 -a file:///home/node/packages/wazuh-package.zip -s file:///home/node/packages/security-package.zip -b file:///home/node/packages/dashboard-package.zip -rp file:///home/node/packages/reporting-package.zip -WORKDIR /home/node/wzd/dev-tools/build-packages/base/output -RUN cp ./* /home/node/packages/ - - -FROM node:${NODE_VERSION} -USER node -COPY --chown=node:node --from=base /home/node/wzd /home/node/wzd -COPY --chown=node:node --from=base /home/node/packages /home/node/packages -WORKDIR /home/node/wzd diff --git a/dev-tools/test-packages/test-packages.sh b/dev-tools/test-packages/test-packages.sh index ca0eea5831f3..5f21bc955e00 100644 --- a/dev-tools/test-packages/test-packages.sh +++ b/dev-tools/test-packages/test-packages.sh @@ -12,6 +12,7 @@ FILE_OWNER="wazuh-dashboard" # Remove container and image clean() { docker stop $CONTAINER_NAME + docker rm $CONTAINER_NAME docker rmi $CONTAINER_NAME }