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

The creation of the base is integrated within the script build_packages.sh #1831

Merged
merged 7 commits into from Sep 7, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 5 additions & 5 deletions stack/dashboard/base/builder.sh
Expand Up @@ -8,13 +8,13 @@
# License (version 2) as published by the FSF - Free Software
# Foundation.

set -ex
set -e

# Script parameters to build the package
opensearch_version="${1}"
future="${2}"
revision="${3}"
reference="${4}"
future="${1}"
revision="${2}"
reference="${3}"
opensearch_version="2.1.0"
base_dir=/tmp/output/wazuh-dashboard-base

# -----------------------------------------------------------------------------
Expand Down
14 changes: 2 additions & 12 deletions stack/dashboard/base/generate_base.sh
Expand Up @@ -15,7 +15,6 @@ reference=""
current_path="$( cd $(dirname $0) ; pwd -P )"
dockerfile_path="${current_path}/docker"
container_name="dashboard_base_builder"
opensearch_version="2.1.0"
outdir="${current_path}/output"
revision="1"
future="no"
Expand Down Expand Up @@ -49,11 +48,11 @@ build() {

if [ "${reference}" ];then
docker run -t --rm -v ${outdir}/:/tmp/output:Z \
${container_name} ${opensearch_version} ${future} ${revision} ${reference} || return 1
${container_name} ${future} ${revision} ${reference} || return 1
else
docker run -t --rm -v ${outdir}/:/tmp/output:Z \
-v ${current_path}/../../..:/root:Z \
${container_name} ${opensearch_version} ${future} ${revision} || return 1
${container_name} ${future} ${revision} || return 1
fi

echo "Base file $(ls -Art ${outdir} | tail -n 1) added to ${outdir}."
Expand All @@ -68,7 +67,6 @@ help() {
echo "Usage: $0 [OPTIONS]"
echo
echo " -s, --store <path> [Optional] Set the destination path of package. By default, an output folder will be created."
echo " -v, --version <path> [Optional] The OpenSearch-dashboards Version. By default, ${opensearch_version}"
echo " --reference <ref> [Optional] wazuh-packages branch or tag"
echo " --future [Optional] Build test future package 99.99.0 Used for development purposes."
echo " -r, --revision <rev> [Optional] Package revision. By default ${revision}"
Expand All @@ -94,14 +92,6 @@ main() {
help 1
fi
;;
"-v"|"--version")
if [ -n "${2}" ]; then
opensearch_version="${2}"
shift 2
else
help 1
fi
;;
"--reference")
if [ -n "${2}" ]; then
reference="${2}"
Expand Down
40 changes: 15 additions & 25 deletions stack/dashboard/deb/build_package.sh
Expand Up @@ -16,8 +16,8 @@ build_docker="yes"
deb_amd64_builder="deb_dashboard_builder_amd64"
deb_builder_dockerfile="${current_path}/docker"
future="no"
base="s3"
base_path="${current_path}/../base/output"
base_path="/tmp"
base_cmd=""

trap ctrl_c INT

Expand All @@ -41,6 +41,15 @@ build_deb() {
# Copy the necessary files
cp ${current_path}/builder.sh ${dockerfile_path}

# Base generation
if [ "${future}" == "yes" ];then
base_cmd+="--future "
fi
if [ "${reference}" ];then
base_cmd+="--reference ${reference}"
fi
../base/generate_base.sh -s ${base_path} -r ${revision} ${base_cmd}

# Build the Docker image
if [[ ${build_docker} == "yes" ]]; then
docker build -t ${container_name} ${dockerfile_path} || return 1
Expand All @@ -51,16 +60,15 @@ build_deb() {
volumes="-v ${outdir}/:/tmp:Z"
if [ "${reference}" ];then
docker run -t --rm ${volumes} \
-v ${base_path}:/root/output:Z \
${container_name} ${architecture} ${revision} \
${future} ${base} ${reference} || return 1
${future} ${reference} || return 1
else
if [ "${base}" = "local" ];then
volumes="${volumes} -v ${base_path}:/root/output:Z"
fi
docker run -t --rm ${volumes} \
-v ${base_path}:/root/output:Z \
-v ${current_path}/../../..:/root:Z \
${container_name} ${architecture} ${revision} \
${future} ${base} || return 1
${future} || return 1
fi

echo "Package $(ls -Art ${outdir} | tail -n 1) added to ${outdir}."
Expand Down Expand Up @@ -94,8 +102,6 @@ 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 99.99.0 Used for development purposes."
echo " --base <s3/local> [Optional] Base file location, use local or s3, default: s3"
echo " --base-path [Optional] If base is local, you can indicate the full path where the base is located, default: stack/dashboard/base/output"
echo " -h, --help Show this help."
echo
exit $1
Expand Down Expand Up @@ -141,22 +147,6 @@ main() {
future="yes"
shift 1
;;
"--base")
if [ -n "${2}" ]; then
base="${2}"
shift 2
else
help 1
fi
;;
"--base-path")
if [ -n "${2}" ]; then
base_path="${2}"
shift 2
else
help 1
fi
;;
"-s"|"--store")
if [ -n "${2}" ]; then
outdir="${2}"
Expand Down
7 changes: 3 additions & 4 deletions stack/dashboard/deb/builder.sh
Expand Up @@ -8,14 +8,13 @@
# License (version 2) as published by the FSF - Free Software
# Foundation.

set -ex
set -e
# Script parameters to build the package
target="wazuh-dashboard"
architecture=$1
revision=$2
future=$3
base_location=$4
reference=$5
reference=$4
directory_base="/usr/share/wazuh-dashboard"

if [ -z "${revision}" ]; then
Expand Down Expand Up @@ -63,7 +62,7 @@ cd ${source_dir}
mk-build-deps -ir -t "apt-get -o Debug::pkgProblemResolver=yes -y"

# Build package
debuild --no-lintian -eINSTALLATION_DIR="${directory_base}" -eBASE="${base_location}" -eBASE_VERSION="${version}" -eBASE_REVISION="${revision}" -b -uc -us
debuild --no-lintian -eINSTALLATION_DIR="${directory_base}" -eBASE_VERSION="${version}" -eBASE_REVISION="${revision}" -b -uc -us

deb_file="${target}_${version}-${revision}_${architecture}.deb"

Expand Down
9 changes: 2 additions & 7 deletions stack/dashboard/deb/debian/rules
Expand Up @@ -52,12 +52,7 @@ override_dh_auto_install:
# -----------------------------------------------------------------------------

override_dh_install:
if [ "$(BASE)" = "s3" ]; then \
curl -kOL https://packages-dev.wazuh.com/stack/dashboard/base/$(DASHBOARD_FILE) ;\
else \
cp /root/output/$(DASHBOARD_FILE) ./ ;\
fi

cp /root/output/$(DASHBOARD_FILE) ./ ;\

groupadd $(GROUP)
useradd -g $(GROUP) $(USER)
Expand Down Expand Up @@ -92,7 +87,7 @@ override_dh_install:
chown $(USER):$(GROUP) $(TARGET_DIR)/etc/default/$(NAME)

if [ "$(BASE_VERSION)" = "99.99.0" ]; then \
runuser $(USER) --shell="/bin/bash" --command="$(TARGET_DIR)$(INSTALLATION_DIR)/bin/opensearch-dashboards-plugin install https://packages-dev.wazuh.com/futures/ui/dashboard/wazuh-99.99.0-1.zip" ;\
runuser $(USER) --shell="/bin/bash" --command="$(TARGET_DIR)$(INSTALLATION_DIR)/bin/opensearch-dashboards-plugin install https://packages-dev.wazuh.com/futures/ui/dashboard/wazuh-99.99.0-$(BASE_REVISION).zip" ;\
else \
runuser $(USER) --shell="/bin/bash" --command="$(TARGET_DIR)$(INSTALLATION_DIR)/bin/opensearch-dashboards-plugin install https://packages-dev.wazuh.com/pre-release/ui/dashboard/wazuh-$(BASE_VERSION)-${BASE_REVISION}.zip" ;\
fi
Expand Down
40 changes: 15 additions & 25 deletions stack/dashboard/rpm/build_package.sh
Expand Up @@ -16,8 +16,8 @@ build_docker="yes"
rpm_x86_builder="rpm_dashboard_builder_x86"
rpm_builder_dockerfile="${current_path}/docker"
future="no"
base="s3"
base_path="${current_path}/../base/output"
base_path="/tmp"
base_cmd=""

trap ctrl_c INT

Expand All @@ -41,6 +41,15 @@ build_rpm() {
# Copy the necessary files
cp ${current_path}/builder.sh ${dockerfile_path}

# Base generation
if [ "${future}" == "yes" ];then
base_cmd+="--future "
fi
if [ "${reference}" ];then
base_cmd+="--reference ${reference}"
fi
../base/generate_base.sh -s ${base_path} -r ${revision} ${base_cmd}

# Build the Docker image
if [[ ${build_docker} == "yes" ]]; then
docker build -t ${container_name} ${dockerfile_path} || return 1
Expand All @@ -50,16 +59,15 @@ build_rpm() {
volumes="-v ${outdir}/:/tmp:Z"
if [ "${reference}" ];then
docker run -t --rm ${volumes} \
-v ${base_path}:/root/output:Z \
${container_name} ${architecture} ${revision} \
${future} ${base} ${reference} || return 1
${future} ${reference} || return 1
else
if [ "${base}" = "local" ];then
volumes="${volumes} -v ${base_path}:/root/output:Z"
fi
docker run -t --rm ${volumes} \
-v ${base_path}:/root/output:Z \
-v ${current_path}/../../..:/root:Z \
${container_name} ${architecture} \
${revision} ${future} ${base} || return 1
${revision} ${future} || return 1
fi

echo "Package $(ls -Art ${outdir} | tail -n 1) added to ${outdir}."
Expand Down Expand Up @@ -93,8 +101,6 @@ 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 99.99.0 Used for development purposes."
echo " --base <s3/local> [Optional] Base file location, use local or s3, default: s3"
echo " --base-path [Optional] If base is local, you can indicate the full path where the base is located, default: stack/dashboard/base/output"
echo " -h, --help Show this help."
echo
exit $1
Expand Down Expand Up @@ -140,22 +146,6 @@ main() {
future="yes"
shift 1
;;
"--base")
if [ -n "$2" ]; then
base="$2"
shift 2
else
help 1
fi
;;
"--base-path")
if [ -n "$2" ]; then
base_path="$2"
shift 2
else
help 1
fi
;;
"-s"|"--store")
if [ -n "$2" ]; then
outdir="$2"
Expand Down
4 changes: 1 addition & 3 deletions stack/dashboard/rpm/builder.sh
Expand Up @@ -14,8 +14,7 @@ target="wazuh-dashboard"
architecture=$1
revision=$2
future=$3
base_location=$4
reference=$5
reference=$4
directory_base="/usr/share/wazuh-dashboard"

if [ -z "${revision}" ]; then
Expand Down Expand Up @@ -61,7 +60,6 @@ cd ${build_dir} && tar czf "${rpm_build_dir}/SOURCES/${pkg_name}.tar.gz" "${pkg_
# Building RPM
/usr/bin/rpmbuild --define "_topdir ${rpm_build_dir}" --define "_version ${version}" \
--define "_release ${revision}" --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: 3 additions & 7 deletions stack/dashboard/rpm/wazuh-dashboard.spec
Expand Up @@ -42,12 +42,8 @@ Wazuh dashboard is a user interface and visualization tool for security-related

%prep

# Set up required files
if [ "%{_base}" = "s3" ];then
curl -kOL https://packages-dev.wazuh.com/stack/dashboard/base/%{DASHBOARD_FILE}
else
cp /root/output/%{DASHBOARD_FILE} ./
fi
cp /root/output/%{DASHBOARD_FILE} ./

groupadd %{GROUP}
useradd -g %{GROUP} %{USER}

Expand Down Expand Up @@ -94,7 +90,7 @@ chown %{USER}:%{GROUP} %{buildroot}/etc/systemd/system/wazuh-dashboard.service
chown %{USER}:%{GROUP} %{buildroot}/etc/init.d/wazuh-dashboard

if [ "%{version}" = "99.99.0" ];then
runuser %{USER} --shell="/bin/bash" --command="%{buildroot}%{INSTALL_DIR}/bin/opensearch-dashboards-plugin install https://packages-dev.wazuh.com/futures/ui/dashboard/wazuh-99.99.0-1.zip"
runuser %{USER} --shell="/bin/bash" --command="%{buildroot}%{INSTALL_DIR}/bin/opensearch-dashboards-plugin install https://packages-dev.wazuh.com/futures/ui/dashboard/wazuh-99.99.0-%{release}.zip"
else
runuser %{USER} --shell="/bin/bash" --command="%{buildroot}%{INSTALL_DIR}/bin/opensearch-dashboards-plugin install https://packages-dev.wazuh.com/pre-release/ui/dashboard/wazuh-%{version}-%{release}.zip"
fi
Expand Down
8 changes: 4 additions & 4 deletions stack/indexer/base/builder.sh
Expand Up @@ -10,10 +10,10 @@

set -e

opensearch_version="${1}"
future="${2}"
revision="${3}"
reference="${4}"
future="${1}"
revision="${2}"
reference="${3}"
opensearch_version="2.1.0"
base_dir=/tmp/output/wazuh-indexer-base

# -----------------------------------------------------------------------------
Expand Down
15 changes: 2 additions & 13 deletions stack/indexer/base/generate_base.sh
Expand Up @@ -11,8 +11,6 @@
set -e

reference=""
opensearch_version="2.1.0"

current_path="$( cd $(dirname $0) ; pwd -P )"
outdir="${current_path}/output"
dockerfile_path="${current_path}/docker"
Expand Down Expand Up @@ -49,11 +47,11 @@ build_base() {
# Build the RPM package with a Docker container
if [ "${reference}" ];then
docker run -t --rm -v ${outdir}/:/tmp/output:Z \
${container_name} ${opensearch_version} ${future} ${revision} ${reference} || return 1
${container_name} ${future} ${revision} ${reference} || return 1
else
docker run -t --rm -v ${outdir}/:/tmp/output:Z \
-v ${current_path}/../../..:/root:Z \
${container_name} ${opensearch_version} ${future} ${revision} || return 1
${container_name} ${future} ${revision} || return 1
fi

echo "Base file $(ls -Art ${outdir} | tail -n 1) added to ${outdir}."
Expand All @@ -68,7 +66,6 @@ help() {
echo "Usage: $0 [OPTIONS]"
echo
echo " -s, --store <path> [Optional] Set the destination path of package. By default, an output folder will be created."
echo " -v, --version <version> [Optional] OpenSearch version, by default ${opensearch_version}"
echo " --reference <ref> [Optional] wazuh-packages branch or tag"
echo " --future [Optional] Build test future package 99.99.0 Used for development purposes."
echo " -r, --revision <rev> [Optional] Package revision. By default ${revision}"
Expand All @@ -94,14 +91,6 @@ main() {
help 1
fi
;;
"-v"|"--version")
if [ -n "${2}" ]; then
opensearch_version="${2}"
shift 2
else
help 1
fi
;;
"--reference")
if [ -n "${2}" ]; then
reference="${2}"
Expand Down