Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version file standarization #697

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion VERSION

This file was deleted.

4 changes: 4 additions & 0 deletions VERSION.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"version": "5.0.0.",
"stage": "alpha0"
}
2 changes: 1 addition & 1 deletion build-scripts/REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ Arguments:
-p PLATFORM [Optional] Platform, default is 'uname -s'.
-a ARCHITECTURE [Optional] Build architecture, default is 'uname -m'.
-d DISTRIBUTION [Optional] Distribution, default is 'tar'.
-b BRANCH [Optional] Branch from wazuh/wazuh to download the index template from, default is '<VERSION'
-b BRANCH [Optional] Branch from wazuh/wazuh to download the index template from, default is $(bash build-scripts/product_version.sh)
-n NAME [optional] Package name, default is set automatically.
-o OUTPUT [Optional] Output path, default is 'artifacts'.
-h help
Expand Down
36 changes: 14 additions & 22 deletions build-scripts/assemble.sh
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,9 @@ function install_plugins() {
echo "Installing OpenSearch plugins"
local maven_repo_local="$HOME/.m2"
for plugin in "${plugins[@]}"; do
local plugin_from_maven="org.opensearch.plugin:${plugin}:${VERSION}.0"
local plugin_from_maven="org.opensearch.plugin:${plugin}:${UPSTREAM_VERSION}.0"
mvn -Dmaven.repo.local="${maven_repo_local}" org.apache.maven.plugins:maven-dependency-plugin:2.1:get -DrepoUrl=https://repo1.maven.org/maven2 -Dartifact="${plugin_from_maven}:zip"
OPENSEARCH_PATH_CONF=$PATH_CONF "${PATH_BIN}/opensearch-plugin" install --batch --verbose "file:${maven_repo_local}/org/opensearch/plugin/${plugin}/${VERSION}.0/${plugin}-${VERSION}.0.zip"
OPENSEARCH_PATH_CONF=$PATH_CONF "${PATH_BIN}/opensearch-plugin" install --batch --verbose "file:${maven_repo_local}/org/opensearch/plugin/${plugin}/${UPSTREAM_VERSION}.0/${plugin}-${UPSTREAM_VERSION}.0.zip"
done

echo "Installing Wazuh plugins"
Expand Down Expand Up @@ -280,24 +280,21 @@ function assemble_tar() {
local decompressed_tar_dir
decompressed_tar_dir=$(ls -d wazuh-indexer-*/)

local version
version=$(cat "${decompressed_tar_dir}"/VERSION)

PATH_CONF="${decompressed_tar_dir}/config"
PATH_BIN="${decompressed_tar_dir}/bin"
PATH_PLUGINS="${decompressed_tar_dir}/plugins"

# Install plugins
install_plugins "${version}"
install_plugins "${PRODUCT_VERSION}"
fix_log_rotation "${PATH_CONF}"
add_demo_certs_installer
# Swap configuration files
add_configuration_files
remove_unneeded_files
add_wazuh_tools "${version}"
add_wazuh_tools "${PRODUCT_VERSION}"

# Pack
archive_name="wazuh-indexer-${version}"
archive_name="wazuh-indexer-${PRODUCT_VERSION}"
tar -cvf "${archive_name}-${SUFFIX}.${EXT}" "${archive_name}"
cd ../../..
cp "${TMP_DIR}/${archive_name}-${SUFFIX}.${EXT}" "${OUTPUT}/dist/$ARTIFACT_PACKAGE_NAME"
Expand All @@ -324,33 +321,30 @@ function assemble_rpm() {
echo "Extract ${ARTIFACT_BUILD_NAME} archive"
rpm2cpio "${ARTIFACT_BUILD_NAME}" | cpio -imdv

local version
version=$(cat ./usr/share/wazuh-indexer/VERSION)

# Install plugins
install_plugins "${version}"
install_plugins "${PRODUCT_VERSION}"
fix_log_rotation ${PATH_CONF}
enable_performance_analyzer_rca ${src_path}
add_demo_certs_installer
# Swap configuration files
add_configuration_files
remove_unneeded_files
add_wazuh_tools "${version}"
add_wazuh_tools "${PRODUCT_VERSION}"

# Generate final package
local topdir
local spec_file="wazuh-indexer.rpm.spec"
topdir=$(pwd)
rpmbuild --bb \
--define "_topdir ${topdir}" \
--define "_version ${version}" \
--define "_version ${PRODUCT_VERSION}" \
--define "_architecture ${SUFFIX}" \
--define "_release ${REVISION}" \
${spec_file}

# Move to the root folder, copy the package and clean.
cd ../../..
package_name="wazuh-indexer-${version}-${REVISION}.${SUFFIX}.${EXT}"
package_name="wazuh-indexer-${PRODUCT_VERSION}-${REVISION}.${SUFFIX}.${EXT}"
cp "${TMP_DIR}/RPMS/${SUFFIX}/${package_name}" "${OUTPUT}/dist/$ARTIFACT_PACKAGE_NAME"

clean
Expand Down Expand Up @@ -379,18 +373,15 @@ function assemble_deb() {
ar xf "${ARTIFACT_BUILD_NAME}" data.tar.gz
tar zvxf data.tar.gz

local version
version=$(cat ./usr/share/wazuh-indexer/VERSION)

# Install plugins
install_plugins "${version}"
install_plugins "${PRODUCT_VERSION}"
fix_log_rotation ${PATH_CONF}
enable_performance_analyzer_rca ${src_path}
add_demo_certs_installer
# Swap configuration files
add_configuration_files
remove_unneeded_files
add_wazuh_tools "${version}"
add_wazuh_tools "${PRODUCT_VERSION}"

# Configure debmake to only generate binaries
echo 'DEBUILD_DPKG_BUILDPACKAGE_OPTS="-us -uc -ui -b"' >~/.devscripts
Expand All @@ -405,7 +396,7 @@ function assemble_deb() {
--package wazuh-indexer \
--native \
--revision "${REVISION}" \
--upstreamversion "${version}-${REVISION}"
--upstreamversion "${PRODUCT_VERSION}-${REVISION}"

# Move to the root folder, copy the package and clean.
cd ../../..
Expand All @@ -424,7 +415,8 @@ function main() {

echo "Assembling wazuh-indexer for $PLATFORM-$DISTRIBUTION-$ARCHITECTURE"

VERSION=$(bash build-scripts/upstream-version.sh)
UPSTREAM_VERSION=$(bash build-scripts/upstream-version.sh)
PRODUCT_VERSION=$(bash build-scripts/product_version.sh)
ARTIFACT_BUILD_NAME=$(ls "${OUTPUT}/dist/" | grep "wazuh-indexer-min.*$SUFFIX.*\.$EXT")
ARTIFACT_PACKAGE_NAME=${ARTIFACT_BUILD_NAME/-min/}

Expand Down
2 changes: 1 addition & 1 deletion build-scripts/baptizer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -165,5 +165,5 @@ function main() {
}

GIT_COMMIT=$(git rev-parse --short HEAD)
VERSION=$(<VERSION)
VERSION=$(bash build-scripts/product_version.sh)
main "${@}"
2 changes: 1 addition & 1 deletion build-scripts/build-and-push-docker-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ function parse_args() {
fi

REVISION="${REVISION:-0}"
VERSION=$(<VERSION)
VERSION=$(bash build-scripts/product_name.sh)
}

# ====
Expand Down
4 changes: 2 additions & 2 deletions build-scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function usage() {
echo -e "-p PLATFORM\t[Optional] Platform, default is 'uname -s'."
echo -e "-a ARCHITECTURE\t[Optional] Build architecture, default is 'uname -m'."
echo -e "-d DISTRIBUTION\t[Optional] Distribution, default is 'tar'."
echo -e "-b BRANCH\t[Optional] Branch from wazuh/wazuh to download the index template from, default is '<VERSION'"
echo -e "-b BRANCH\t[Optional] Branch from wazuh/wazuh to download the index template from, default is $(bash build-scripts/product_version.sh)"
echo -e "-n NAME\t[optional] Package name, default is set automatically."
echo -e "-o OUTPUT\t[Optional] Output path, default is 'artifacts'."
echo -e "-h help"
Expand Down Expand Up @@ -79,7 +79,7 @@ function parse_args() {
[ -z "$PLATFORM" ] && PLATFORM=$(uname -s | awk '{print tolower($0)}')
[ -z "$ARCHITECTURE" ] && ARCHITECTURE=$(uname -m)
[ -z "$DISTRIBUTION" ] && DISTRIBUTION="tar"
[ -z "$BRANCH" ] && BRANCH=$(<VERSION)
[ -z "$BRANCH" ] && BRANCH=$(bash build-scripts/product_version.sh)

case $PLATFORM-$DISTRIBUTION-$ARCHITECTURE in
linux-tar-x64 | darwin-tar-x64)
Expand Down
1 change: 1 addition & 0 deletions build-scripts/builder/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ RUN apt-get update \
rpm \
rpm2cpio \
maven \
jq \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

# Install OpenJDK 21
Expand Down
2 changes: 1 addition & 1 deletion build-scripts/builder/builder.sh
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ function main() {
compose_file="build-scripts/${current}/compose.yml"
compose_cmd="docker compose -f $compose_file"
REPO_PATH=$(pwd)
VERSION=$(cat VERSION)
VERSION="$(bash ${REPO_PATH}/build-scripts/product_version.sh)"
export REPO_PATH
export VERSION
export INDEXER_PLUGINS_BRANCH
Expand Down
2 changes: 1 addition & 1 deletion build-scripts/builder/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ main() {
echo "---------Starting Build Process---------"
clone_repositories
# Set version env var
VERSION=$(cat ~/VERSION)
VERSION=$(bash ~/build-scripts/product_version.sh)
# Build and assemble the package
build_plugins "$VERSION" "$REVISION"
build_reporting "$VERSION" "$REVISION"
Expand Down
8 changes: 4 additions & 4 deletions build-scripts/check-version.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#!/bin/bash

# Check if VERSION file has exactly one line and that line is non-empty
if [ "$(wc -l <VERSION)" -ne 0 ]; then
echo "Error: VERSION file must contain exactly one line."
if [ "$(jq -e .version VERSION.json)" -ne 0 ]; then
echo "Error: VERSION file must contain a 'version' field."
exit 1
fi
if [ -z "$(cat VERSION)" ]; then
echo "Error: VERSION file is empty."
if [ "$(jq -e .stage VERSION.json)" -ne 0 ]; then
echo "Error: VERSION file must contain a 'stage' field."
exit 1
fi
6 changes: 3 additions & 3 deletions build-scripts/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ FROM amazonlinux:2023.6.20241212.0 AS builder
ARG VERSION
ARG INDEXER_TAR_NAME

RUN yum install openssl tar findutils shadow-utils -y
RUN yum install openssl tar findutils shadow-utils jq -y

COPY ${INDEXER_TAR_NAME} /

Expand All @@ -30,7 +30,7 @@ ENV USER="wazuh-indexer" \
NAME="wazuh-indexer" \
INSTALL_DIR="/usr/share/wazuh-indexer"

RUN yum install curl-minimal shadow-utils findutils hostname -y
RUN yum install curl-minimal shadow-utils findutils hostname jq -y

RUN getent group $GROUP || groupadd -r -g 1000 $GROUP

Expand Down Expand Up @@ -75,4 +75,4 @@ EXPOSE 9200

ENTRYPOINT ["/entrypoint.sh"]
# Dummy overridable parameter parsed by entrypoint
CMD ["opensearchwrapper"]
CMD ["opensearchwrapper"]
15 changes: 15 additions & 0 deletions build-scripts/product_version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash


## Check that jq is installed
if [ ! -e '/usr/bin/jq' ]
then
echo "ERROR: jq command could not be found under /usr/bin"
exit 1
fi

cd "$(dirname "${BASH_SOURCE[0]}")"

jq -r .version ../VERSION.json

exit 0
2 changes: 1 addition & 1 deletion build-scripts/provision.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
apt-get update -y && apt-get upgrade -y && apt-get install -y curl build-essential &&
apt-get install -y debmake debhelper-compat &&
apt-get install -y libxrender1 libxtst6 libxi6 &&
apt-get install -y libatk1.0-0 libatk-bridge2.0-0 libcups2 libdrm2 libatspi2.0-dev libxcomposite-dev libxdamage1 libxfixes3 libxfixes-dev libxrandr2 libgbm-dev libxkbcommon-x11-0 libpangocairo-1.0-0 libcairo2 libcairo2-dev libnss3 libnspr4 libnspr4-dev &&
apt-get install -y libatk1.0-0 libatk-bridge2.0-0 libcups2 libdrm2 libatspi2.0-dev libxcomposite-dev libxdamage1 libxfixes3 libxfixes-dev libxrandr2 libgbm-dev libxkbcommon-x11-0 libpangocairo-1.0-0 libcairo2 libcairo2-dev libnss3 libnspr4 libnspr4-dev jq &&
apt-get clean -y
7 changes: 6 additions & 1 deletion distribution/archives/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ import org.opensearch.gradle.JavaPackageType
apply plugin: 'opensearch.internal-distribution-archive-setup'

CopySpec archiveFiles(CopySpec modulesFiles, String distributionType, String platform, String architecture, JavaPackageType java) {
version = rootProject.file('VERSION').getText()
version = new ByteArrayOutputStream()
rootProject.exec {
commandLine 'bash', rootProject.file('build-scripts/product_version.sh').absolutePath
standardOutput = version
}
version = version.toString().trim()
return copySpec {
into("wazuh-indexer-${version}") {
into('lib') {
Expand Down
2 changes: 1 addition & 1 deletion distribution/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ configure(subprojects.findAll { ['archives', 'packages'].contains(it.name) }) {

versionFile = {
copySpec {
from(rootProject.file('VERSION'))
from(rootProject.file('VERSION.json'))
filePermissions{
unix 0644
}
Expand Down
7 changes: 6 additions & 1 deletion distribution/packages/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,12 @@ addProcessFilesTask('rpm', false)
// since we have different templated files that need to be consumed, but the structure
// is the same
Closure commonPackageConfig(String type, boolean jdk, String architecture) {
project.version = rootProject.file('VERSION').getText()
version = new ByteArrayOutputStream()
rootProject.exec {
commandLine 'bash', rootProject.file('build-scripts/product_version.sh').absolutePath
standardOutput = version
}
project.version = version.toString().trim()
return {
onlyIf {
OS.current().equals(OS.WINDOWS) == false
Expand Down
2 changes: 1 addition & 1 deletion distribution/packages/src/deb/debmake_install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ if [ -e "${buildroot}/${config_dir}/wazuh-indexer-reports-scheduler/reports-sche
fi

# Files that need other permissions
chmod -c 440 "${buildroot}${product_dir}/VERSION"
chmod -c 440 "${buildroot}${product_dir}/VERSION.json"
if [ -d "${buildroot}${product_dir}/plugins/opensearch-security" ]; then
chmod -c 0740 "${buildroot}${product_dir}"/plugins/opensearch-security/tools/*.sh
fi
Expand Down
4 changes: 2 additions & 2 deletions distribution/packages/src/rpm/wazuh-indexer.rpm.spec
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ set -- "$@" "%{config_dir}/jvm.options"
set -- "$@" "%{config_dir}/opensearch.yml"
set -- "$@" "%{config_dir}/opensearch-security/.*\.yml"
set -- "$@" "%{config_dir}/opensearch-security/opensearch.yml.example"
set -- "$@" "%{product_dir}/VERSION"
set -- "$@" "%{product_dir}/VERSION.json"
set -- "$@" "%{product_dir}/plugins/opensearch-security/tools/.*\.sh"
set -- "$@" "%{product_dir}/bin/.*"
set -- "$@" "%{product_dir}/jdk/bin/.*"
Expand Down Expand Up @@ -347,7 +347,7 @@ fi
%endif

# Files that need other permissions
%attr(440, %{name}, %{name}) %{product_dir}/VERSION
%attr(440, %{name}, %{name}) %{product_dir}/VERSION.json
%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