From e2b246730b105f65e98e6cbe8c07e47041f5fdcf Mon Sep 17 00:00:00 2001 From: c-bordon Date: Tue, 30 Aug 2022 09:59:42 -0300 Subject: [PATCH 1/3] Integrate base creation in package deb dockerfile --- stack/indexer/base/builder.sh | 8 ++-- stack/indexer/base/generate_base.sh | 14 +------ stack/indexer/deb/build_package.sh | 38 +++++++------------ stack/indexer/deb/debian/rules | 7 +--- stack/indexer/deb/docker/amd64/Dockerfile | 46 +++++++++++++++++++++-- 5 files changed, 64 insertions(+), 49 deletions(-) diff --git a/stack/indexer/base/builder.sh b/stack/indexer/base/builder.sh index 7158b25e82..4b56d7bae5 100644 --- a/stack/indexer/base/builder.sh +++ b/stack/indexer/base/builder.sh @@ -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 # ----------------------------------------------------------------------------- diff --git a/stack/indexer/base/generate_base.sh b/stack/indexer/base/generate_base.sh index 323ed71570..911d89c8b4 100755 --- a/stack/indexer/base/generate_base.sh +++ b/stack/indexer/base/generate_base.sh @@ -11,7 +11,6 @@ set -e reference="" -opensearch_version="2.1.0" current_path="$( cd $(dirname $0) ; pwd -P )" outdir="${current_path}/output" @@ -49,11 +48,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}." @@ -68,7 +67,6 @@ help() { echo "Usage: $0 [OPTIONS]" echo echo " -s, --store [Optional] Set the destination path of package. By default, an output folder will be created." - echo " -v, --version [Optional] OpenSearch version, by default ${opensearch_version}" echo " --reference [Optional] wazuh-packages branch or tag" echo " --future [Optional] Build test future package 99.99.0 Used for development purposes." echo " -r, --revision [Optional] Package revision. By default ${revision}" @@ -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}" diff --git a/stack/indexer/deb/build_package.sh b/stack/indexer/deb/build_package.sh index e3917c7b01..c689335cd0 100755 --- a/stack/indexer/deb/build_package.sh +++ b/stack/indexer/deb/build_package.sh @@ -16,8 +16,6 @@ build_docker="yes" deb_amd64_builder="deb_indexer_builder_amd64" deb_builder_dockerfile="${current_path}/docker" future="no" -base="s3" -base_path="${current_path}/../base/output" trap ctrl_c INT @@ -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} } @@ -40,23 +39,32 @@ 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} \ @@ -94,8 +102,6 @@ help() { echo " --reference [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 [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/indexer/base/output" echo " -h, --help Show this help." echo exit $1 @@ -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}" diff --git a/stack/indexer/deb/debian/rules b/stack/indexer/deb/debian/rules index 8ef0de8513..40206d8a82 100644 --- a/stack/indexer/deb/debian/rules +++ b/stack/indexer/deb/debian/rules @@ -61,11 +61,8 @@ override_dh_auto_install: override_dh_install: rm -rf $(INSTALLATION_DIR)/ - if [ "$(BASE)" = "s3" ]; then \ - curl -kOL https://packages-dev.wazuh.com/stack/indexer/base/$(INDEXER_FILE) ;\ - else \ - cp /root/output/$(INDEXER_FILE) ./ ;\ - fi + cp /opt/$(INDEXER_FILE) ./ ;\ + tar -xf $(INDEXER_FILE) # Copy to the target diff --git a/stack/indexer/deb/docker/amd64/Dockerfile b/stack/indexer/deb/docker/amd64/Dockerfile index 6edf9beae2..43df892a8c 100644 --- a/stack/indexer/deb/docker/amd64/Dockerfile +++ b/stack/indexer/deb/docker/amd64/Dockerfile @@ -1,12 +1,50 @@ +FROM rockylinux:8.5 as builder_base + +ARG FUTURE +ARG REVISION +ARG REFERENCE + +# Install all the necessary tools +RUN yum clean all && yum update -y +RUN yum install -y \ + findutils \ + git \ + java-11-openjdk-devel + +# Add the script +ADD builder_base.sh /usr/local/bin/builder_base +RUN chmod +x /usr/local/bin/builder_base + +ADD files/ /root/stack/indexer/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:8 +ARG VERSION +ARG REVISION ENV DEBIAN_FRONTEND noninteractive +COPY --from=builder_base "/tmp/output/wazuh-indexer-base-$VERSION-$REVISION-linux-x64.tar.xz" "/opt/wazuh-indexer-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 +RUN apt-get update && apt-get install -y apt-utils \ + 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 From 0f0159b45ace3a8ac850f20189cfcd95f4b8be1c Mon Sep 17 00:00:00 2001 From: c-bordon Date: Tue, 30 Aug 2022 13:54:49 -0300 Subject: [PATCH 2/3] Integrate base generation in package dockerfile --- stack/dashboard/base/builder.sh | 11 ++-- stack/dashboard/base/generate_base.sh | 14 +--- stack/dashboard/deb/build_package.sh | 40 +++++------- stack/dashboard/deb/debian/rules | 6 +- stack/dashboard/deb/docker/amd64/Dockerfile | 59 ++++++++++++++++- stack/dashboard/rpm/build_package.sh | 42 +++++------- stack/dashboard/rpm/builder.sh | 6 +- stack/dashboard/rpm/docker/x86_64/Dockerfile | 67 ++++++++++++++++++-- stack/dashboard/rpm/wazuh-dashboard.spec | 6 +- stack/indexer/deb/builder.sh | 5 +- stack/indexer/rpm/build_package.sh | 42 +++++------- stack/indexer/rpm/builder.sh | 4 +- stack/indexer/rpm/docker/x86_64/Dockerfile | 44 ++++++++++++- stack/indexer/rpm/wazuh-indexer.spec | 8 +-- 14 files changed, 224 insertions(+), 130 deletions(-) diff --git a/stack/dashboard/base/builder.sh b/stack/dashboard/base/builder.sh index 927719c537..50f551331f 100755 --- a/stack/dashboard/base/builder.sh +++ b/stack/dashboard/base/builder.sh @@ -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 # ----------------------------------------------------------------------------- diff --git a/stack/dashboard/base/generate_base.sh b/stack/dashboard/base/generate_base.sh index 587accb919..ac88a49e05 100755 --- a/stack/dashboard/base/generate_base.sh +++ b/stack/dashboard/base/generate_base.sh @@ -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" @@ -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}." @@ -68,7 +67,6 @@ help() { echo "Usage: $0 [OPTIONS]" echo echo " -s, --store [Optional] Set the destination path of package. By default, an output folder will be created." - echo " -v, --version [Optional] The OpenSearch-dashboards Version. By default, ${opensearch_version}" echo " --reference [Optional] wazuh-packages branch or tag" echo " --future [Optional] Build test future package 99.99.0 Used for development purposes." echo " -r, --revision [Optional] Package revision. By default ${revision}" @@ -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}" diff --git a/stack/dashboard/deb/build_package.sh b/stack/dashboard/deb/build_package.sh index c5759d6e00..7adadd1b1e 100755 --- a/stack/dashboard/deb/build_package.sh +++ b/stack/dashboard/deb/build_package.sh @@ -16,9 +16,6 @@ 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() { @@ -26,6 +23,7 @@ clean() { # Clean the files rm -rf ${dockerfile_path}/{*.sh,*.tar.gz,wazuh-*} + rm -rf ${dockerfile_path}/VERSION ${dockerfile_path}/files exit ${exit_code} } @@ -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} \ @@ -94,8 +102,6 @@ help() { echo " --reference [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 [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 @@ -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}" diff --git a/stack/dashboard/deb/debian/rules b/stack/dashboard/deb/debian/rules index 2413e95f53..18bd32a353 100644 --- a/stack/dashboard/deb/debian/rules +++ b/stack/dashboard/deb/debian/rules @@ -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) ./ ;\ groupadd $(GROUP) diff --git a/stack/dashboard/deb/docker/amd64/Dockerfile b/stack/dashboard/deb/docker/amd64/Dockerfile index 77d3684396..ec52ba1f2d 100644 --- a/stack/dashboard/deb/docker/amd64/Dockerfile +++ b/stack/dashboard/deb/docker/amd64/Dockerfile @@ -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 diff --git a/stack/dashboard/rpm/build_package.sh b/stack/dashboard/rpm/build_package.sh index 6cd0cbac60..542b1333a3 100755 --- a/stack/dashboard/rpm/build_package.sh +++ b/stack/dashboard/rpm/build_package.sh @@ -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 @@ -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} } @@ -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}." @@ -93,8 +101,6 @@ help() { echo " --reference [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 [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 @@ -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" diff --git a/stack/dashboard/rpm/builder.sh b/stack/dashboard/rpm/builder.sh index bca723d755..ce2ef0d2f1 100755 --- a/stack/dashboard/rpm/builder.sh +++ b/stack/dashboard/rpm/builder.sh @@ -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 @@ -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 diff --git a/stack/dashboard/rpm/docker/x86_64/Dockerfile b/stack/dashboard/rpm/docker/x86_64/Dockerfile index 169d380032..8df85b7394 100644 --- a/stack/dashboard/rpm/docker/x86_64/Dockerfile +++ b/stack/dashboard/rpm/docker/x86_64/Dockerfile @@ -1,12 +1,69 @@ -FROM centos:7 +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 openssh-clients sudo gnupg \ - yum-utils epel-release redhat-rpm-config rpm-devel \ - zlib zlib-devel rpm-build autoconf automake \ - glibc-devel libtool perl +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 centos:7 + +ARG VERSION +ARG REVISION + +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" + +# Install all the necessary tools to build the packages +RUN yum clean all && yum update -y +RUN yum install -y openssh-clients \ + sudo \ + gnupg \ + yum-utils \ + epel-release \ + redhat-rpm-config \ + rpm-devel \ + zlib \ + zlib-devel \ + rpm-build \ + autoconf \ + automake \ + glibc-devel \ + libtool \ + perl # Add the scripts to build the RPM package ADD builder.sh /usr/local/bin/builder diff --git a/stack/dashboard/rpm/wazuh-dashboard.spec b/stack/dashboard/rpm/wazuh-dashboard.spec index eb737d281b..8b1c7186fb 100644 --- a/stack/dashboard/rpm/wazuh-dashboard.spec +++ b/stack/dashboard/rpm/wazuh-dashboard.spec @@ -43,11 +43,7 @@ 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 /opt/%{DASHBOARD_FILE} ./ ;\ groupadd %{GROUP} useradd -g %{GROUP} %{USER} diff --git a/stack/indexer/deb/builder.sh b/stack/indexer/deb/builder.sh index d5c0c9f947..1bf3e343c3 100755 --- a/stack/indexer/deb/builder.sh +++ b/stack/indexer/deb/builder.sh @@ -15,8 +15,7 @@ target="wazuh-indexer" architecture=$1 revision=$2 future=$3 -base_location=$4 -reference=$5 +reference=$4 directory_base="/usr/share/wazuh-indexer" if [ -z "${revision}" ]; then @@ -62,7 +61,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" diff --git a/stack/indexer/rpm/build_package.sh b/stack/indexer/rpm/build_package.sh index eeedc0bf8b..9fa6d7cefe 100755 --- a/stack/indexer/rpm/build_package.sh +++ b/stack/indexer/rpm/build_package.sh @@ -18,8 +18,6 @@ build_docker="yes" rpm_x86_builder="rpm_indexer_builder_x86" rpm_builder_dockerfile="${current_path}/docker" future="no" -base="s3" -base_path="${current_path}/../base/output" trap ctrl_c INT @@ -28,6 +26,7 @@ clean() { # Clean the files rm -rf ${dockerfile_path}/{*.sh,*.tar.gz,wazuh-*} + rm -rf ${dockerfile_path}/VERSION ${dockerfile_path}/files exit ${exit_code} } @@ -42,26 +41,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}." @@ -95,8 +103,6 @@ help() { echo " --reference [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 [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/indexer/base/output" echo " -h, --help Show this help." echo exit $1 @@ -142,22 +148,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" diff --git a/stack/indexer/rpm/builder.sh b/stack/indexer/rpm/builder.sh index 6aa8111502..38a42662b6 100755 --- a/stack/indexer/rpm/builder.sh +++ b/stack/indexer/rpm/builder.sh @@ -15,8 +15,7 @@ target="wazuh-indexer" architecture=$1 revision=$2 future=$3 -base_location=$4 -reference=$5 +reference=$4 directory_base="/usr/share/wazuh-indexer" if [ -z "${revision}" ]; then @@ -60,7 +59,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 diff --git a/stack/indexer/rpm/docker/x86_64/Dockerfile b/stack/indexer/rpm/docker/x86_64/Dockerfile index 4c0588798c..a6ab16f4d8 100644 --- a/stack/indexer/rpm/docker/x86_64/Dockerfile +++ b/stack/indexer/rpm/docker/x86_64/Dockerfile @@ -1,10 +1,48 @@ +FROM rockylinux:8.5 as builder_base + +ARG FUTURE +ARG REVISION +ARG REFERENCE + +# Install all the necessary tools +RUN yum clean all && yum update -y +RUN yum install -y \ + findutils \ + git \ + java-11-openjdk-devel + +# Add the script +ADD builder_base.sh /usr/local/bin/builder_base +RUN chmod +x /usr/local/bin/builder_base + +ADD files/ /root/stack/indexer/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 rockylinux:8.5 +ARG VERSION +ARG REVISION + +COPY --from=builder_base "/tmp/output/wazuh-indexer-base-$VERSION-$REVISION-linux-x64.tar.xz" "/opt/wazuh-indexer-base-$VERSION-$REVISION-linux-x64.tar.xz" + # Install all the necessary tools to build the packages RUN yum clean all && yum update -y -RUN yum install -y openssh-clients sudo gnupg \ - yum-utils epel-release redhat-rpm-config rpm-devel \ - zlib zlib-devel rpm-build +RUN yum install -y openssh-clients \ + sudo \ + gnupg \ + yum-utils \ + epel-release \ + redhat-rpm-config \ + rpm-devel \ + zlib \ + zlib-devel \ + rpm-build # Add the scripts to build the RPM package ADD builder.sh /usr/local/bin/builder diff --git a/stack/indexer/rpm/wazuh-indexer.spec b/stack/indexer/rpm/wazuh-indexer.spec index 5267a01b4a..199b60ef05 100755 --- a/stack/indexer/rpm/wazuh-indexer.spec +++ b/stack/indexer/rpm/wazuh-indexer.spec @@ -68,12 +68,8 @@ mkdir -p ${RPM_BUILD_ROOT}%{LOG_DIR} mkdir -p ${RPM_BUILD_ROOT}%{LIB_DIR} mkdir -p ${RPM_BUILD_ROOT}%{SYS_DIR} -# Set up required files -if [ "%{_base}" = "s3" ];then - curl -kOL https://packages-dev.wazuh.com/stack/indexer/base/%{INDEXER_FILE} -else - cp /root/output/%{INDEXER_FILE} ./ -fi +cp /opt/%{INDEXER_FILE} ./ ;\ + tar -xf %{INDEXER_FILE} && rm -f %{INDEXER_FILE} chown -R %{USER}:%{GROUP} wazuh-indexer-*/* From 687b704f9cc8e8e483e0e4fe2f37cc525c2026c4 Mon Sep 17 00:00:00 2001 From: c-bordon Date: Fri, 2 Sep 2022 09:13:13 -0300 Subject: [PATCH 3/3] Removed base parameters for dashboard deb build --- stack/dashboard/deb/build_package.sh | 4 ++-- stack/dashboard/deb/builder.sh | 7 +++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/stack/dashboard/deb/build_package.sh b/stack/dashboard/deb/build_package.sh index 7adadd1b1e..515f105dc0 100755 --- a/stack/dashboard/deb/build_package.sh +++ b/stack/dashboard/deb/build_package.sh @@ -63,12 +63,12 @@ build_deb() { if [ "${reference}" ];then docker run -t --rm ${volumes} \ ${container_name} ${architecture} ${revision} \ - ${future} ${base} ${reference} || return 1 + ${future} ${reference} || return 1 else docker run -t --rm ${volumes} \ -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}." diff --git a/stack/dashboard/deb/builder.sh b/stack/dashboard/deb/builder.sh index 50e21521b4..ad0465ec43 100755 --- a/stack/dashboard/deb/builder.sh +++ b/stack/dashboard/deb/builder.sh @@ -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 @@ -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"