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

Unification of base creation in stack package Dockerfiles #1815

Open
wants to merge 3 commits into
base: 4.4
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
11 changes: 6 additions & 5 deletions stack/dashboard/base/builder.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
# 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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,14 @@ 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"

trap ctrl_c INT

clean() {
exit_code=$1

# Clean the files
rm -rf ${dockerfile_path}/{*.sh,*.tar.gz,wazuh-*}
rm -rf ${dockerfile_path}/VERSION ${dockerfile_path}/files

exit ${exit_code}
}
Expand All @@ -40,23 +38,33 @@ build_deb() {

# Copy the necessary files
cp ${current_path}/builder.sh ${dockerfile_path}
cp ../base/builder.sh ${dockerfile_path}/builder_base.sh
cp -R ../base/files ${dockerfile_path}/
cp ../../../VERSION ${dockerfile_path}/VERSION

if [[ ${future} == "yes" ]]; then
version="99.99.0"
else
version=$(cat ../../../VERSION)
fi


# Build the Docker image
if [[ ${build_docker} == "yes" ]]; then
docker build -t ${container_name} ${dockerfile_path} || return 1
docker build --progress=plain --build-arg VERSION=${version} \
--build-arg FUTURE=${future} --build-arg REVISION=${revision} \
--build-arg REFERENCE=${reference} -t ${container_name} ${dockerfile_path} || return 1
fi


# Build the Debian package with a Docker container
volumes="-v ${outdir}/:/tmp:Z"

if [ "${reference}" ];then
docker run -t --rm ${volumes} \
${container_name} ${architecture} ${revision} \
${future} ${base} ${reference} || return 1
else
if [ "${base}" = "local" ];then
volumes="${volumes} -v ${base_path}:/root/output:Z"
fi
docker run -t --rm ${volumes} \
-v ${current_path}/../../..:/root:Z \
${container_name} ${architecture} ${revision} \
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
6 changes: 1 addition & 5 deletions stack/dashboard/deb/debian/rules
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +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 /opt/$(DASHBOARD_FILE) ./ ;\
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The base source directory change is due to the fact that the /root directory is a directory mounted at the boot of the container, for this reason, everything that exists in the image in the /root directory is replaced by the contents of the directory mounted.

For this reason, I decided to place the base in another dir and continue the installation with this reference



groupadd $(GROUP)
Expand Down
59 changes: 57 additions & 2 deletions stack/dashboard/deb/docker/amd64/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,67 @@
FROM rockylinux:8.5 as builder_base

ARG FUTURE
ARG REVISION
ARG REFERENCE

# Install all the necessary tools to build the packages
RUN yum clean all && yum update -y
RUN yum install -y \
curl \
tar \
findutils \
git \
xz \
gcc \
make \
bc \
sed \
gzip \
autoconf \
automake \
libtool \
jq

RUN git clone https://github.com/google/brotli.git

RUN cd brotli && ./bootstrap && ./configure --prefix=/usr --bindir=/usr/bin --sbindir=/usr/sbin --libexecdir=/usr/lib64/brotli --libdir=/usr/lib64/brotli --datarootdir=/usr/share --mandir=/usr/share/man/man1 --docdir=/usr/share/doc \
&& make && make install

# Add the script
ADD builder_base.sh /usr/local/bin/builder_base
RUN chmod +x /usr/local/bin/builder_base

ADD files/ /root/stack/dashboard/base/files/
ADD VERSION /root/VERSION

RUN if [ $REFERENCE ];then \
/usr/local/bin/builder_base $FUTURE $REVISION $REFERENCE; \
else \
/usr/local/bin/builder_base $FUTURE $REVISION; \
fi

FROM debian:10

ARG VERSION
ARG REVISION
ENV DEBIAN_FRONTEND noninteractive

COPY --from=builder_base "/tmp/output/wazuh-dashboard-base-$VERSION-$REVISION-linux-x64.tar.xz" "/opt/wazuh-dashboard-base-$VERSION-$REVISION-linux-x64.tar.xz"

# Installing necessary packages
RUN apt-get update && apt-get install -y apt-utils && \
apt-get install -y \
curl sudo wget expect gnupg build-essential \
devscripts equivs selinux-basics procps gawk
curl \
sudo \
wget \
expect \
gnupg \
build-essential \
devscripts \
equivs \
selinux-basics \
procps \
gawk

# Add the script to build the Debian package
ADD builder.sh /usr/local/bin/builder
Expand Down
42 changes: 16 additions & 26 deletions stack/dashboard/rpm/build_package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ 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"

trap ctrl_c INT

Expand All @@ -26,6 +24,7 @@ clean() {

# Clean the files
rm -rf ${dockerfile_path}/{*.sh,*.tar.gz,wazuh-*}
rm -rf ${dockerfile_path}/VERSION ${dockerfile_path}/files

exit ${exit_code}
}
Expand All @@ -40,26 +39,35 @@ build_rpm() {

# Copy the necessary files
cp ${current_path}/builder.sh ${dockerfile_path}
cp ../base/builder.sh ${dockerfile_path}/builder_base.sh
cp -R ../base/files ${dockerfile_path}/
cp ../../../VERSION ${dockerfile_path}/VERSION

if [[ ${future} == "yes" ]]; then
version="99.99.0"
else
version=$(cat ../../../VERSION)
fi

# Build the Docker image
if [[ ${build_docker} == "yes" ]]; then
docker build -t ${container_name} ${dockerfile_path} || return 1
docker build --progress=plain --build-arg VERSION=${version} \
--build-arg FUTURE=${future} --build-arg REVISION=${revision} \
--build-arg REFERENCE=${reference} -t ${container_name} ${dockerfile_path} || return 1
fi

# Build the RPM package with a Docker container
volumes="-v ${outdir}/:/tmp:Z"

if [ "${reference}" ];then
docker run -t --rm ${volumes} \
${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 ${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
6 changes: 2 additions & 4 deletions stack/dashboard/rpm/builder.sh
Original file line number Diff line number Diff line change
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 @@ -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
Loading