Skip to content

Commit

Permalink
Added option to build with S3 base or locally
Browse files Browse the repository at this point in the history
  • Loading branch information
okynos committed Feb 9, 2022
1 parent c9c013d commit 27b6b1c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 8 deletions.
24 changes: 20 additions & 4 deletions stack/indexer/rpm/build_package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
# License (version 2) as published by the FSF - Free Software
# Foundation.

set -e

CURRENT_PATH="$( cd $(dirname $0) ; pwd -P )"
ARCHITECTURE="x86_64"
OUTDIR="${CURRENT_PATH}/output"
Expand All @@ -16,6 +18,7 @@ BUILD_DOCKER="yes"
RPM_X86_BUILDER="rpm_indexer_builder_x86"
RPM_BUILDER_DOCKERFILE="${CURRENT_PATH}/docker"
FUTURE="no"
BASE="s3"

trap ctrl_c INT

Expand Down Expand Up @@ -45,15 +48,19 @@ build_rpm() {
fi

# Build the RPM package with a Docker container
VOLUMES="-v ${OUTDIR}/:/tmp:Z"
if [ "${REFERENCE}" ];then
docker run -t --rm -v ${OUTDIR}/:/tmp:Z \
docker run -t --rm ${VOLUMES} \
${CONTAINER_NAME} ${ARCHITECTURE} ${REVISION} \
${FUTURE} ${REFERENCE} || return 1
${FUTURE} ${BASE} ${REFERENCE} || return 1
else
docker run -t --rm -v ${OUTDIR}/:/tmp:Z \
if [ "${BASE}" = "local" ];then
VOLUMES="${VOLUMES} -v ${CURRENT_PATH}/../base/output:/root/output:Z"
fi
docker run -t --rm ${VOLUMES} \
-v ${CURRENT_PATH}/../../..:/root:Z \
${CONTAINER_NAME} ${ARCHITECTURE} \
${REVISION} ${FUTURE} || return 1
${REVISION} ${FUTURE} ${BASE} || return 1
fi

echo "Package $(ls -Art ${OUTDIR} | tail -n 1) added to ${OUTDIR}."
Expand Down Expand Up @@ -87,6 +94,7 @@ help() {
echo " --reference <ref> [Optional] wazuh-packages branch to download SPECs, not used by default."
echo " --dont-build-docker [Optional] Locally built docker image will be used instead of generating a new one."
echo " --future [Optional] Build test future package x.30.0 Used for development purposes."
echo " --base <s3/local> [Optional] Base file location, use local or s3, default: s3"
echo " -h, --help Show this help."
echo
exit $1
Expand Down Expand Up @@ -132,6 +140,14 @@ main() {
FUTURE="yes"
shift 1
;;
"--base")
if [ -n "$2" ]; then
BASE="$2"
shift 2
else
help 1
fi
;;
"-s"|"--store")
if [ -n "$2" ]; then
OUTDIR="$2"
Expand Down
6 changes: 5 additions & 1 deletion stack/indexer/rpm/builder.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@
# Foundation.

set -ex

# Script parameters to build the package
target="wazuh-indexer"
architecture=$1
release=$2
future=$3
spec_reference=$4
base_location=$4
spec_reference=$5
directory_base="/usr/share/wazuh-indexer"
rpmbuild="rpmbuild"

Expand Down Expand Up @@ -57,8 +59,10 @@ fi
cd ${build_dir} && tar czf "${rpm_build_dir}/SOURCES/${pkg_name}.tar.gz" "${pkg_name}"

# Building RPM
ls -lah /root/output
/usr/bin/rpmbuild --define "_topdir ${rpm_build_dir}" --define "_version ${version}" \
--define "_release ${release}" --define "_localstatedir ${directory_base}" \
--define "_base ${base_location}" \
--target ${architecture} -ba ${rpm_build_dir}/SPECS/${pkg_name}.spec

cd ${pkg_path} && sha512sum ${rpm_file} > /tmp/${rpm_file}.sha512
Expand Down
10 changes: 7 additions & 3 deletions stack/indexer/rpm/wazuh-indexer.spec
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,13 @@ mkdir -p ${RPM_BUILD_ROOT}%{LOG_DIR}
mkdir -p ${RPM_BUILD_ROOT}%{LIB_DIR}
mkdir -p ${RPM_BUILD_ROOT}%{SYS_DIR}

# Download required sources
curl -kOL https://s3.amazonaws.com/warehouse.wazuh.com/stack/indexer/wazuh-indexer-base-linux-x64.tar.gz
tar -xzf wazuh-indexer-*.tar.gz && rm -f wazuh-indexer-*.tar.gz
# Set up required files
if [ "%{_base}" = "s3" ];then
curl -kOL https://packages-dev.wazuh.com/stack/indexer/base/wazuh-indexer-base-%{version}-linux-x64.tar.xz
else
cp /root/output/wazuh-indexer-base-%{version}-linux-x64.tar.xz ./
fi
tar -xf wazuh-indexer-*.tar.xz && rm -f wazuh-indexer-*.tar.xz
chown -R %{USER}:%{GROUP} wazuh-indexer-*/*

# Copy base files into RPM_BUILD_ROOT directory
Expand Down

0 comments on commit 27b6b1c

Please sign in to comment.