diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 2c05d48c4a507..ce16d90e8ecf2 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -58,9 +58,25 @@ jobs: # skip arm64 until we have arm runners - architecture: arm64 - distribution: tar - uses: ./.github/workflows/r_assemble.yml with: architecture: ${{ matrix.architecture }} distribution: ${{ matrix.distribution }} min: wazuh-indexer-min_${{ needs.version.outputs.version }}-${{ github.event_name == 'push' && '1' || inputs.revision }}-${{ matrix.architecture }}_${{ needs.commit_sha.outputs.commit_sha }}.${{ matrix.distribution }} + + test: + needs: [version, commit_sha, assemble] + strategy: + matrix: + distribution: [tar, rpm, deb] + architecture: [x64, arm64] + exclude: + # Only DEB packages can be tested on GitHub runners (ubuntu) + - architecture: arm64 + - distribution: tar + - distribution: rpm + uses: ./.github/workflows/r_test.yml + with: + architecture: ${{ matrix.architecture }} + distribution: ${{ matrix.distribution }} + package: wazuh-indexer-${{ needs.version.outputs.version }}-${{ github.event_name == 'push' && '1' || inputs.revision }}-${{ matrix.architecture }}_${{ needs.commit_sha.outputs.commit_sha }}.${{ matrix.distribution }} diff --git a/.github/workflows/r_build.yml b/.github/workflows/r_build.yml index 299eb8155f735..1a5f4c6de83db 100644 --- a/.github/workflows/r_build.yml +++ b/.github/workflows/r_build.yml @@ -15,7 +15,7 @@ on: default: "x64" required: true type: string - revision: + revision: # TODO remove if it works description: "Any string or number used to extend the package's identifier." type: string required: true @@ -40,11 +40,11 @@ jobs: java-version: 11 - name: Setup Gradle - uses: gradle/gradle-build-action@v2.9.0 + uses: gradle/actions/setup-gradle@v3 - name: Run `build.sh` run: | - bash scripts/build.sh -v ${{ vars.OPENSEARCH_VERSION }} -s false -p linux -a ${{ inputs.architecture }} -d ${{ inputs.distribution }} -r ${{ inputs.revision }} + bash scripts/build.sh -v ${{ vars.OPENSEARCH_VERSION }} -s false -p linux -a ${{ inputs.architecture }} -d ${{ inputs.distribution }} # The package's name is stored in artifacts/artifact_min_name.txt. - name: Set package name diff --git a/.github/workflows/r_test.yml b/.github/workflows/r_test.yml new file mode 100644 index 0000000000000..198af8ab6704d --- /dev/null +++ b/.github/workflows/r_test.yml @@ -0,0 +1,50 @@ +name: Test (reusable) + +# This workflow runs when any of the following occur: +# - Run from another workflow +on: + workflow_call: + inputs: + distribution: + description: "One of [ 'tar', 'rpm', 'deb' ]" + default: "rpm" + required: true + type: string + architecture: + description: "One of [ 'x64', 'arm64' ]" + default: "x64" + required: true + type: string + package: + description: "The name of the package to download." + required: true + type: string + +jobs: + r_test: + runs-on: ubuntu-latest + # Permissions to upload the package + permissions: + packages: read + contents: read + steps: + - uses: actions/checkout@v4 + + - name: Run `assemble.sh` to get the package name + id: get_package_name + run: | + echo "name=$(bash scripts/assemble.sh -v ${{ vars.OPENSEARCH_VERSION }} -p linux -a ${{ inputs.architecture }} -d ${{ inputs.distribution }} -D)" >> $GITHUB_OUTPUT + + - name: Download artifact + uses: actions/download-artifact@v4 + with: + name: ${{ steps.get_package_name.outputs.name }} + path: artifacts/dist + + - name: Run `test.sh` + run: | + dpkg -i "artifacts/dist/${{ inputs.package }}"; + systemctl daemon-reload; + systemctl enable wazuh-indexer.service; + systemctl start wazuh-indexer; + systemctl status wazuh-indexer diff --git a/.github/workflows/r_version.yml b/.github/workflows/r_version.yml index d3c01135a6c35..723a84611ed61 100644 --- a/.github/workflows/r_version.yml +++ b/.github/workflows/r_version.yml @@ -8,15 +8,20 @@ on: version: description: "Returns the version of Wazuh" value: ${{ jobs.r_version.outputs.version }} + revision: + description: "Returns the revision of Wazuh" + value: ${{ jobs.r_version.outputs.revision }} jobs: r_version: runs-on: ubuntu-latest outputs: version: ${{ steps.get_version.outputs.version }} + revision: ${{ steps.get_version.outputs.revision }} steps: - uses: actions/checkout@v4 - name: Read 'VERSION' id: get_version run: | - echo "version=$(cat VERSION)" >> $GITHUB_OUTPUT + echo "version=$(> $GITHUB_OUTPUT + echo "revision=$(> $GITHUB_OUTPUT diff --git a/REVISION b/REVISION new file mode 100644 index 0000000000000..56a6051ca2b02 --- /dev/null +++ b/REVISION @@ -0,0 +1 @@ +1 \ No newline at end of file diff --git a/distribution/archives/build.gradle b/distribution/archives/build.gradle index a4c95e64b7b2c..bb09e6648426c 100644 --- a/distribution/archives/build.gradle +++ b/distribution/archives/build.gradle @@ -34,6 +34,7 @@ apply plugin: 'opensearch.internal-distribution-archive-setup' CopySpec archiveFiles(CopySpec modulesFiles, String distributionType, String platform, String architecture, JavaPackageType java) { version = rootProject.file('VERSION').getText() + revision = rootProject.file('REVISION').getText() return copySpec { into("wazuh-indexer-${version}") { into('lib') { @@ -75,6 +76,9 @@ CopySpec archiveFiles(CopySpec modulesFiles, String distributionType, String pla into('') { with versionFile() } + into('') { + with revisionFile() + } from(rootProject.projectDir) { include 'README.md' } diff --git a/distribution/build.gradle b/distribution/build.gradle index 8a2bd5b2a56a3..3c33d123e68c1 100644 --- a/distribution/build.gradle +++ b/distribution/build.gradle @@ -364,6 +364,13 @@ configure(subprojects.findAll { ['archives', 'packages'].contains(it.name) }) { } } + revisionFile = { + copySpec { + from(rootProject.file('REVISION')) + fileMode 0644 + } + } + modulesFiles = { platform -> copySpec { eachFile { @@ -563,6 +570,7 @@ subprojects { Map expansions = [ 'project.name': project.name, 'project.version': version, + 'project.revision': revision, 'path.conf': [ 'deb': '/etc/wazuh-indexer', diff --git a/distribution/packages/build.gradle b/distribution/packages/build.gradle index b99eebea6c660..49dd3c2058eb3 100644 --- a/distribution/packages/build.gradle +++ b/distribution/packages/build.gradle @@ -107,6 +107,7 @@ addProcessFilesTask('rpm', false) // is the same Closure commonPackageConfig(String type, boolean jdk, String architecture) { project.version = rootProject.file('VERSION').getText() + project.revision = rootProject.file('REVISION').getText() return { onlyIf { OS.current().equals(OS.WINDOWS) == false @@ -137,9 +138,9 @@ Closure commonPackageConfig(String type, boolean jdk, String architecture) { // SystemPackagingTask overrides default archive task convention mappings, but doesn't provide a setter so we have to override the convention mapping itself // Deb convention uses a '_' for final separator before architecture, rpm uses a '.' if (type == 'deb') { - archiveFileName.value(project.provider({ "${destinationDirectory.get()}/${packageName}-min_${project.version}${jdkString}_${archString}.${type}" })) + archiveFileName.value(project.provider({ "${destinationDirectory.get()}/${packageName}-min_${project.version}-${project.revision}${jdkString}_${archString}.${type}" })) } else { - archiveFileName.value(project.provider({ "${destinationDirectory.get()}/${packageName}-min-${project.version}${jdkString}.${archString}.${type}" })) + archiveFileName.value(project.provider({ "${destinationDirectory.get()}/${packageName}-min-${project.version}-${project.revision}${jdkString}.${archString}.${type}" })) } String packagingFiles = "build/packaging/${jdk ? '' : 'no-jdk-'}${type}" diff --git a/distribution/packages/src/deb/debmake_install.sh b/distribution/packages/src/deb/debmake_install.sh index 74064f87620e6..602eebc256810 100644 --- a/distribution/packages/src/deb/debmake_install.sh +++ b/distribution/packages/src/deb/debmake_install.sh @@ -75,6 +75,7 @@ fi # Files that need other permissions chmod -c 440 "${buildroot}${product_dir}/VERSION" +chmod -c 440 "${buildroot}${product_dir}/REVISION" if [ -d "${buildroot}${product_dir}/plugins/opensearch-security" ]; then chmod -c 0740 "${buildroot}${product_dir}"/plugins/opensearch-security/tools/*.sh fi diff --git a/distribution/packages/src/rpm/wazuh-indexer.rpm.spec b/distribution/packages/src/rpm/wazuh-indexer.rpm.spec index b81d6a91ecb97..8de47603bd3be 100644 --- a/distribution/packages/src/rpm/wazuh-indexer.rpm.spec +++ b/distribution/packages/src/rpm/wazuh-indexer.rpm.spec @@ -117,6 +117,7 @@ set -- "$@" "%{config_dir}/jvm.options" set -- "$@" "%{config_dir}/opensearch.yml" set -- "$@" "%{config_dir}/wazuh-template.json" set -- "$@" "%{product_dir}/VERSION" +set -- "$@" "%{product_dir}/REVISION" set -- "$@" "%{product_dir}/plugins/opensearch-security/tools/.*\.sh" set -- "$@" "%{product_dir}/bin/.*" set -- "$@" "%{product_dir}/jdk/bin/.*" @@ -254,6 +255,7 @@ exit 0 # Files that need other permissions %attr(440, %{name}, %{name}) %{product_dir}/VERSION +%attr(440, %{name}, %{name}) %{product_dir}/REVISION %attr(740, %{name}, %{name}) %{product_dir}/plugins/opensearch-security/tools/*.sh %attr(750, %{name}, %{name}) %{product_dir}/bin/* %attr(750, %{name}, %{name}) %{product_dir}/jdk/bin/* diff --git a/docker/ci/ci.sh b/docker/ci/ci.sh index 13e84c0881b3f..5a2c5e9c6b51e 100755 --- a/docker/ci/ci.sh +++ b/docker/ci/ci.sh @@ -36,9 +36,11 @@ function main() { compose_file="docker/${current}/ci.yml" compose_cmd="docker compose -f $compose_file" REPO_PATH=$(pwd) - VERSION=$(cat VERSION) + VERSION=$("${OUTPUT}/artifact_name.txt" + echo "${ARTIFACT_NAME}" >"${OUTPUT}/artifact_name.txt" } # ==== @@ -243,8 +250,8 @@ function assemble_tar() { PATH_PLUGINS="./plugins" # Extract - echo "Extract ${ARTIFACT_BUILD_NAME} archive" - tar -zvxf "${ARTIFACT_BUILD_NAME}" + echo "Extract ${BUILD_ARTIFACT_NAME} archive" + tar -zvxf "${BUILD_ARTIFACT_NAME}" cd "$(ls -d wazuh-indexer-*/)" local version @@ -262,7 +269,7 @@ function assemble_tar() { cd .. tar -cvf "${archive_name}-${SUFFIX}.${EXT}" "${archive_name}" cd ../../.. - cp "${TMP_DIR}/${archive_name}-${SUFFIX}.${EXT}" "${OUTPUT}/dist/$ARTIFACT_PACKAGE_NAME" + cp "${TMP_DIR}/${archive_name}-${SUFFIX}.${EXT}" "${OUTPUT}/dist/$ARTIFACT_NAME" clean } @@ -283,8 +290,8 @@ function assemble_rpm() { PATH_PLUGINS="${src_path}/plugins" # Extract min-package. Creates usr/, etc/ and var/ in the current directory - echo "Extract ${ARTIFACT_BUILD_NAME} archive" - rpm2cpio "${ARTIFACT_BUILD_NAME}" | cpio -imdv + echo "Extract ${BUILD_ARTIFACT_NAME} archive" + rpm2cpio "${BUILD_ARTIFACT_NAME}" | cpio -imdv local version version=$(cat ./usr/share/wazuh-indexer/VERSION) @@ -310,7 +317,7 @@ function assemble_rpm() { # Move to the root folder, copy the package and clean. cd ../../.. package_name="wazuh-indexer-${version}-1.${SUFFIX}.${EXT}" - cp "${TMP_DIR}/RPMS/${SUFFIX}/${package_name}" "${OUTPUT}/dist/$ARTIFACT_PACKAGE_NAME" + cp "${TMP_DIR}/RPMS/${SUFFIX}/${package_name}" "${OUTPUT}/dist/$ARTIFACT_NAME" clean } @@ -334,8 +341,8 @@ function assemble_deb() { PATH_PLUGINS="${src_path}/plugins" # Extract min-package. Creates usr/, etc/ and var/ in the current directory - echo "Extract ${ARTIFACT_BUILD_NAME} archive" - ar xf "${ARTIFACT_BUILD_NAME}" data.tar.gz + echo "Extract ${BUILD_ARTIFACT_NAME} archive" + ar xf "${BUILD_ARTIFACT_NAME}" data.tar.gz tar zvxf data.tar.gz local version @@ -366,7 +373,7 @@ function assemble_deb() { cd ../../.. package_name="wazuh-indexer_${version}_${SUFFIX}.${EXT}" # debmake creates the package one level above - cp "${TMP_DIR}/../${package_name}" "${OUTPUT}/dist/$ARTIFACT_PACKAGE_NAME" + cp "${TMP_DIR}/../${package_name}" "${OUTPUT}/dist/$ARTIFACT_NAME" clean } @@ -377,16 +384,25 @@ function assemble_deb() { function main() { parse_args "${@}" - echo "Assembling wazuh-indexer for $PLATFORM-$DISTRIBUTION-$ARCHITECTURE" + BUILD_ARTIFACT_NAME=$(ls "${OUTPUT}/dist/" | grep "wazuh-indexer-min_.*$SUFFIX.*\.$EXT") + # ARTIFACT_NAME=${BUILD_ARTIFACT_NAME/min_/} - ARTIFACT_BUILD_NAME=$(ls "${OUTPUT}/dist/" | grep "wazuh-indexer-min_.*$SUFFIX.*\.$EXT") + GIT_COMMIT=$(git rev-parse --short HEAD) + WI_VERSION=$("$OUTPUT/artifact_min_name.txt" +echo "$ARTIFACT_NAME" >"$OUTPUT/artifact_min_name.txt" mkdir -p "${OUTPUT}/dist" -cp "distribution/$TYPE/$TARGET/build/distributions/$ARTIFACT_BUILD_NAME" "${OUTPUT}/dist/$ARTIFACT_PACKAGE_NAME" +cp "distribution/$TYPE/$TARGET/build/distributions/$BUILD_ARTIFACT_NAME" "${OUTPUT}/dist/$ARTIFACT_NAME" diff --git a/scripts/test-ci.sh b/scripts/test-ci.sh new file mode 100644 index 0000000000000..86222ac355185 --- /dev/null +++ b/scripts/test-ci.sh @@ -0,0 +1,73 @@ +#!/bin/bash + + +# CI tests + +GIT_COMMIT=$(git rev-parse --short HEAD) +WI_VERSION=$(