Skip to content

Commit

Permalink
Add revision number as file
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexRuiz7 committed Mar 6, 2024
1 parent c6c7de5 commit 85639b9
Show file tree
Hide file tree
Showing 13 changed files with 53 additions and 37 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/r_version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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=$(<VERSION)" >> $GITHUB_OUTPUT
echo "revision=$(<REVISION)" >> $GITHUB_OUTPUT
1 change: 1 addition & 0 deletions REVISION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.9.0-1
4.9.0
1 change: 1 addition & 0 deletions distribution/packages/src/deb/debmake_install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions distribution/packages/src/rpm/wazuh-indexer.rpm.spec
Original file line number Diff line number Diff line change
Expand Up @@ -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/.*"
Expand Down Expand Up @@ -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/*
Expand Down
4 changes: 3 additions & 1 deletion docker/ci/ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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=$(<VERSION)
REVISION=$(<REVISION)
export REPO_PATH
export VERSION
export REVISION

case $1 in
up)
Expand Down
8 changes: 4 additions & 4 deletions docker/ci/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ version: "3.9"
services:
# Essentially wi-dev, but doesn't expose port 9200
wi-build:
image: wi-build:${VERSION}
container_name: wi-build_${VERSION}
image: wi-build:${VERSION}-${REVISION}
container_name: wi-build_${VERSION}-${REVISION}
build:
context: ./../..
dockerfile: ${REPO_PATH}/docker/dev/images/Dockerfile
Expand All @@ -15,8 +15,8 @@ services:
working_dir: /home/wazuh-indexer

wi-assemble:
image: wi-assemble:${VERSION}
container_name: wi-assemble_${VERSION}
image: wi-assemble:${VERSION}-${REVISION}
container_name: wi-assemble_${VERSION}-${REVISION}
build:
context: ./../..
dockerfile: ${REPO_PATH}/docker/ci/images/Dockerfile
Expand Down
4 changes: 3 additions & 1 deletion docker/dev/dev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@ function main() {
compose_file="docker/${current}/dev.yml"
compose_cmd="docker compose -f $compose_file"
REPO_PATH=$(pwd)
VERSION=$(cat VERSION)
VERSION=$(<VERSION)
REVISION=$(<REVISION)
export REPO_PATH
export VERSION
export REVISION

case $1 in
up)
Expand Down
4 changes: 2 additions & 2 deletions docker/dev/dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ version: "3.9"

services:
wi-dev:
image: wi-dev:${VERSION}
container_name: wi-dev_${VERSION}
image: wi-dev:${VERSION}-${REVISION}
container_name: wi-dev_${VERSION}-${REVISION}
build:
context: ./../..
dockerfile: ${REPO_PATH}/docker/dev/images/Dockerfile
Expand Down
6 changes: 3 additions & 3 deletions scripts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ act -j build -W .github/workflows/build.yml --artifact-server-path ./artifacts
Using the [Docker environment](../docker):

```console
docker exec -it wi-build_$(<VERSION) bash scripts/build.sh -v 2.11.1 -s false -p linux -a {x64|arm64} -d {rpm|deb|tar}
docker exec -it wi-build_$(<VERSION)-$(<REVISION) bash scripts/build.sh -v 2.11.1 -s false -p linux -a {x64|arm64} -d {rpm|deb|tar}
```

The generated package is sent to `artifacts/`
Expand Down Expand Up @@ -128,7 +128,7 @@ Pre-requisites:
- Using the [Docker environment](../docker):

```console
docker exec -it wi-assemble_$(<VERSION) bash scripts/assemble.sh -v 2.11.1 -p linux -a x64 -d deb
docker exec -it wi-assemble_$(<VERSION)-$(<REVISION) bash scripts/assemble.sh -v 2.11.1 -p linux -a x64 -d deb
```

### RPM
Expand Down Expand Up @@ -198,5 +198,5 @@ Pre-requisites:
- Using the [Docker environment](../docker):

```console
docker exec -it wi-assemble_$(<VERSION) bash scripts/assemble.sh -v 2.11.1 -p linux -a x64 -d rpm
docker exec -it wi-assemble_$(<VERSION)-$(<REVISION) bash scripts/assemble.sh -v 2.11.1 -p linux -a x64 -d rpm
```
31 changes: 16 additions & 15 deletions scripts/assemble.sh
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ function clean() {
rm -r "${OUTPUT}/tmp"
echo "After execution, shell path is $(pwd)"
# Store package's name to file. Used by GH Action.
echo "${ARTIFACT_PACKAGE_NAME}" >"${OUTPUT}/artifact_name.txt"
echo "${ARTIFACT_NAME}" >"${OUTPUT}/artifact_name.txt"
}

# ====
Expand All @@ -250,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
Expand All @@ -269,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
}
Expand All @@ -290,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)
Expand All @@ -317,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
}
Expand All @@ -341,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
Expand Down Expand Up @@ -373,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
}
Expand All @@ -384,24 +384,25 @@ function assemble_deb() {
function main() {
parse_args "${@}"

ARTIFACT_BUILD_NAME=$(ls "${OUTPUT}/dist/" | grep "wazuh-indexer-min_.*$SUFFIX.*\.$EXT")
# ARTIFACT_PACKAGE_NAME=${ARTIFACT_BUILD_NAME/min_/}
BUILD_ARTIFACT_NAME=$(ls "${OUTPUT}/dist/" | grep "wazuh-indexer-min_.*$SUFFIX.*\.$EXT")
# ARTIFACT_NAME=${BUILD_ARTIFACT_NAME/min_/}

GIT_COMMIT=$(git rev-parse --short HEAD)
WI_VERSION=$(<VERSION)
ARTIFACT_PACKAGE_NAME=wazuh-indexer-"$WI_VERSION"_"$SUFFIX"_"$GIT_COMMIT"."$EXT"
REVISION=$(<REVISION)
ARTIFACT_NAME=wazuh-indexer-"$WI_VERSION"-"$REVISION"_"$SUFFIX"_"$GIT_COMMIT"."$EXT"

# Print the package name and exit
if [ "$DRY" ]; then
echo "${ARTIFACT_PACKAGE_NAME}"
echo "${ARTIFACT_NAME}"
exit 0
fi

echo "Assembling wazuh-indexer for $PLATFORM-$DISTRIBUTION-$ARCHITECTURE"
# Create temporal directory and copy the min package there for extraction
TMP_DIR="${OUTPUT}/tmp/${TARGET}"
mkdir -p "$TMP_DIR"
cp "${OUTPUT}/dist/$ARTIFACT_BUILD_NAME" "${TMP_DIR}"
cp "${OUTPUT}/dist/$BUILD_ARTIFACT_NAME" "${TMP_DIR}"

case $PACKAGE in
tar)
Expand Down
11 changes: 6 additions & 5 deletions scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,12 @@ esac

GIT_COMMIT=$(git rev-parse --short HEAD)
WI_VERSION=$(<VERSION)
ARTIFACT_PACKAGE_NAME=wazuh-indexer-min_"$WI_VERSION"_"$SUFFIX"_"$GIT_COMMIT"."$EXT"
REVISION=$(<REVISION)
ARTIFACT_NAME=wazuh-indexer-min_"$WI_VERSION"-"$REVISION"_"$SUFFIX"_"$GIT_COMMIT"."$EXT"

# Print the package name and exit
if [ "$DRY" ]; then
echo "${ARTIFACT_PACKAGE_NAME}"
echo "${ARTIFACT_NAME}"
exit 0
fi

Expand Down Expand Up @@ -212,10 +213,10 @@ fi
# Copy artifact to dist folder in bundle build output
echo "Copying artifact to ${OUTPUT}/dist"

ARTIFACT_BUILD_NAME=$(ls "distribution/$TYPE/$TARGET/build/distributions/" | grep "wazuh-indexer-min.*$SUFFIX.$EXT")
BUILD_ARTIFACT_NAME=$(ls "distribution/$TYPE/$TARGET/build/distributions/" | grep "wazuh-indexer-min.*$SUFFIX.$EXT")

# Used by the GH workflow to upload the artifact
echo "$ARTIFACT_PACKAGE_NAME" >"$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"
9 changes: 5 additions & 4 deletions scripts/test-ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

GIT_COMMIT=$(git rev-parse --short HEAD)
WI_VERSION=$(<VERSION)
REVISION=$(<REVISION)

rpm_args="-v 2.11.1 -p linux -a x64 -d rpm -D"
deb_args="-v 2.11.1 -p linux -a x64 -d deb -D"
Expand All @@ -15,7 +16,7 @@ build() {
local success=0

rpm=$(bash "scripts/build.sh" $rpm_args)
local artifact_name=wazuh-indexer-min_"$WI_VERSION"_x86_64_"$GIT_COMMIT".rpm
local artifact_name=wazuh-indexer-min_"$WI_VERSION"-"$REVISION"_x86_64_"$GIT_COMMIT".rpm
if [ "$rpm" = "$artifact_name" ]; then
echo -e "\t[PASSED] rpm build output has the value '$rpm'"
else
Expand All @@ -24,7 +25,7 @@ build() {
fi

deb=$(bash "scripts/build.sh" $deb_args)
local artifact_name=wazuh-indexer-min_"$WI_VERSION"_amd64_"$GIT_COMMIT".deb
local artifact_name=wazuh-indexer-min_"$WI_VERSION"-"$REVISION"_amd64_"$GIT_COMMIT".deb
if [ "$deb" = "$artifact_name" ]; then
echo -e "\t[PASSED] deb build output has the value '$deb'"
else
Expand All @@ -42,7 +43,7 @@ assemble() {
local success=0

rpm=$(bash "scripts/assemble.sh" $rpm_args)
local artifact_name=wazuh-indexer-"$WI_VERSION"_x86_64_"$GIT_COMMIT".rpm
local artifact_name=wazuh-indexer-"$WI_VERSION"-"$REVISION"_x86_64_"$GIT_COMMIT".rpm
if [ "$rpm" = "$artifact_name" ]; then
echo -e "\t[PASSED] rpm assemble output has the value '$rpm'"
else
Expand All @@ -51,7 +52,7 @@ assemble() {
fi

deb=$(bash "scripts/assemble.sh" $deb_args)
local artifact_name=wazuh-indexer-"$WI_VERSION"_amd64_"$GIT_COMMIT".deb
local artifact_name=wazuh-indexer-"$WI_VERSION"-"$REVISION"_amd64_"$GIT_COMMIT".deb
if [ "$deb" = "$artifact_name" ]; then
echo -e "\t[PASSED] deb assemble output has the value '$deb'"
else
Expand Down

0 comments on commit 85639b9

Please sign in to comment.