From 69d25aa6580c373fcc17bb5e6827c5d514cf677b Mon Sep 17 00:00:00 2001 From: Nicolas Date: Wed, 23 Oct 2024 09:47:10 -0300 Subject: [PATCH 01/30] Add new output and tmp directories to gitignore --- .gitignore | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index cf91a061d892..b8559c25273c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,8 @@ .aws-config.json .signing-config.json .ackrc -/dev-tools/build-packages/*/output +/dev-tools/build-packages/output +/dev-tools/build-packages/tmp /.opensearch /.chromium /package.json.bak @@ -71,4 +72,4 @@ snapshots.js .yarn-local-mirror # Ignore the generated antlr files -/src/plugins/data/public/antlr/opensearch_sql/grammar/.antlr \ No newline at end of file +/src/plugins/data/public/antlr/opensearch_sql/grammar/.antlr From e84068e8c44abda4b3c83f6d58998ed084150190 Mon Sep 17 00:00:00 2001 From: Nicolas Date: Wed, 23 Oct 2024 09:47:51 -0300 Subject: [PATCH 02/30] Add docker to generate base --- .../build-packages/base/Docker/Dockerfile | 35 ++++ dev-tools/build-packages/base/base-builder.sh | 162 ++++++++++++++++++ 2 files changed, 197 insertions(+) create mode 100644 dev-tools/build-packages/base/Docker/Dockerfile create mode 100755 dev-tools/build-packages/base/base-builder.sh diff --git a/dev-tools/build-packages/base/Docker/Dockerfile b/dev-tools/build-packages/base/Docker/Dockerfile new file mode 100644 index 000000000000..6614bda6ce49 --- /dev/null +++ b/dev-tools/build-packages/base/Docker/Dockerfile @@ -0,0 +1,35 @@ +FROM rockylinux:8.5 + +# 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 \ + python3-devel \ + python3-pip \ + jq \ + unzip + +RUN git clone https://github.com/google/brotli.git -b v1.0.9 + +RUN cd brotli && chmod +x ./bootstrap && ./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 scripts to build the RPM package +ADD base-builder.sh /usr/local/bin/builder +ADD plugins /usr/local/bin/plugins +RUN chmod +x /usr/local/bin/builder + +# Set the entrypoint +ENTRYPOINT ["/usr/local/bin/builder"] diff --git a/dev-tools/build-packages/base/base-builder.sh b/dev-tools/build-packages/base/base-builder.sh new file mode 100755 index 000000000000..e54015c0beb9 --- /dev/null +++ b/dev-tools/build-packages/base/base-builder.sh @@ -0,0 +1,162 @@ +#!/bin/bash + +# Wazuh package generator +# Copyright (C) 2022, Wazuh Inc. +# +# This program is a free software; you can redistribute it +# and/or modify it under the terms of the GNU General Public +# License (version 2) as published by the FSF - Free Software +# Foundation. + +set -e + +# Inputs +version="$1" +revision="$2" +architecture="$3" +verbose="$4" + +if [ "$verbose" = "debug" ]; then + set -x +fi + +trap clean INT +trap clean EXIT + +log() { + if [ "$verbose" = "info" ] || [ "$verbose" = "debug" ]; then + echo "$@" + fi +} + +clean() { + exit_code=$? + # Clean the files + rm -rf ${tmp_dir}/* + trap '' EXIT + exit ${exit_code} +} + +# Paths +current_path="$( cd $(dirname $0) ; pwd -P )" + +# Folders +tmp_dir="/tmp" +out_dir="/output" +config_path=$tmp_dir/config + + +# ----------------------------------------------------------------------------- +cd $tmp_dir + +log +log "Extracting packages" +log + +mkdir -p applications +mkdir -p base +packages_list=(app base security) +packages_names=("Wazuh plugins" "Wazuh Dashboard" "Security plugin") + + +for i in "${!packages_list[@]}"; do + package_var="${packages_list[$i]}" + package_name="${packages_names[$i]}" + if [[ "$package_var" == "base" ]]; then + wzd_package_name=$(unzip -l "packages/${package_var}.zip" | awk 'NR==4 {print $4}') + unzip -o -q "packages/${package_var}.zip" -d base + else + unzip -o -q "packages/${package_var}.zip" -d applications + fi +done + +cd base + +log +log "Installing plugins" +log + +tar -zxf $wzd_package_name +directory_name=$(ls -td */ | head -1) +cd $directory_name +plugins=$(ls $tmp_dir/applications)' '$(cat $current_path/plugins) + for plugin in $plugins; do + if [[ $plugin =~ .*\.zip ]]; then + install="file://${tmp_dir}/applications/${plugin}" + else + install=$plugin + fi + log "Installing ${plugin} plugin" + if ! bin/opensearch-dashboards-plugin install $install 2>&1 --allow-root> /dev/null; then + echo "Plugin ${plugin} installation failed" + exit 1 + fi + log "Plugin ${plugin} installed successfully" + log + done + +log +log "Replacing application categories" +log + +category_explore='{id:"explore",label:"Explore",order:100,euiIconType:"search"}' +category_dashboard_management='{id:"management",label:"Index management",order:5e3,euiIconType:"managementApp"}' + +# Replace app category to Reporting app +sed -i -e "s|category:{id:\"opensearch\",label:_i18n.i18n.translate(\"opensearch.reports.categoryName\",{defaultMessage:\"OpenSearch Plugins\"}),order:2e3}|category:${category_explore}|" ./plugins/reportsDashboards/target/public/reportsDashboards.plugin.js + +# Replace app category to Alerting app +sed -i -e "s|category:{id:\"opensearch\",label:\"OpenSearch Plugins\",order:2e3}|category:${category_explore}|" ./plugins/alertingDashboards/target/public/alertingDashboards.plugin.js + +# Replace app category to Maps app +sed -i -e "s|category:{id:\"opensearch\",label:\"OpenSearch Plugins\",order:2e3}|category:${category_explore}|" ./plugins/customImportMapDashboards/target/public/customImportMapDashboards.plugin.js + +# Replace app category to Notifications app +sed -i -e "s|category:DEFAULT_APP_CATEGORIES.management|category:${category_explore}|" ./plugins/notificationsDashboards/target/public/notificationsDashboards.plugin.js + +# Replace app category to Index Management app +sed -i -e "s|category:DEFAULT_APP_CATEGORIES.management|category:${category_dashboard_management}|g" ./plugins/indexManagementDashboards/target/public/indexManagementDashboards.plugin.js + + +log +log "Recreating plugin files" +log + +# Generate compressed files +files_to_recreate=( + ./plugins/reportsDashboards/target/public/reportsDashboards.plugin.js + ./plugins/alertingDashboards/target/public/alertingDashboards.plugin.js + ./plugins/customImportMapDashboards/target/public/customImportMapDashboards.plugin.js + ./plugins/notificationsDashboards/target/public/notificationsDashboards.plugin.js + ./plugins/indexManagementDashboards/target/public/indexManagementDashboards.plugin.js +) + +for value in "${files_to_recreate[@]}" +do + gzip -c "$value" > "$value.gz" + brotli -c "$value" > "$value.br" +done + +log +log "Adding configuration files" +log + +cp -f $config_path/opensearch_dashboards.prod.yml config/opensearch_dashboards.yml +cp -f $config_path/node.options.prod config/node.options + +log +log "Fixing shebangs" +log +# TODO: investigate to remove this if possible +# Fix ambiguous shebangs (necessary for RPM building) +grep -rnwl './node_modules/' -e '#!/usr/bin/env python$' | xargs -I {} sed -i 's/#!\/usr\/bin\/env python/#!\/usr\/bin\/env python3/g' {} +grep -rnwl './node_modules/' -e '#!/usr/bin/python$' | xargs -I {} sed -i 's/#!\/usr\/bin\/python/#!\/usr\/bin\/python3/g' {} + +log +log "Compressing final package" +log + +mkdir -p $out_dir +tar -czf $out_dir/wazuh-dashboard-$version-$revision-linux-$architecture.tar.gz * + +log Done! From c95b83e73cd7922cb5850ff2ff769189965e0539 Mon Sep 17 00:00:00 2001 From: Nicolas Date: Wed, 23 Oct 2024 09:48:28 -0300 Subject: [PATCH 03/30] Reduce steps in rpm and deb build --- dev-tools/build-packages/deb/deb-builder.sh | 106 ++++++++++++ dev-tools/build-packages/rpm/rpm-builder.sh | 170 ++++++++++++++++++++ 2 files changed, 276 insertions(+) create mode 100755 dev-tools/build-packages/deb/deb-builder.sh create mode 100644 dev-tools/build-packages/rpm/rpm-builder.sh diff --git a/dev-tools/build-packages/deb/deb-builder.sh b/dev-tools/build-packages/deb/deb-builder.sh new file mode 100755 index 000000000000..1bcaa53f0773 --- /dev/null +++ b/dev-tools/build-packages/deb/deb-builder.sh @@ -0,0 +1,106 @@ +#!/bin/bash + +# Wazuh package builder +# Copyright (C) 2021, Wazuh Inc. +# +# This program is a free software; you can redistribute it +# and/or modify it under the terms of the GNU General Public +# License (version 2) as published by the FSF - Free Software +# Foundation. + +set -e + +# Script parameters to build the package +target="wazuh-dashboard" +version=$1 +revision=$2 +architecture=$3 +commit_sha=$4 +is_production=$5 +verbose=$6 + +directory_base="/usr/share/wazuh-dashboard" + +# Paths +current_path="$( cd $(dirname $0) ; pwd -P )" + +# Folders +tmp_dir="/tmp" +out_dir="/output" +config_path=$tmp_dir/config + +if [ "$verbose" = "debug" ]; then + set -x +fi +trap clean INT +trap clean EXIT + +log() { + if [ "$verbose" = "info" ] || [ "$verbose" = "debug" ]; then + echo "$@" + fi +} + +clean() { + exit_code=$? + # Clean the files + rm -rf ${tmp_dir}/* + trap '' EXIT + exit ${exit_code} +} + +mkdir -p ${tmp_dir}/wazuh-dashboard-base +cd ${tmp_dir}/wazuh-dashboard-base +log "Extracting base tar.gz..." +tar -zxf ${out_dir}/wazuh-dashboard-$version-$revision-linux-$architecture.tar.gz +log "Preparing the package..." +jq '.wazuh.revision="'${revision}'"' package.json > pkgtmp.json && mv pkgtmp.json package.json +cp $config_path/* . +echo ${version} > VERSION +cd .. +tar -czf wazuh-dashboard.tar.gz wazuh-dashboard-base + +log "Setting up parameters" +if [ "${architecture}" = "x64" ]; then + architecture="amd64" +fi +# Build directories +build_dir=/build +pkg_name="${target}-${version}" +pkg_path="${build_dir}/${target}" +source_dir="${pkg_path}/${pkg_name}" +deb_file="${target}_${version}-${revision}_${architecture}.deb" +final_name="${target}_${version}-${revision}_${architecture}_${commit_sha}.deb" + +mkdir -p ${source_dir}/debian + +# Including spec file +cp -r /usr/local/bin/debian/* ${source_dir}/debian/ + +# Generating directory structure to build the .deb package +cd ${build_dir}/${target} && tar -czf ${pkg_name}.orig.tar.gz "${pkg_name}" + +# Configure the package with the different parameters +sed -i "s:VERSION:${version}:g" ${source_dir}/debian/changelog +sed -i "s:RELEASE:${revision}:g" ${source_dir}/debian/changelog +sed -i "s:export INSTALLATION_DIR=.*:export INSTALLATION_DIR=${directory_base}:g" ${source_dir}/debian/rules + +# Installing build dependencies +cd ${source_dir} +mk-build-deps -ir -t "apt-get -o Debug::pkgProblemResolver=yes -y" + +log "Building the package..." +# Build package +debuild --no-lintian -b -uc -us \ + -eINSTALLATION_DIR="${directory_base}" \ + -eVERSION="${version}" \ + -eREVISION="${revision}" + +cd ${pkg_path} && sha512sum ${deb_file} >/${out_dir}/${deb_file}.sha512 + +if [ "${is_production}" = "no" ]; then + mv ${pkg_path}/${deb_file} /${out_dir}/${final_name} + mv /${out_dir}/${deb_file}.sha512 /${out_dir}/${final_name}.sha512 +else + mv ${pkg_path}/${deb_file} /${out_dir}/ +fi diff --git a/dev-tools/build-packages/rpm/rpm-builder.sh b/dev-tools/build-packages/rpm/rpm-builder.sh new file mode 100644 index 000000000000..0865decf5e5b --- /dev/null +++ b/dev-tools/build-packages/rpm/rpm-builder.sh @@ -0,0 +1,170 @@ +#!/bin/bash + +# Wazuh package builder +# Copyright (C) 2021, Wazuh Inc. +# +# This program is a free software; you can redistribute it +# and/or modify it under the terms of the GNU General Public +# License (version 2) as published by the FSF - Free Software +# Foundation. + +set -e + +# Script parameters to build the package +target="wazuh-dashboard" +version=$1 +revision=$2 +architecture=$3 +commit_sha=$4 +is_production=$5 +verbose=$6 + +# Paths +current_path="$( cd $(dirname $0) ; pwd -P )" + +# Folders +tmp_dir="/tmp" +out_dir="/output" +config_path=$tmp_dir/config + +if [ "$verbose" = "debug" ]; then + set -x +fi + +trap clean INT +trap clean EXIT + +log() { + if [ "$verbose" = "info" ] || [ "$verbose" = "debug" ]; then + echo "$@" + fi +} + +clean() { + exit_code=$? + # Clean the files + rm -rf ${tmp_dir}/* + trap '' EXIT + exit ${exit_code} +} + +mkdir -p ${tmp_dir}/wazuh-dashboard-base +cd ${tmp_dir}/wazuh-dashboard-base +log "Extracting base tar.gz..." +tar -zxf ${out_dir}/wazuh-dashboard-$version-$revision-linux-$architecture.tar.gz +log "Preparing the package..." +jq '.wazuh.revision="'${revision}'"' package.json > pkgtmp.json && mv pkgtmp.json package.json +mkdir -p etc/services +cp $config_path/* etc/services +echo ${version} > VERSION +cd .. +tar -czf wazuh-dashboard.tar.gz wazuh-dashboard-base + +log "Setting up parameters" + +if [ "${architecture}" = "x64" ]; then + architecture="x86_64" +fi + +build_dir=/build +rpm_build_dir=${build_dir}/rpmbuild +directory_base="/usr/share/wazuh-dashboard" + + +pkg_name=${target}-${version} +pkg_path="${rpm_build_dir}/RPMS/${architecture}" +file_name="${target}-${version}-${revision}" +rpm_file="${file_name}.${architecture}.rpm" + +if [ "$is_production" = "no" ]; then + final_name="${target}_${version}-${revision}_${architecture}_${commit_sha}.rpm" +else + final_name="${target}_${version}-${revision}_${architecture}.rpm" +fi + +mkdir -p ${rpm_build_dir}/{BUILD,BUILDROOT,RPMS,SOURCES,SPECS,SRPMS} + +mkdir ${build_dir}/${pkg_name} + +# Including spec file +cp /usr/local/bin/${target}.spec ${rpm_build_dir}/SPECS/${pkg_name}.spec +cd ${build_dir} && tar czf "${rpm_build_dir}/SOURCES/${pkg_name}.tar.gz" "${pkg_name}" + +log "Building RPM..." +/usr/bin/rpmbuild -v \ + --define "_topdir ${rpm_build_dir}" \ + --define "_version ${version}" \ + --define "_release ${revision}" \ + --define "_localstatedir ${directory_base}" \ + --target ${architecture} \ + -ba ${rpm_build_dir}/SPECS/${pkg_name}.spec + +cd ${pkg_path} && sha512sum ${rpm_file} >/${out_dir}/${rpm_file}.sha512 + +find ${pkg_path}/ -maxdepth 3 -type f -name "${file_name}*" -exec mv {} /${out_dir}/ \; +if [ "${is_production}" = "no" ]; then + mv /${out_dir}/${rpm_file} /${out_dir}/${final_name} + mv /${out_dir}/${rpm_file}.sha512 /${out_dir}/${final_name}.sha512 +fi + + + +asdf(){ + rm wazuh-dashboard.tar.gz + mv $directory_name wazuh-dashboard-base + jq '.wazuh.revision="'${revision}'"' wazuh-dashboard-base/package.json > pkgtmp.json && mv pkgtmp.json wazuh-dashboard-base/package.json + mkdir -p wazuh-dashboard-base/etc/services + cp $config_path/* wazuh-dashboard-base/etc/services + echo ${version} >wazuh-dashboard-base/VERSION + + + + +# Build directories + +build_dir=/build +rpm_build_dir=${build_dir}/rpmbuild +directory_base="/usr/share/wazuh-dashboard" + + +pkg_name=${target}-${version} +pkg_path="${rpm_build_dir}/RPMS/${architecture}" +file_name="${target}-${version}-${revision}" +rpm_file="${file_name}.${architecture}.rpm" + +if [ "$is_production" = "no" ]; then + final_name="${target}_${version}-${revision}_${architecture}_${commit_sha}.rpm" +else + final_name="${target}_${version}-${revision}_${architecture}.rpm" +fi + +mkdir -p ${rpm_build_dir}/{BUILD,BUILDROOT,RPMS,SOURCES,SPECS,SRPMS} + +# Prepare the sources directory to build the source tar.gz +mkdir ${build_dir}/${pkg_name} + +# Including spec file +cp /usr/local/bin/${target}.spec ${rpm_build_dir}/SPECS/${pkg_name}.spec + +# Generating source tar.gz +cd ${build_dir} && tar czf "${rpm_build_dir}/SOURCES/${pkg_name}.tar.gz" "${pkg_name}" + +ls -l ${rpm_build_dir}/SOURCES + +# Building RPM +/usr/bin/rpmbuild -v \ + --define "_topdir ${rpm_build_dir}" \ + --define "_version ${version}" \ + --define "_release ${revision}" \ + --define "_localstatedir ${directory_base}" \ + --target ${architecture} \ + -ba ${rpm_build_dir}/SPECS/${pkg_name}.spec + +cd ${pkg_path} && sha512sum ${rpm_file} >/tmp/${rpm_file}.sha512 + +find ${pkg_path}/ -maxdepth 3 -type f -name "${file_name}*" -exec mv {} /tmp/ \; +if [ "${is_production}" = "no" ]; then + mv /tmp/${rpm_file} /tmp/${final_name} + mv /tmp/${rpm_file}.sha512 /tmp/${final_name}.sha512 +fi +} From 56c599619e3c9ec8a8bc9014d62ac6c20aa0f2ba Mon Sep 17 00:00:00 2001 From: Nicolas Date: Wed, 23 Oct 2024 09:48:47 -0300 Subject: [PATCH 04/30] Apply required changes in rpm building --- .../build-packages/rpm/Docker/Dockerfile | 22 +++++++++++++++++++ .../build-packages/rpm/wazuh-dashboard.spec | 2 +- 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 dev-tools/build-packages/rpm/Docker/Dockerfile diff --git a/dev-tools/build-packages/rpm/Docker/Dockerfile b/dev-tools/build-packages/rpm/Docker/Dockerfile new file mode 100644 index 000000000000..1c719166a7de --- /dev/null +++ b/dev-tools/build-packages/rpm/Docker/Dockerfile @@ -0,0 +1,22 @@ +FROM rockylinux:8.5 + +# 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 jq + +#RUN yum install -y --nobest https://repo.ius.io/ius-release-el7.rpm + +RUN yum update -y && yum install -y python3 + +RUN ln -fs /usr/bin/python3.6 /usr/bin/python + +# Add the scripts to build the RPM package +ADD rpm-builder.sh /usr/local/bin/builder +ADD wazuh-dashboard.spec /usr/local/bin/wazuh-dashboard.spec +RUN chmod +x /usr/local/bin/builder + +# Set the entrypoint +ENTRYPOINT ["/usr/local/bin/builder"] diff --git a/dev-tools/build-packages/rpm/wazuh-dashboard.spec b/dev-tools/build-packages/rpm/wazuh-dashboard.spec index 758e6ef7aa62..3addff105bde 100644 --- a/dev-tools/build-packages/rpm/wazuh-dashboard.spec +++ b/dev-tools/build-packages/rpm/wazuh-dashboard.spec @@ -44,7 +44,7 @@ Wazuh dashboard is a user interface and visualization tool for security-related %prep -cp /opt/%{DASHBOARD_FILE} ./ +cp /tmp/%{DASHBOARD_FILE} ./ groupadd %{GROUP} useradd -g %{GROUP} %{USER} From 11e1d76def4a35f8b26c0ffc2f14fb5a88426a47 Mon Sep 17 00:00:00 2001 From: Nicolas Date: Wed, 23 Oct 2024 09:49:03 -0300 Subject: [PATCH 05/30] Apply required changes in deb building --- dev-tools/build-packages/deb/Docker/Dockerfile | 17 +++++++++++++++++ dev-tools/build-packages/deb/debian/rules | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 dev-tools/build-packages/deb/Docker/Dockerfile diff --git a/dev-tools/build-packages/deb/Docker/Dockerfile b/dev-tools/build-packages/deb/Docker/Dockerfile new file mode 100644 index 000000000000..ed88a214d5b1 --- /dev/null +++ b/dev-tools/build-packages/deb/Docker/Dockerfile @@ -0,0 +1,17 @@ +FROM debian:10 + +ENV DEBIAN_FRONTEND=noninteractive + +# Installing necessary packages +RUN apt-get update && apt-get install -y --allow-change-held-packages apt-utils && \ + apt-get install -y --allow-change-held-packages \ + curl sudo wget expect gnupg build-essential \ + devscripts equivs selinux-basics procps gawk jq + +# Add the script to build the Debian package +ADD deb-builder.sh /usr/local/bin/builder +ADD debian /usr/local/bin/debian +RUN chmod +x /usr/local/bin/builder + +# Set the entrypoint +ENTRYPOINT ["/usr/local/bin/builder"] diff --git a/dev-tools/build-packages/deb/debian/rules b/dev-tools/build-packages/deb/debian/rules index 7fe98ddcc597..ac2087b35ef0 100644 --- a/dev-tools/build-packages/deb/debian/rules +++ b/dev-tools/build-packages/deb/debian/rules @@ -52,7 +52,7 @@ override_dh_auto_install: # ----------------------------------------------------------------------------- override_dh_install: - cp /opt/$(DASHBOARD_FILE) ./ + cp /tmp/$(DASHBOARD_FILE) ./ groupadd $(GROUP) useradd -g $(GROUP) $(USER) From b203cd01346469b6a51a5337d256acf03b789eb7 Mon Sep 17 00:00:00 2001 From: Nicolas Date: Wed, 23 Oct 2024 09:49:20 -0300 Subject: [PATCH 06/30] Change main package building script --- dev-tools/build-packages/build-packages.sh | 163 ++++++++++++++++----- 1 file changed, 130 insertions(+), 33 deletions(-) diff --git a/dev-tools/build-packages/build-packages.sh b/dev-tools/build-packages/build-packages.sh index bf2d93f22dc3..f7705da53de4 100755 --- a/dev-tools/build-packages/build-packages.sh +++ b/dev-tools/build-packages/build-packages.sh @@ -1,4 +1,5 @@ #!/bin/bash +set -e app="" base="" @@ -9,59 +10,136 @@ all_platforms="no" deb="no" rpm="no" tar="no" -output="$( cd $(dirname $0) ; pwd -P )/output" -production="" +architecture="x64" +production="no" +commit_sha=$(git rev-parse --short HEAD) current_path="$( cd $(dirname $0) ; pwd -P )" +output_dir="${current_path}/output" +tmp_dir="${current_path}/tmp" +config_dir="${current_path}/../../config" +package_config_dir="${current_path}/config" +verbose="info" -build_tar() { - echo "Building tar package..." - cd ./base - bash ./generate_base.sh -a $app -b $base -s $security -v $version -r $revision +trap clean INT +trap clean EXIT - name_package_tar=$(ls ./output) +log() { + if [ "$verbose" = "info" ] || [ "$verbose" = "debug" ]; then + echo "$@" + fi +} - echo "Moving tar package to $output" - mv $current_path/base/output/$name_package_tar $output/$name_package_tar - cd ../ +clean() { + exit_code=$? + echo + echo "Cleaning temporary files..." + echo + # Clean the files + rm -rf ${tmp_dir} + rm -f ${current_path}/base/Docker/base-builder.sh + rm -f ${current_path}/base/Docker/plugins + rm -f ${current_path}/rpm/Docker/rpm-builder.sh + rm -f ${current_path}/rpm/Docker/wazuh-dashboard.spec + rm -f ${current_path}/deb/Docker/deb-builder.sh + rm -rf ${current_path}/deb/Docker/debian + trap '' EXIT + exit ${exit_code} } -build_deb() { - echo "Building deb package..." - name_package_tar=$(find $output -name "*.tar.gz") - cd ./deb - bash ./launcher.sh -v $version -r $revision -p file://$name_package_tar $production - name_package_tar=$(ls ./output) - echo "Moving deb package to $output/deb" - mv $current_path/deb/output $output/deb - cd ../ +ctrl_c() { + clean 1 +} + +get_packages(){ + packages_list=(app base security) + packages_names=("Wazuh plugins" "Wazuh Dashboard" "Security plugin") + valid_url='(https?|ftp|file)://[-[:alnum:]\+&@#/%?=~_|!:,.;]*[-[:alnum:]\+&@#/%=~_|]' + mkdir -p ${tmp_dir} + cd ${tmp_dir} + mkdir -p packages + for i in "${!packages_list[@]}"; do + package_var="${packages_list[$i]}" + package_name="${packages_names[$i]}" + package_url="${!package_var}" + + log + log "Downloading ${package_name}" + + if [[ $package_url =~ $valid_url ]]; then + if ! curl --output "packages/${package_var}.zip" --silent --fail "${package_url}"; then + echo "The given URL or Path to the ${package_name} is not working: ${package_url}" + clean 1 + fi + else + echo "The given URL or Path to the ${package_name} is not valid: ${package_url}" + clean 1 + fi + log "Done!" + log + done + cd .. +} + +build_tar() { + log + log "Building base package..." + log + mkdir -p ${output_dir} + cp -r ${config_dir} ${tmp_dir} + cd ./base + dockerfile_path="${current_path}/base/Docker" + container_name="dashboard-base-builder" + cp ./base-builder.sh ${dockerfile_path} + cp ./plugins ${dockerfile_path} + docker build -t ${container_name} ${dockerfile_path} || return 1 + docker run -t --rm -v ${tmp_dir}/:/tmp:Z -v ${output_dir}/:/output:Z\ + ${container_name} ${version} ${revision} ${architecture} ${verbose}|| return 1 + cd .. } build_rpm() { - echo "Building rpm package..." - name_package_tar=$(find $output -name "*.tar.gz") + log "Building rpm package..." cd ./rpm - bash ./launcher.sh -v $version -r $revision -p file://$name_package_tar $production - echo "Moving rpm package to $output/rpm" - mv $current_path/rpm/output $output/rpm + dockerfile_path="${current_path}/rpm/Docker" + container_name="dashboard-rpm-builder" + cp -r ${package_config_dir} ${tmp_dir} + cp ./rpm-builder.sh ${dockerfile_path} + cp ./wazuh-dashboard.spec ${dockerfile_path} + docker build -t ${container_name} ${dockerfile_path} || return 1 + docker run -t --rm -v ${tmp_dir}/:/tmp:Z -v ${output_dir}/:/output:Z\ + ${container_name} ${version} ${revision} ${architecture}\ + ${commit_sha} ${production} ${verbose}|| return 1 cd ../ } -build() { - name_package_tar="wazuh-dashboard-$version-$revision-linux-x64.tar.gz" +build_deb() { + log "Building deb package..." + cd ./deb + dockerfile_path="${current_path}/deb/Docker" + container_name="dashboard-deb-builder" + cp -r ${package_config_dir} ${tmp_dir} + cp ./deb-builder.sh ${dockerfile_path} + cp -r ./debian ${dockerfile_path} + docker build -t ${container_name} ${dockerfile_path} || return 1 + docker run -t --rm -v ${tmp_dir}/:/tmp:Z -v ${output_dir}/:/output:Z \ + ${container_name} ${version} ${revision} ${architecture}\ + ${commit_sha} ${production} ${verbose}|| return 1 + cd .. +} - if [ ! -d "$output" ]; then - mkdir $output - fi + + +build(){ + log "Building package..." if [ "$all_platforms" == "yes" ]; then deb="yes" rpm="yes" tar="yes" fi - + get_packages build_tar - cd $current_path if [ $deb == "yes" ]; then echo "Building deb package..." @@ -91,8 +169,10 @@ help() { echo " --rpm Build for rpm." echo " --tar Build for tar." echo " --production [Optional] The naming of the package will be ready for production." + echo " --arm [Optional] Build for arm64 instead of x64." + echo " --debug [Optional] Debug mode." + echo " --silent [Optional] Silent mode. Will not work if --debug is set." echo " -r, --revision [Optional] Set the revision of this build. By default, it is set to 1." - echo " -o, --output [Optional] Set the destination path of package. By default, an output folder will be created." echo " -h, --help Show this help." echo exit $1 @@ -145,7 +225,7 @@ main() { fi ;; "--production") - production="--production" + production="yes" shift 1 ;; "--all-platforms") @@ -164,6 +244,19 @@ main() { tar="yes" shift 1 ;; + "--arm") + architecture="arm64" + shift 1 + ;; + "--silent") + verbose="silent" + shift 1 + ;; + "--debug") + verbose="debug" + shift 1 + ;; + "-o" | "--output") if [ -n "${2}" ]; then output="${2}" @@ -188,6 +281,10 @@ main() { help 1 fi + if [ "$verbose" = "debug" ]; then + set -x + fi + build || exit 1 exit 0 From 71644754d8759c2b7c8f22b1123444cd916f18c9 Mon Sep 17 00:00:00 2001 From: Nicolas Date: Wed, 23 Oct 2024 09:49:30 -0300 Subject: [PATCH 07/30] Change workflow to build packages --- .../build_wazuh_dashboard_with_plugins.yml | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build_wazuh_dashboard_with_plugins.yml b/.github/workflows/build_wazuh_dashboard_with_plugins.yml index dec43ac031f6..cece2b91f967 100644 --- a/.github/workflows/build_wazuh_dashboard_with_plugins.yml +++ b/.github/workflows/build_wazuh_dashboard_with_plugins.yml @@ -19,6 +19,8 @@ on: options: - amd64 - x86_64 + - aarch64 + - arm64 default: amd64 revision: type: string @@ -91,14 +93,22 @@ jobs: steps: - name: Validate inputs run: | - if [ "${{ inputs.architecture }}" = "amd64" ] && [ "${{ inputs.system }}" = "rpm" ]; then + + if { [ "${{ inputs.architecture }}" = "amd64" ] || [ "${{ inputs.architecture }}" = "arm64" ]; } && [ "${{ inputs.system }}" = "rpm" ]; then echo "Invalid combination of architecture and system" exit 1 fi - if [ "${{ inputs.architecture }}" = "x86_64" ] && [ "${{ inputs.system }}" = "deb" ]; then + if {[ "${{ inputs.architecture }}" = "x86_64" ] || [ "${{ inputs.architecture }}" = "aarch64" ]}&& [ "${{ inputs.system }}" = "deb" ]; then echo "Invalid combination of architecture and system" exit 1 fi + - name: Setup variables + run: | + if {[ "${{ inputs.architecture }}" = "x86_64" ] || [ "${{ inputs.architecture }}" = "amd64" ]}; then + echo ARCH="x64" >> $GITHUB_ENV + else + echo ARCH="arm64" >> $GITHUB_ENV + fi build-base: needs: [validate-inputs] @@ -123,7 +133,7 @@ jobs: build-and-test-package: needs: [build-main-plugins, build-base, build-security-plugin] - runs-on: ubuntu-latest + runs-on: ${{ (inputs.architecture == 'arm64' || inputs.architecture == 'aarch64') && 'wz-linux-arm64' || 'ubuntu-22.04' }} name: Generate packages steps: - name: Checkout code @@ -144,6 +154,7 @@ jobs: if [ "${{ inputs.is_stage }}" = "true" ]; then echo "PRODUCTION=--production" >> $GITHUB_ENV fi + if - name: Setup packages names run: | @@ -197,6 +208,7 @@ jobs: -a file://${{env.CURRENT_DIR}}/artifacts/wazuh-package.zip \ -s file://${{env.CURRENT_DIR}}/artifacts/security-package.zip \ -b file://${{env.CURRENT_DIR}}/artifacts/dashboard-package.zip \ + ${{ inputs.architecture == 'aarch64' || inputs.architecture == 'arm64' && '--arm' || '' }} \ --${{ inputs.system }} ${{ env.PRODUCTION }} - name: Test package From d68bbcd01120a8122537ebfe49b0d5dc3a812dd7 Mon Sep 17 00:00:00 2001 From: Nicolas Date: Wed, 23 Oct 2024 09:50:13 -0300 Subject: [PATCH 08/30] Remove unnecessary files --- .../build-packages/base/generate_base.sh | 292 ------------------ dev-tools/build-packages/deb/builder.sh | 60 ---- .../deb/docker/amd64/Dockerfile | 16 - dev-tools/build-packages/deb/launcher.sh | 204 ------------ dev-tools/build-packages/rpm/builder.sh | 57 ---- .../rpm/docker/x86_64/Dockerfile | 21 -- dev-tools/build-packages/rpm/launcher.sh | 207 ------------- 7 files changed, 857 deletions(-) delete mode 100755 dev-tools/build-packages/base/generate_base.sh delete mode 100755 dev-tools/build-packages/deb/builder.sh delete mode 100644 dev-tools/build-packages/deb/docker/amd64/Dockerfile delete mode 100755 dev-tools/build-packages/deb/launcher.sh delete mode 100755 dev-tools/build-packages/rpm/builder.sh delete mode 100644 dev-tools/build-packages/rpm/docker/x86_64/Dockerfile delete mode 100755 dev-tools/build-packages/rpm/launcher.sh diff --git a/dev-tools/build-packages/base/generate_base.sh b/dev-tools/build-packages/base/generate_base.sh deleted file mode 100755 index 6b45e7d35cff..000000000000 --- a/dev-tools/build-packages/base/generate_base.sh +++ /dev/null @@ -1,292 +0,0 @@ -#!/bin/bash - -# Wazuh package generator -# Copyright (C) 2022, Wazuh Inc. -# -# This program is a free software; you can redistribute it -# and/or modify it under the terms of the GNU General Public -# License (version 2) as published by the FSF - Free Software -# Foundation. - -set -e - -# Inputs -app="" -base="" -revision="1" -security="" -version="" - -# Paths -current_path="$( cd $(dirname $0) ; pwd -P )" -config_path=$(realpath $current_path/../../../config) - -# Folders -out_dir="${current_path}/output" -tmp_dir="${current_path}/tmp" - -trap ctrl_c INT - -clean() { - exit_code=$1 - echo - echo "Cleaning temporary files..." - echo - # Clean the files - rm -r $tmp_dir - - if [ $exit_code != 0 ]; then - rm $out_dir/*.tar.gz - rmdir $out_dir - fi - - exit ${exit_code} -} - -ctrl_c() { - clean 1 -} - -# ----------------------------------------------------------------------------- - -build() { - # Validate and download files to build the package - valid_url='(https?|ftp|file)://[-[:alnum:]\+&@#/%?=~_|!:,.;]*[-[:alnum:]\+&@#/%=~_|]' - echo - echo "Downloading plugins..." - echo - mkdir -p $tmp_dir - cd $tmp_dir - mkdir -p applications - mkdir -p dashboards - if [[ $app =~ $valid_url ]]; then - if ! curl --output applications/app.zip --silent --fail "${app}"; then - echo "The given URL or Path to the Wazuh Apps is not working: ${app}" - clean 1 - else - echo "Extracting applications from app.zip" - unzip -q applications/app.zip -d applications - rm applications/app.zip - fi - else - echo "The given URL or Path to the Wazuh App is not valid: ${app}" - clean 1 - fi - - echo - echo "Downloading dashboards..." - echo - if [[ $base =~ $valid_url ]]; then - if [[ $base =~ .*\.zip ]]; then - if ! curl --output wazuh-dashboard.zip --silent --fail "${base}"; then - echo "The given URL or Path to the Wazuh Dashboard base is not working: ${base}" - clean 1 - else - echo "Extracting Wazuh Dashboard base" - unzip -q wazuh-dashboard.zip -d ./dashboards/ - rm wazuh-dashboard.zip - mv ./dashboards/$(ls ./dashboards) wazuh-dashboard.tar.gz - fi - else - if ! curl --output wazuh-dashboard.tar.gz --silent --fail "${base}"; then - echo "The given URL or Path to the Wazuh Dashboard base is not working: ${base}" - clean 1 - fi - fi - else - echo "The given URL or Path to the Wazuh Dashboard base is not valid: ${base}" - clean 1 - fi - - echo - echo "Downloading security plugin..." - echo - - if [[ $security =~ $valid_url ]]; then - if ! curl --output applications/security.zip --silent --fail "${security}"; then - echo "The given URL or Path to the Wazuh Security Plugin is not working: ${security}" - clean 1 - else - echo "Extracting Security application" - unzip -q applications/security.zip -d applications - rm applications/security.zip - fi - else - echo "The given URL or Path to the Wazuh Security Plugin is not valid: ${security}" - clean 1 - fi - - tar -zxf wazuh-dashboard.tar.gz - directory_name=$(ls -td */ | head -1) - working_dir="wazuh-dashboard-$version-$revision-linux-x64" - mv $directory_name $working_dir - cd $working_dir - - echo - echo Building the package... - echo - - # Install Wazuh apps and Security app - - plugins=$(ls $tmp_dir/applications)' '$(cat $current_path/plugins) - for plugin in $plugins; do - if [[ $plugin =~ .*\.zip ]]; then - install='file:../applications/'$plugin - else - install=$plugin - fi - echo "Installing ${plugin%.*} plugin" - if ! bin/opensearch-dashboards-plugin install $install 2>&1 > /dev/null; then - echo "Plugin installation failed" - clean 1 - fi - done - - echo - echo Finished installing plugins - echo - - # Move installed plugins from categories after generating the package - category_explore='{id:"explore",label:"Explore",order:100,euiIconType:"search"}' - category_dashboard_management='{id:"management",label:"Indexer management",order:5e3,euiIconType:"managementApp"}' - - # Replace app category to Reporting app - sed -i -e "s|category:{id:\"opensearch\",label:_i18n.i18n.translate(\"opensearch.reports.categoryName\",{defaultMessage:\"OpenSearch Plugins\"}),order:2e3}|category:${category_explore}|" ./plugins/reportsDashboards/target/public/reportsDashboards.plugin.js - - # Replace app category to Alerting app - sed -i -e "s|category:{id:\"opensearch\",label:\"OpenSearch Plugins\",order:2e3}|category:${category_explore}|" ./plugins/alertingDashboards/target/public/alertingDashboards.plugin.js - - # Replace app category to Maps app - sed -i -e "s|category:{id:\"opensearch\",label:\"OpenSearch Plugins\",order:2e3}|category:${category_explore}|" ./plugins/customImportMapDashboards/target/public/customImportMapDashboards.plugin.js - - # Replace app category to Notifications app - sed -i -e "s|category:DEFAULT_APP_CATEGORIES.management|category:${category_explore}|" ./plugins/notificationsDashboards/target/public/notificationsDashboards.plugin.js - - # Replace app category to Indexer Management app - sed -i -e "s|category:DEFAULT_APP_CATEGORIES.management|category:${category_dashboard_management}|g" ./plugins/indexManagementDashboards/target/public/indexManagementDashboards.plugin.js - - # Generate compressed files - files_to_recreate=( - ./plugins/reportsDashboards/target/public/reportsDashboards.plugin.js - ./plugins/alertingDashboards/target/public/alertingDashboards.plugin.js - ./plugins/customImportMapDashboards/target/public/customImportMapDashboards.plugin.js - ./plugins/notificationsDashboards/target/public/notificationsDashboards.plugin.js - ./plugins/indexManagementDashboards/target/public/indexManagementDashboards.plugin.js - ) - - for value in "${files_to_recreate[@]}" - do - gzip -c "$value" > "$value.gz" - brotli -c "$value" > "$value.br" - done - - # Enable the default configuration (renaming) - cp $config_path/opensearch_dashboards.prod.yml config/opensearch_dashboards.yml - cp $config_path/node.options.prod config/node.options - - # TODO: investigate to remove this if possible - # Fix ambiguous shebangs (necessary for RPM building) - grep -rnwl './node_modules/' -e '#!/usr/bin/env python$' | xargs -I {} sed -i 's/#!\/usr\/bin\/env python/#!\/usr\/bin\/env python3/g' {} - grep -rnwl './node_modules/' -e '#!/usr/bin/python$' | xargs -I {} sed -i 's/#!\/usr\/bin\/python/#!\/usr\/bin\/python3/g' {} - - # Compress - echo - echo Compressing the package... - echo - cd .. - if [ ! -d "$out_dir" ]; then - mkdir -p $out_dir - fi - tar -czf $out_dir/$working_dir.tar.gz $working_dir - - echo - echo DONE! - echo - clean 0 -} - -# ----------------------------------------------------------------------------- - -help() { - echo - echo "Usage: $0 [OPTIONS]" - echo " -a, --app Set the location of the .zip file containing the Wazuh plugin." - echo " -b, --base Set the location of the .tar.gz file containing the base wazuh-dashboard build." - echo " -s, --security Set the location of the .zip file containing the wazuh-security-dashboards-plugin." - echo " -v, --version Set the version of this build." - echo " -r, --revision [Optional] Set the revision of this build. By default, it is set to 1." - echo " -o, --output [Optional] Set the destination path of package. By default, an output folder will be created." - echo " -h, --help Show this help." - echo - exit $1 -} - -# ----------------------------------------------------------------------------- - -main() { - while [ -n "${1}" ]; do - case "${1}" in - "-h" | "--help") - help 0 - ;; - "-a" | "--app") - if [ -n "$2" ]; then - app="$2" - shift 2 - else - help 1 - fi - ;; - "-s" | "--security") - if [ -n "${2}" ]; then - security="${2}" - shift 2 - else - help 0 - fi - ;; - "-b" | "--base") - if [ -n "${2}" ]; then - base="${2}" - shift 2 - else - help 0 - fi - ;; - "-v" | "--version") - if [ -n "${2}" ]; then - version="${2}" - shift 2 - else - help 0 - fi - ;; - "-r" | "--revision") - if [ -n "${2}" ]; then - revision="${2}" - shift 2 - fi - ;; - "-o" | "--output") - if [ -n "${2}" ]; then - output="${2}" - shift 2 - fi - ;; - *) - - help 1 - ;; - esac - done - - if [ -z "$app" ] | [ -z "$base" ] | [ -z "$security" ] | [ -z "$version" ]; then - help 1 - fi - - build || exit 1 - - exit 0 -} - -main "$@" diff --git a/dev-tools/build-packages/deb/builder.sh b/dev-tools/build-packages/deb/builder.sh deleted file mode 100755 index 925997dd4b12..000000000000 --- a/dev-tools/build-packages/deb/builder.sh +++ /dev/null @@ -1,60 +0,0 @@ -#!/bin/bash - -# Wazuh package builder -# Copyright (C) 2021, Wazuh Inc. -# -# This program is a free software; you can redistribute it -# and/or modify it under the terms of the GNU General Public -# License (version 2) as published by the FSF - Free Software -# Foundation. - -set -e - -# Script parameters to build the package -target="wazuh-dashboard" -architecture=$1 -revision=$2 -version=$3 -commit_sha=$4 -is_production=$5 -directory_base="/usr/share/wazuh-dashboard" - -# Build directories -build_dir=/build -pkg_name="${target}-${version}" -pkg_path="${build_dir}/${target}" -source_dir="${pkg_path}/${pkg_name}" -deb_file="${target}_${version}-${revision}_${architecture}.deb" -final_name="${target}_${version}-${revision}_${architecture}_${commit_sha}.deb" - -mkdir -p ${source_dir}/debian - -# Including spec file -cp -r /root/build-packages/deb/debian/* ${source_dir}/debian/ - -# Generating directory structure to build the .deb package -cd ${build_dir}/${target} && tar -czf ${pkg_name}.orig.tar.gz "${pkg_name}" - -# Configure the package with the different parameters -sed -i "s:VERSION:${version}:g" ${source_dir}/debian/changelog -sed -i "s:RELEASE:${revision}:g" ${source_dir}/debian/changelog -sed -i "s:export INSTALLATION_DIR=.*:export INSTALLATION_DIR=${directory_base}:g" ${source_dir}/debian/rules - -# Installing build dependencies -cd ${source_dir} -mk-build-deps -ir -t "apt-get -o Debug::pkgProblemResolver=yes -y" - -# Build package -debuild --no-lintian -b -uc -us \ - -eINSTALLATION_DIR="${directory_base}" \ - -eVERSION="${version}" \ - -eREVISION="${revision}" - -cd ${pkg_path} && sha512sum ${deb_file} >/tmp/${deb_file}.sha512 - -if [ "${is_production}" = "no" ]; then - mv ${pkg_path}/${deb_file} /tmp/${final_name} - mv /tmp/${deb_file}.sha512 /tmp/${final_name}.sha512 -else - mv ${pkg_path}/${deb_file} /tmp/ -fi diff --git a/dev-tools/build-packages/deb/docker/amd64/Dockerfile b/dev-tools/build-packages/deb/docker/amd64/Dockerfile deleted file mode 100644 index f3ca3b981113..000000000000 --- a/dev-tools/build-packages/deb/docker/amd64/Dockerfile +++ /dev/null @@ -1,16 +0,0 @@ -FROM debian:10 - -ENV DEBIAN_FRONTEND noninteractive - -# Installing necessary packages -RUN apt-get update && apt-get install -y --allow-change-held-packages apt-utils && \ - apt-get install -y --allow-change-held-packages \ - 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 -RUN chmod +x /usr/local/bin/builder - -# Set the entrypoint -ENTRYPOINT ["/usr/local/bin/builder"] \ No newline at end of file diff --git a/dev-tools/build-packages/deb/launcher.sh b/dev-tools/build-packages/deb/launcher.sh deleted file mode 100755 index dcab4b3653f0..000000000000 --- a/dev-tools/build-packages/deb/launcher.sh +++ /dev/null @@ -1,204 +0,0 @@ -#!/bin/bash - -# Wazuh package generator -# Copyright (C) 2021, Wazuh Inc. -# -# This program is a free software; you can redistribute it -# and/or modify it under the terms of the GNU General Public -# License (version 2) as published by the FSF - Free Software -# Foundation. - -# Inputs -package="" -version="" -revision="0" -architecture="amd64" -build_base="yes" -build_docker="yes" -is_production="no" - -# Constants -deb_amd64_builder="deb_dashboard_builder_amd64" -deb_builder_dockerfile="${current_path}/docker" -commit_sha=$(git rev-parse --short HEAD) - -# Paths -current_path="$( cd $(dirname $0) ; pwd -P )" -config_path=$(realpath $current_path/../config) - -# Folders -out_dir="${current_path}/output" -tmp_dir="${current_path}/tmp" - -trap ctrl_c INT - -clean() { - exit_code=$1 - echo - echo "Cleaning temporary files..." - echo - # Clean the files - rm -r $tmp_dir - rm $current_path/docker/amd64/*.sh - if [ $exit_code != 0 ]; then - rm $out_dir/* - rmdir $out_dir - fi - - exit ${exit_code} -} - -ctrl_c() { - clean 1 -} - -build_deb() { - container_name="$1" - dockerfile_path="$2" - - # Validate and download files to build the package - valid_url='(https?|ftp|file)://[-[:alnum:]\+&@#/%?=~_|!:,.;]*[-[:alnum:]\+&@#/%=~_|]' - - echo - echo "Downloading files..." - echo - - mkdir -p $tmp_dir - cd $tmp_dir - - if [[ $package =~ $valid_url ]]; then - if ! curl --output wazuh-dashboard.tar.gz --silent --fail "${package}"; then - echo "The given URL or Path to the Wazuh Dashboard package is not working: ${package}" - clean 1 - fi - else - echo "The given URL or Path to the Wazuh Dashboard package is not valid: ${package}" - clean 1 - fi - - echo - echo Building the package... - echo - - # Prepare the package - tar -zxf wazuh-dashboard.tar.gz - directory_name=$(ls -td */ | head -1) - rm wazuh-dashboard.tar.gz - mv $directory_name wazuh-dashboard-base - jq '.wazuh.revision="'${revision}'"' wazuh-dashboard-base/package.json > pkgtmp.json && mv pkgtmp.json wazuh-dashboard-base/package.json - cp $config_path/* wazuh-dashboard-base - echo ${version} >wazuh-dashboard-base/VERSION - tar -czf ./wazuh-dashboard.tar.gz wazuh-dashboard-base - - # Copy the necessary files - cp ${current_path}/builder.sh ${dockerfile_path} - - # Build the Docker image - if [[ ${build_docker} == "yes" ]]; then - docker build -t ${container_name} ${dockerfile_path} || return 1 - fi - # Build the Debian package with a Docker container - if [ ! -d "$out_dir" ]; then - mkdir -p $out_dir - fi - - volumes="-v ${out_dir}/:/tmp:Z -v ${tmp_dir}/wazuh-dashboard.tar.gz:/opt/wazuh-dashboard.tar.gz" - docker run -t --rm ${volumes} \ - -v ${current_path}/../..:/root:Z \ - ${container_name} ${architecture} \ - ${revision} ${version} ${commit_sha} ${is_production}\ - || return 1 - - echo "Package $(ls -Art ${out_dir} | tail -n 1) added to ${out_dir}." - - echo - echo DONE! - echo - - return 0 -} - -build() { - build_name="${deb_amd64_builder}" - file_path="../${deb_builder_dockerfile}/${architecture}" - build_deb ${build_name} ${file_path} ${commit_sha} ${is_production}|| return 1 - return 0 -} - -help() { - echo - echo "Usage: $0 [OPTIONS]" - echo - echo " -v, --version Wazuh version" - echo " -p, --package Set the location of the .tar.gz file containing the Wazuh Dashboard package." - echo " -r, --revision [Optional] Package revision. By default: 1." - echo " -o, --output [Optional] Set the destination path of package. By default, an output folder will be created." - echo " --dont-build-docker [Optional] Locally built Docker image will be used instead of generating a new one." - echo " --production [Optional] The naming of the package will be ready for production." - echo " -h, --help Show this help." - echo - exit $1 -} - -main() { - while [ -n "${1}" ]; do - case "${1}" in - "-h" | "--help") - help 0 - ;; - "-p" | "--package") - if [ -n "${2}" ]; then - package="${2}" - shift 2 - else - help 1 - fi - ;; - "-v" | "--version") - if [ -n "${2}" ]; then - version="${2}" - shift 2 - else - help 1 - fi - ;; - "-r" | "--revision") - if [ -n "${2}" ]; then - revision="${2}" - shift 2 - else - help 1 - fi - ;; - "--dont-build-docker") - build_docker="no" - shift 1 - ;; - "--production") - is_production="yes" - shift 1 - ;; - "-o" | "--output") - if [ -n "${2}" ]; then - out_dir="${2}" - shift 2 - else - help 1 - fi - ;; - *) - help 1 - ;; - esac - done - - if [ -z "$package" ] | [ -z "$version" ]; then - help 1 - fi - - build || clean 1 - - clean 0 -} - -main "$@" diff --git a/dev-tools/build-packages/rpm/builder.sh b/dev-tools/build-packages/rpm/builder.sh deleted file mode 100755 index 63f5043a77b8..000000000000 --- a/dev-tools/build-packages/rpm/builder.sh +++ /dev/null @@ -1,57 +0,0 @@ -#!/bin/bash - -# Wazuh package builder -# Copyright (C) 2021, Wazuh Inc. -# -# This program is a free software; you can redistribute it -# and/or modify it under the terms of the GNU General Public -# License (version 2) as published by the FSF - Free Software -# Foundation. - -set -e - -# Script parameters to build the package -target="wazuh-dashboard" -architecture=$1 -revision=$2 -version=$3 -commit_sha=$4 -is_production=$5 -directory_base="/usr/share/wazuh-dashboard" - -# Build directories -build_dir=/build -rpm_build_dir=${build_dir}/rpmbuild -pkg_name=${target}-${version} -pkg_path="${rpm_build_dir}/RPMS/${architecture}" -file_name="${target}-${version}-${revision}" -rpm_file="${file_name}.${architecture}.rpm" -final_name="${target}_${version}-${revision}_${architecture}_${commit_sha}.rpm" - -mkdir -p ${rpm_build_dir}/{BUILD,BUILDROOT,RPMS,SOURCES,SPECS,SRPMS} - -# Prepare the sources directory to build the source tar.gz -mkdir ${build_dir}/${pkg_name} - -# Including spec file -cp /root/build-packages/rpm/${target}.spec ${rpm_build_dir}/SPECS/${pkg_name}.spec - -# Generating source tar.gz -cd ${build_dir} && tar czf "${rpm_build_dir}/SOURCES/${pkg_name}.tar.gz" "${pkg_name}" - -# Building RPM -/usr/bin/rpmbuild -v \ - --define "_topdir ${rpm_build_dir}" \ - --define "_version ${version}" \ - --define "_release ${revision}" \ - --define "_localstatedir ${directory_base}" \ - --target ${architecture} \ - -ba ${rpm_build_dir}/SPECS/${pkg_name}.spec - -cd ${pkg_path} && sha512sum ${rpm_file} >/tmp/${rpm_file}.sha512 - -find ${pkg_path}/ -maxdepth 3 -type f -name "${file_name}*" -exec mv {} /tmp/ \; -if [ "${is_production}" = "no" ]; then - mv /tmp/${rpm_file} /tmp/${final_name} - mv /tmp/${rpm_file}.sha512 /tmp/${final_name}.sha512 -fi diff --git a/dev-tools/build-packages/rpm/docker/x86_64/Dockerfile b/dev-tools/build-packages/rpm/docker/x86_64/Dockerfile deleted file mode 100644 index eb6493d15878..000000000000 --- a/dev-tools/build-packages/rpm/docker/x86_64/Dockerfile +++ /dev/null @@ -1,21 +0,0 @@ -FROM rockylinux:8.5 - -# 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 --nobest https://repo.ius.io/ius-release-el7.rpm - -RUN yum update -y && yum install -y python3 - -RUN ln -fs /usr/bin/python3.6 /usr/bin/python - -# Add the scripts to build the RPM package -ADD builder.sh /usr/local/bin/builder -RUN chmod +x /usr/local/bin/builder - -# Set the entrypoint -ENTRYPOINT ["/usr/local/bin/builder"] diff --git a/dev-tools/build-packages/rpm/launcher.sh b/dev-tools/build-packages/rpm/launcher.sh deleted file mode 100755 index 9695f9e8c4df..000000000000 --- a/dev-tools/build-packages/rpm/launcher.sh +++ /dev/null @@ -1,207 +0,0 @@ -#!/bin/bash - -# Wazuh package generator -# Copyright (C) 2021, Wazuh Inc. -# -# This program is a free software; you can redistribute it -# and/or modify it under the terms of the GNU General Public -# License (version 2) as published by the FSF - Free Software -# Foundation. - -# Inputs -package="" -version="" -revision="0" -architecture="x86_64" -build_base="yes" -build_docker="yes" -is_production="no" - -# Constants -rpm_x86_builder="rpm_dashboard_builder_x86" -rpm_builder_dockerfile="${current_path}/docker" -commit_sha=$(git rev-parse --short HEAD) - -# Paths -current_path="$( cd $(dirname $0) ; pwd -P )" -config_path=$(realpath $current_path/../config) - -# Folders -out_dir="${current_path}/output" -tmp_dir="${current_path}/tmp" - -trap ctrl_c INT - -clean() { - exit_code=$1 - echo - echo "Cleaning temporary files..." - echo - # Clean the files - rm -r $tmp_dir - rm $current_path/docker/x86_64/*.sh - - if [ $exit_code != 0 ]; then - rm $out_dir/* - rmdir $out_dir - fi - - exit ${exit_code} -} - -ctrl_c() { - clean 1 -} - -build_rpm() { - container_name="$1" - dockerfile_path="$2" - - # Validate and download files to build the package - valid_url='(https?|ftp|file)://[-[:alnum:]\+&@#/%?=~_|!:,.;]*[-[:alnum:]\+&@#/%=~_|]' - - echo - echo "Downloading files..." - echo - - mkdir -p $tmp_dir - cd $tmp_dir - - if [[ $package =~ $valid_url ]]; then - if ! curl --output wazuh-dashboard.tar.gz --silent --fail "${package}"; then - echo "The given URL or Path to the Wazuh Dashboard package is not working: ${package}" - clean 1 - fi - else - echo "The given URL or Path to the Wazuh Dashboard package is not valid: ${package}" - clean 1 - fi - - echo - echo Building the package... - echo - - # Prepare the package - tar -zxf wazuh-dashboard.tar.gz - directory_name=$(ls -td */ | head -1) - rm wazuh-dashboard.tar.gz - mv $directory_name wazuh-dashboard-base - jq '.wazuh.revision="'${revision}'"' wazuh-dashboard-base/package.json > pkgtmp.json && mv pkgtmp.json wazuh-dashboard-base/package.json - mkdir -p wazuh-dashboard-base/etc/services - cp $config_path/* wazuh-dashboard-base/etc/services - echo ${version} >wazuh-dashboard-base/VERSION - tar -czf ./wazuh-dashboard.tar.gz wazuh-dashboard-base - - # Copy the necessary files - cp ${current_path}/builder.sh ${dockerfile_path} - - # Build the Docker image - if [[ ${build_docker} == "yes" ]]; then - docker build -t ${container_name} ${dockerfile_path} || return 1 - fi - - # Build the RPM package with a Docker container - - if [ ! -d "$out_dir" ]; then - mkdir -p $out_dir - fi - volumes="-v ${out_dir}/:/tmp:Z -v ${tmp_dir}/wazuh-dashboard.tar.gz:/opt/wazuh-dashboard.tar.gz" - docker run -t --rm ${volumes} \ - -v ${current_path}/../..:/root:Z \ - ${container_name} ${architecture} \ - ${revision} ${version} ${commit_sha} ${is_production}\ - || return 1 - - echo "Package $(ls -Art ${out_dir} | tail -n 1) added to ${out_dir}." - - echo - echo DONE! - echo - - return 0 -} - -build() { - build_name="${rpm_x86_builder}" - file_path="../${rpm_builder_dockerfile}/${architecture}" - build_rpm ${build_name} ${file_path} ${commit_sha} ${is_production}|| return 1 - return 0 -} - -help() { - echo - echo "Usage: $0 [OPTIONS]" - echo - echo " -v, --version Wazuh version" - echo " -p, --package Set the location of the .tar.gz file containing the Wazuh Dashboard package." - echo " -r, --revision [Optional] Package revision. By default: 1." - echo " -o, --output [Optional] Set the destination path of package. By default, an output folder will be created." - echo " --dont-build-docker [Optional] Locally built Docker image will be used instead of generating a new one." - echo " --production [Optional] The naming of the package will be ready for production." - echo " -h, --help Show this help." - echo - exit $1 -} - -main() { - while [ -n "${1}" ]; do - case "${1}" in - "-h" | "--help") - help 0 - ;; - "-p" | "--package") - if [ -n "${2}" ]; then - package="${2}" - shift 2 - else - help 1 - fi - ;; - "-v" | "--version") - if [ -n "${2}" ]; then - version="${2}" - shift 2 - else - help 1 - fi - ;; - "-r" | "--revision") - if [ -n "${2}" ]; then - revision="${2}" - shift 2 - else - help 1 - fi - ;; - "--dont-build-docker") - build_docker="no" - shift 1 - ;; - "--production") - is_production="yes" - shift 1 - ;; - "-o" | "--output") - if [ -n "${2}" ]; then - outdir="${2}" - shift 2 - else - help 1 - fi - ;; - *) - help 1 - ;; - esac - done - - if [ -z "$package" ] | [ -z "$version" ]; then - help 1 - fi - - build || clean 1 - - clean 0 -} - -main "$@" From 75d0320ae706400d72d1835f5b06e4dc75a3fdfb Mon Sep 17 00:00:00 2001 From: Nicolas Date: Wed, 23 Oct 2024 09:53:21 -0300 Subject: [PATCH 09/30] Add debug logging to workflow --- .github/workflows/build_wazuh_dashboard_with_plugins.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build_wazuh_dashboard_with_plugins.yml b/.github/workflows/build_wazuh_dashboard_with_plugins.yml index cece2b91f967..8678e539db96 100644 --- a/.github/workflows/build_wazuh_dashboard_with_plugins.yml +++ b/.github/workflows/build_wazuh_dashboard_with_plugins.yml @@ -209,7 +209,7 @@ jobs: -s file://${{env.CURRENT_DIR}}/artifacts/security-package.zip \ -b file://${{env.CURRENT_DIR}}/artifacts/dashboard-package.zip \ ${{ inputs.architecture == 'aarch64' || inputs.architecture == 'arm64' && '--arm' || '' }} \ - --${{ inputs.system }} ${{ env.PRODUCTION }} + --${{ inputs.system }} --debug ${{ env.PRODUCTION }} - name: Test package run: | From 38d65901c7006e2c5cb4ca2f9b589e4330467afb Mon Sep 17 00:00:00 2001 From: Nicolas Date: Wed, 23 Oct 2024 10:10:34 -0300 Subject: [PATCH 10/30] Fix typo --- .github/workflows/build_wazuh_dashboard_with_plugins.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/build_wazuh_dashboard_with_plugins.yml b/.github/workflows/build_wazuh_dashboard_with_plugins.yml index 8678e539db96..cc91ebb73a1f 100644 --- a/.github/workflows/build_wazuh_dashboard_with_plugins.yml +++ b/.github/workflows/build_wazuh_dashboard_with_plugins.yml @@ -154,7 +154,6 @@ jobs: if [ "${{ inputs.is_stage }}" = "true" ]; then echo "PRODUCTION=--production" >> $GITHUB_ENV fi - if - name: Setup packages names run: | From 96308a5073e85c27534752718c37bc035a6f4124 Mon Sep 17 00:00:00 2001 From: Nicolas Date: Wed, 23 Oct 2024 10:57:05 -0300 Subject: [PATCH 11/30] Allow build-base to build arm base --- .github/workflows/build_base.yml | 18 ++++++++++++++---- .../build_wazuh_dashboard_with_plugins.yml | 18 +++++++++++++----- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/.github/workflows/build_base.yml b/.github/workflows/build_base.yml index 0fac06eaa850..28f0066221ba 100644 --- a/.github/workflows/build_base.yml +++ b/.github/workflows/build_base.yml @@ -10,6 +10,11 @@ on: required: true default: '' type: string + ARCHITECTURE: + description: 'The architecture to build the package for' + required: true + default: 'x64' + type: string workflow_dispatch: inputs: @@ -17,10 +22,15 @@ on: description: 'The branch/tag/commit to checkout to' required: true default: '' + ARCHITECTURE: + description: 'The architecture to build the package for' + required: true + default: 'x64' + type: string jobs: build: - runs-on: ubuntu-latest + runs-on: ${{ inputs.ARCHITECTURE == 'x64' && 'ubuntu-latest' || 'wz-linux-arm64' }} name: Build defaults: run: @@ -28,7 +38,7 @@ jobs: strategy: matrix: DISTRIBUTION: [tar.gz] - ARCHITECTURE: [x64] + ARCHITECTURE: [x64, arm64] steps: - name: Checkout code @@ -75,11 +85,11 @@ jobs: run: yarn osd bootstrap - name: Build linux-x64 - if: matrix.ARCHITECTURE == 'x64' + if: matrix.ARCHITECTURE == 'x64' && inputs.ARCHITECTURE == 'x64' run: yarn build-platform --linux --skip-os-packages --release - name: Build linux-arm64 - if: matrix.ARCHITECTURE == 'arm64' + if: matrix.ARCHITECTURE == 'arm64' && inputs.ARCHITECTURE == 'arm64' run: yarn build-platform --linux-arm --skip-os-packages --release - name: Rename artifact diff --git a/.github/workflows/build_wazuh_dashboard_with_plugins.yml b/.github/workflows/build_wazuh_dashboard_with_plugins.yml index cc91ebb73a1f..ba2b50af36d6 100644 --- a/.github/workflows/build_wazuh_dashboard_with_plugins.yml +++ b/.github/workflows/build_wazuh_dashboard_with_plugins.yml @@ -102,20 +102,28 @@ jobs: echo "Invalid combination of architecture and system" exit 1 fi - - name: Setup variables + set-architecture: + runs-on: ubuntu-latest + name: Set Architecture + outputs: + architecture: ${{ steps.set-arch.outputs.arch }} + steps: + - name: Determine Architecture + id: set-arch run: | - if {[ "${{ inputs.architecture }}" = "x86_64" ] || [ "${{ inputs.architecture }}" = "amd64" ]}; then - echo ARCH="x64" >> $GITHUB_ENV + if [[ "${{ inputs.architecture }}" == "x86_64" || "${{ inputs.architecture }}" == "amd64" ]]; then + echo "::set-output name=arch::x64" else - echo ARCH="arm64" >> $GITHUB_ENV + echo "::set-output name=arch::arm64" fi build-base: needs: [validate-inputs] name: Build dashboard - uses: wazuh/wazuh-dashboard/.github/workflows/build_base.yml@4.10.2 + uses: wazuh/wazuh-dashboard/.github/workflows/build_base.yml@change/337-support-arm-packages-generation with: CHECKOUT_TO: ${{ github.head_ref || github.ref_name }} + ARCHITECTURE: ${{ needs.set-architecture.outputs.architecture }} build-main-plugins: needs: [validate-inputs] From f97e5d457b32109332e6ed6a9011085a194dc7b7 Mon Sep 17 00:00:00 2001 From: Nicolas Date: Wed, 23 Oct 2024 11:11:45 -0300 Subject: [PATCH 12/30] Change build-base --- .github/workflows/build_base.yml | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/.github/workflows/build_base.yml b/.github/workflows/build_base.yml index 28f0066221ba..ba528d092f96 100644 --- a/.github/workflows/build_base.yml +++ b/.github/workflows/build_base.yml @@ -38,7 +38,6 @@ jobs: strategy: matrix: DISTRIBUTION: [tar.gz] - ARCHITECTURE: [x64, arm64] steps: - name: Checkout code @@ -79,18 +78,14 @@ jobs: - name: Get artifact build name run: | - echo "ARTIFACT_BUILD_NAME=wazuh-dashboard_${{ env.WZD_VERSION }}-${{ env.WZD_REVISION }}_${{ matrix.ARCHITECTURE }}.${{ matrix.DISTRIBUTION }}" >> $GITHUB_ENV + echo "ARTIFACT_BUILD_NAME=wazuh-dashboard_${{ env.WZD_VERSION }}-${{ env.WZD_REVISION }}_${{ inputs.ARCHITECTURE }}.${{ matrix.DISTRIBUTION }}" >> $GITHUB_ENV - name: Run bootstrap run: yarn osd bootstrap - - name: Build linux-x64 - if: matrix.ARCHITECTURE == 'x64' && inputs.ARCHITECTURE == 'x64' - run: yarn build-platform --linux --skip-os-packages --release - - - name: Build linux-arm64 + - name: Build if: matrix.ARCHITECTURE == 'arm64' && inputs.ARCHITECTURE == 'arm64' - run: yarn build-platform --linux-arm --skip-os-packages --release + run: yarn build-platform --${{inputs.ARCHITECTURE == 'arm64' && 'linux-arm' || 'linux'}} --skip-os-packages --release - name: Rename artifact run: mv /home/runner/work/wazuh-dashboard/wazuh-dashboard/artifacts/target/opensearch-dashboards-${{ env.VERSION }}-linux-${{ matrix.ARCHITECTURE }}.${{ matrix.DISTRIBUTION }} /home/runner/work/wazuh-dashboard/wazuh-dashboard/artifacts/target/${{ env.ARTIFACT_BUILD_NAME }} From e82b156ec4c2216b7488d8041558c66c6647c054 Mon Sep 17 00:00:00 2001 From: Nicolas Date: Wed, 23 Oct 2024 11:19:57 -0300 Subject: [PATCH 13/30] FIx conditional error --- .github/workflows/build_base.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/build_base.yml b/.github/workflows/build_base.yml index ba528d092f96..da7372141826 100644 --- a/.github/workflows/build_base.yml +++ b/.github/workflows/build_base.yml @@ -84,7 +84,6 @@ jobs: run: yarn osd bootstrap - name: Build - if: matrix.ARCHITECTURE == 'arm64' && inputs.ARCHITECTURE == 'arm64' run: yarn build-platform --${{inputs.ARCHITECTURE == 'arm64' && 'linux-arm' || 'linux'}} --skip-os-packages --release - name: Rename artifact From b45834f0b28e1e1fb6cb36c816b3541c6dd990c3 Mon Sep 17 00:00:00 2001 From: Nicolas Date: Wed, 23 Oct 2024 11:52:58 -0300 Subject: [PATCH 14/30] Fix problem with variables --- .github/workflows/build_base.yml | 8 ++++---- .../build_wazuh_dashboard_with_plugins.yml | 16 +--------------- 2 files changed, 5 insertions(+), 19 deletions(-) diff --git a/.github/workflows/build_base.yml b/.github/workflows/build_base.yml index da7372141826..c6be8c903279 100644 --- a/.github/workflows/build_base.yml +++ b/.github/workflows/build_base.yml @@ -30,7 +30,7 @@ on: jobs: build: - runs-on: ${{ inputs.ARCHITECTURE == 'x64' && 'ubuntu-latest' || 'wz-linux-arm64' }} + runs-on: ${{ (inputs.ARCHITECTURE == 'x86_64' || inputs.ARCHITECTURE == 'amd64') && 'ubuntu-latest' || 'wz-linux-arm64' }} name: Build defaults: run: @@ -78,16 +78,16 @@ jobs: - name: Get artifact build name run: | - echo "ARTIFACT_BUILD_NAME=wazuh-dashboard_${{ env.WZD_VERSION }}-${{ env.WZD_REVISION }}_${{ inputs.ARCHITECTURE }}.${{ matrix.DISTRIBUTION }}" >> $GITHUB_ENV + echo "ARTIFACT_BUILD_NAME=wazuh-dashboard_${{ env.WZD_VERSION }}-${{ env.WZD_REVISION }}_${{ (inputs.ARCHITECTURE == 'x86_64' || inputs.ARCHITECTURE == 'amd64') && 'x64' || 'arm64' }}.${{ matrix.DISTRIBUTION }}" >> $GITHUB_ENV - name: Run bootstrap run: yarn osd bootstrap - name: Build - run: yarn build-platform --${{inputs.ARCHITECTURE == 'arm64' && 'linux-arm' || 'linux'}} --skip-os-packages --release + run: yarn build-platform --${{(inputs.ARCHITECTURE == 'x86_64' || inputs.ARCHITECTURE == 'amd64') && 'linux' || 'linux-arm'}} --skip-os-packages --release - name: Rename artifact - run: mv /home/runner/work/wazuh-dashboard/wazuh-dashboard/artifacts/target/opensearch-dashboards-${{ env.VERSION }}-linux-${{ matrix.ARCHITECTURE }}.${{ matrix.DISTRIBUTION }} /home/runner/work/wazuh-dashboard/wazuh-dashboard/artifacts/target/${{ env.ARTIFACT_BUILD_NAME }} + run: mv /home/runner/work/wazuh-dashboard/wazuh-dashboard/artifacts/target/opensearch-dashboards-${{ env.VERSION }}-linux-${{ (inputs.ARCHITECTURE == 'x86_64' || inputs.ARCHITECTURE == 'amd64') && 'x64' || 'arm64' }}.${{ matrix.DISTRIBUTION }} /home/runner/work/wazuh-dashboard/wazuh-dashboard/artifacts/target/${{ env.ARTIFACT_BUILD_NAME }} - uses: actions/upload-artifact@v3 if: success() diff --git a/.github/workflows/build_wazuh_dashboard_with_plugins.yml b/.github/workflows/build_wazuh_dashboard_with_plugins.yml index ba2b50af36d6..21a81ba7350a 100644 --- a/.github/workflows/build_wazuh_dashboard_with_plugins.yml +++ b/.github/workflows/build_wazuh_dashboard_with_plugins.yml @@ -102,20 +102,6 @@ jobs: echo "Invalid combination of architecture and system" exit 1 fi - set-architecture: - runs-on: ubuntu-latest - name: Set Architecture - outputs: - architecture: ${{ steps.set-arch.outputs.arch }} - steps: - - name: Determine Architecture - id: set-arch - run: | - if [[ "${{ inputs.architecture }}" == "x86_64" || "${{ inputs.architecture }}" == "amd64" ]]; then - echo "::set-output name=arch::x64" - else - echo "::set-output name=arch::arm64" - fi build-base: needs: [validate-inputs] @@ -123,7 +109,7 @@ jobs: uses: wazuh/wazuh-dashboard/.github/workflows/build_base.yml@change/337-support-arm-packages-generation with: CHECKOUT_TO: ${{ github.head_ref || github.ref_name }} - ARCHITECTURE: ${{ needs.set-architecture.outputs.architecture }} + ARCHITECTURE: ${{ inputs.architecture }} build-main-plugins: needs: [validate-inputs] From 7bfcbbb5064c953b61cfbdcea35dc7712af5bba1 Mon Sep 17 00:00:00 2001 From: Nicolas Date: Wed, 23 Oct 2024 12:24:54 -0300 Subject: [PATCH 15/30] Update base artifact name --- .github/workflows/build_wazuh_dashboard_with_plugins.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build_wazuh_dashboard_with_plugins.yml b/.github/workflows/build_wazuh_dashboard_with_plugins.yml index 21a81ba7350a..31919d189ada 100644 --- a/.github/workflows/build_wazuh_dashboard_with_plugins.yml +++ b/.github/workflows/build_wazuh_dashboard_with_plugins.yml @@ -151,7 +151,7 @@ jobs: - name: Setup packages names run: | - echo "WAZUH_DASHBOARD_SLIM=wazuh-dashboard_${{ env.VERSION }}-${{ env.REVISION }}_x64.tar.gz" >> $GITHUB_ENV + echo "WAZUH_DASHBOARD_SLIM=wazuh-dashboard_${{ env.VERSION }}-${{ env.REVISION }}_${{(inputs.ARCHITECTURE == 'x86_64' || inputs.ARCHITECTURE == 'amd64') && 'x64' || 'arm64'}}.tar.gz" >> $GITHUB_ENV echo "WAZUH_SECURITY_PLUGIN=wazuh-security-dashboards-plugin_${{ env.VERSION }}-${{ env.REVISION }}_${{ inputs.reference_security_plugins }}.zip" >> $GITHUB_ENV echo "WAZUH_PLUGINS=wazuh-dashboard-plugins_${{ env.VERSION }}-${{ env.REVISION }}_${{ inputs.reference_wazuh_plugins }}.zip" >> $GITHUB_ENV if [ "${{ inputs.system }}" = "deb" ]; then From 10f41c83324023ee2ed8857eb6f3c7d76a306bcf Mon Sep 17 00:00:00 2001 From: Nicolas Date: Wed, 23 Oct 2024 14:48:59 -0300 Subject: [PATCH 16/30] Fix output directory --- .github/workflows/build_wazuh_dashboard_with_plugins.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build_wazuh_dashboard_with_plugins.yml b/.github/workflows/build_wazuh_dashboard_with_plugins.yml index 31919d189ada..9867e9a51fa1 100644 --- a/.github/workflows/build_wazuh_dashboard_with_plugins.yml +++ b/.github/workflows/build_wazuh_dashboard_with_plugins.yml @@ -207,8 +207,7 @@ jobs: - name: Test package run: | cd ${{ env.CURRENT_DIR }}/dev-tools/test-packages - ls -la ${{ env.CURRENT_DIR }}/dev-tools/build-packages/output/${{ inputs.system }} - cp ${{ env.CURRENT_DIR }}/dev-tools/build-packages/output/${{ inputs.system }}/${{env.PACKAGE_NAME}} ${{ env.CURRENT_DIR }}/dev-tools/test-packages/${{ inputs.system }} + cp ${{ env.CURRENT_DIR }}/dev-tools/build-packages/output/${{env.PACKAGE_NAME}} ${{ env.CURRENT_DIR }}/dev-tools/test-packages/${{ inputs.system }} bash ./test-packages.sh \ -p ${{env.PACKAGE_NAME}} @@ -222,7 +221,7 @@ jobs: - name: Upload package run: | echo "Uploading package" - aws s3 cp ${{ env.CURRENT_DIR }}/dev-tools/build-packages/output/${{ inputs.system }}/${{env.PACKAGE_NAME}} s3://packages-dev.internal.wazuh.com/development/wazuh/4.x/main/packages/ + aws s3 cp ${{ env.CURRENT_DIR }}/dev-tools/build-packages/output/${{env.PACKAGE_NAME}} s3://packages-dev.internal.wazuh.com/development/wazuh/4.x/main/packages/ s3uri="s3://packages-dev.internal.wazuh.com/development/wazuh/4.x/main/packages/${{env.PACKAGE_NAME}}" echo "S3 URI: ${s3uri}" @@ -230,6 +229,6 @@ jobs: if: ${{ inputs.checksum }} run: | echo "Uploading checksum" - aws s3 cp ${{ env.CURRENT_DIR }}/dev-tools/build-packages/output/${{ inputs.system }}/${{env.PACKAGE_NAME}}.sha512 s3://packages-dev.internal.wazuh.com/development/wazuh/4.x/main/packages/ + aws s3 cp ${{ env.CURRENT_DIR }}/dev-tools/build-packages/output/${{env.PACKAGE_NAME}}.sha512 s3://packages-dev.internal.wazuh.com/development/wazuh/4.x/main/packages/ s3uri="s3://packages-dev.internal.wazuh.com/development/wazuh/4.x/main/packages/${{env.PACKAGE_NAME}}.sha512" echo "S3 sha512 URI: ${s3uri}" From e1ea0115605c2017848d30e7e61a86f51f60edc6 Mon Sep 17 00:00:00 2001 From: Nicolas Date: Wed, 23 Oct 2024 15:26:26 -0300 Subject: [PATCH 17/30] Fix architecture validation --- .github/workflows/build_wazuh_dashboard_with_plugins.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build_wazuh_dashboard_with_plugins.yml b/.github/workflows/build_wazuh_dashboard_with_plugins.yml index 9867e9a51fa1..92efa22d5592 100644 --- a/.github/workflows/build_wazuh_dashboard_with_plugins.yml +++ b/.github/workflows/build_wazuh_dashboard_with_plugins.yml @@ -98,7 +98,7 @@ jobs: echo "Invalid combination of architecture and system" exit 1 fi - if {[ "${{ inputs.architecture }}" = "x86_64" ] || [ "${{ inputs.architecture }}" = "aarch64" ]}&& [ "${{ inputs.system }}" = "deb" ]; then + if {[ "${{ inputs.architecture }}" = "x86_64" ] || [ "${{ inputs.architecture }}" = "aarch64" ]; }&& [ "${{ inputs.system }}" = "deb" ]; then echo "Invalid combination of architecture and system" exit 1 fi From 066c0010997795b71867dca7870ca39376c517ea Mon Sep 17 00:00:00 2001 From: Nicolas Date: Wed, 23 Oct 2024 15:32:27 -0300 Subject: [PATCH 18/30] Fix typo --- .github/workflows/build_wazuh_dashboard_with_plugins.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/build_wazuh_dashboard_with_plugins.yml b/.github/workflows/build_wazuh_dashboard_with_plugins.yml index 92efa22d5592..08d2df3377bb 100644 --- a/.github/workflows/build_wazuh_dashboard_with_plugins.yml +++ b/.github/workflows/build_wazuh_dashboard_with_plugins.yml @@ -93,12 +93,11 @@ jobs: steps: - name: Validate inputs run: | - if { [ "${{ inputs.architecture }}" = "amd64" ] || [ "${{ inputs.architecture }}" = "arm64" ]; } && [ "${{ inputs.system }}" = "rpm" ]; then echo "Invalid combination of architecture and system" exit 1 fi - if {[ "${{ inputs.architecture }}" = "x86_64" ] || [ "${{ inputs.architecture }}" = "aarch64" ]; }&& [ "${{ inputs.system }}" = "deb" ]; then + if {[ "${{ inputs.architecture }}" = "x86_64" ] || [ "${{ inputs.architecture }}" = "aarch64" ]; } && [ "${{ inputs.system }}" = "deb" ]; then echo "Invalid combination of architecture and system" exit 1 fi From 087738c1ec0345707479c3c41ad62b606aef2398 Mon Sep 17 00:00:00 2001 From: Nicolas Date: Wed, 23 Oct 2024 15:52:13 -0300 Subject: [PATCH 19/30] Fix systems validation --- .github/workflows/build_wazuh_dashboard_with_plugins.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build_wazuh_dashboard_with_plugins.yml b/.github/workflows/build_wazuh_dashboard_with_plugins.yml index 08d2df3377bb..7775dafbf009 100644 --- a/.github/workflows/build_wazuh_dashboard_with_plugins.yml +++ b/.github/workflows/build_wazuh_dashboard_with_plugins.yml @@ -93,11 +93,11 @@ jobs: steps: - name: Validate inputs run: | - if { [ "${{ inputs.architecture }}" = "amd64" ] || [ "${{ inputs.architecture }}" = "arm64" ]; } && [ "${{ inputs.system }}" = "rpm" ]; then + if [[ "${{ inputs.architecture }}" == "amd64" || "${{ inputs.architecture }}" == "arm64" ]] && [[ "${{ inputs.system }}" == "rpm" ]]; then echo "Invalid combination of architecture and system" exit 1 fi - if {[ "${{ inputs.architecture }}" = "x86_64" ] || [ "${{ inputs.architecture }}" = "aarch64" ]; } && [ "${{ inputs.system }}" = "deb" ]; then + if [[ "${{ inputs.architecture }}" == "x86_64" || "${{ inputs.architecture }}" == "aarch64" ]] && [[ "${{ inputs.system }}" == "deb" ]]; then echo "Invalid combination of architecture and system" exit 1 fi From 8945e3fe580fa50f072f0926d5ccd7682fb52339 Mon Sep 17 00:00:00 2001 From: Nicolas Date: Thu, 24 Oct 2024 06:30:28 -0300 Subject: [PATCH 20/30] Add new validation --- .github/workflows/build_wazuh_dashboard_with_plugins.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build_wazuh_dashboard_with_plugins.yml b/.github/workflows/build_wazuh_dashboard_with_plugins.yml index 7775dafbf009..47225db89455 100644 --- a/.github/workflows/build_wazuh_dashboard_with_plugins.yml +++ b/.github/workflows/build_wazuh_dashboard_with_plugins.yml @@ -200,7 +200,7 @@ jobs: -a file://${{env.CURRENT_DIR}}/artifacts/wazuh-package.zip \ -s file://${{env.CURRENT_DIR}}/artifacts/security-package.zip \ -b file://${{env.CURRENT_DIR}}/artifacts/dashboard-package.zip \ - ${{ inputs.architecture == 'aarch64' || inputs.architecture == 'arm64' && '--arm' || '' }} \ + ${{(inputs.ARCHITECTURE == 'x86_64' || inputs.ARCHITECTURE == 'amd64') && '' || '--arm'}} \ --${{ inputs.system }} --debug ${{ env.PRODUCTION }} - name: Test package From 214c90f0011bfd9332262f0baa218f4bd9b5cbc3 Mon Sep 17 00:00:00 2001 From: Nicolas Date: Thu, 24 Oct 2024 07:26:14 -0300 Subject: [PATCH 21/30] Fix architecture validation for rpm --- dev-tools/build-packages/rpm/rpm-builder.sh | 62 +-------------------- 1 file changed, 2 insertions(+), 60 deletions(-) diff --git a/dev-tools/build-packages/rpm/rpm-builder.sh b/dev-tools/build-packages/rpm/rpm-builder.sh index 0865decf5e5b..51c1712766e0 100644 --- a/dev-tools/build-packages/rpm/rpm-builder.sh +++ b/dev-tools/build-packages/rpm/rpm-builder.sh @@ -64,6 +64,8 @@ log "Setting up parameters" if [ "${architecture}" = "x64" ]; then architecture="x86_64" +else + architecture="aarch64" fi build_dir=/build @@ -108,63 +110,3 @@ if [ "${is_production}" = "no" ]; then fi - -asdf(){ - rm wazuh-dashboard.tar.gz - mv $directory_name wazuh-dashboard-base - jq '.wazuh.revision="'${revision}'"' wazuh-dashboard-base/package.json > pkgtmp.json && mv pkgtmp.json wazuh-dashboard-base/package.json - mkdir -p wazuh-dashboard-base/etc/services - cp $config_path/* wazuh-dashboard-base/etc/services - echo ${version} >wazuh-dashboard-base/VERSION - - - - -# Build directories - -build_dir=/build -rpm_build_dir=${build_dir}/rpmbuild -directory_base="/usr/share/wazuh-dashboard" - - -pkg_name=${target}-${version} -pkg_path="${rpm_build_dir}/RPMS/${architecture}" -file_name="${target}-${version}-${revision}" -rpm_file="${file_name}.${architecture}.rpm" - -if [ "$is_production" = "no" ]; then - final_name="${target}_${version}-${revision}_${architecture}_${commit_sha}.rpm" -else - final_name="${target}_${version}-${revision}_${architecture}.rpm" -fi - -mkdir -p ${rpm_build_dir}/{BUILD,BUILDROOT,RPMS,SOURCES,SPECS,SRPMS} - -# Prepare the sources directory to build the source tar.gz -mkdir ${build_dir}/${pkg_name} - -# Including spec file -cp /usr/local/bin/${target}.spec ${rpm_build_dir}/SPECS/${pkg_name}.spec - -# Generating source tar.gz -cd ${build_dir} && tar czf "${rpm_build_dir}/SOURCES/${pkg_name}.tar.gz" "${pkg_name}" - -ls -l ${rpm_build_dir}/SOURCES - -# Building RPM -/usr/bin/rpmbuild -v \ - --define "_topdir ${rpm_build_dir}" \ - --define "_version ${version}" \ - --define "_release ${revision}" \ - --define "_localstatedir ${directory_base}" \ - --target ${architecture} \ - -ba ${rpm_build_dir}/SPECS/${pkg_name}.spec - -cd ${pkg_path} && sha512sum ${rpm_file} >/tmp/${rpm_file}.sha512 - -find ${pkg_path}/ -maxdepth 3 -type f -name "${file_name}*" -exec mv {} /tmp/ \; -if [ "${is_production}" = "no" ]; then - mv /tmp/${rpm_file} /tmp/${final_name} - mv /tmp/${rpm_file}.sha512 /tmp/${final_name}.sha512 -fi -} From e9777294683f9229cba353656d39e07ccbdca878 Mon Sep 17 00:00:00 2001 From: Nicolas Date: Thu, 24 Oct 2024 10:34:52 -0300 Subject: [PATCH 22/30] Fix case of input --- .github/workflows/build_wazuh_dashboard_with_plugins.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build_wazuh_dashboard_with_plugins.yml b/.github/workflows/build_wazuh_dashboard_with_plugins.yml index 47225db89455..f2c88499b8b7 100644 --- a/.github/workflows/build_wazuh_dashboard_with_plugins.yml +++ b/.github/workflows/build_wazuh_dashboard_with_plugins.yml @@ -200,7 +200,7 @@ jobs: -a file://${{env.CURRENT_DIR}}/artifacts/wazuh-package.zip \ -s file://${{env.CURRENT_DIR}}/artifacts/security-package.zip \ -b file://${{env.CURRENT_DIR}}/artifacts/dashboard-package.zip \ - ${{(inputs.ARCHITECTURE == 'x86_64' || inputs.ARCHITECTURE == 'amd64') && '' || '--arm'}} \ + ${{(inputs.architecture == 'x86_64' || inputs.architecture == 'amd64') && '' || '--arm'}} \ --${{ inputs.system }} --debug ${{ env.PRODUCTION }} - name: Test package From a93cbd86c6fb28e0d3920ca5bc9a03385594109a Mon Sep 17 00:00:00 2001 From: Nicolas Date: Thu, 24 Oct 2024 11:34:29 -0300 Subject: [PATCH 23/30] Add architecture flag to env --- .github/workflows/build_wazuh_dashboard_with_plugins.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build_wazuh_dashboard_with_plugins.yml b/.github/workflows/build_wazuh_dashboard_with_plugins.yml index f2c88499b8b7..a9b1f20ac169 100644 --- a/.github/workflows/build_wazuh_dashboard_with_plugins.yml +++ b/.github/workflows/build_wazuh_dashboard_with_plugins.yml @@ -153,6 +153,7 @@ jobs: echo "WAZUH_DASHBOARD_SLIM=wazuh-dashboard_${{ env.VERSION }}-${{ env.REVISION }}_${{(inputs.ARCHITECTURE == 'x86_64' || inputs.ARCHITECTURE == 'amd64') && 'x64' || 'arm64'}}.tar.gz" >> $GITHUB_ENV echo "WAZUH_SECURITY_PLUGIN=wazuh-security-dashboards-plugin_${{ env.VERSION }}-${{ env.REVISION }}_${{ inputs.reference_security_plugins }}.zip" >> $GITHUB_ENV echo "WAZUH_PLUGINS=wazuh-dashboard-plugins_${{ env.VERSION }}-${{ env.REVISION }}_${{ inputs.reference_wazuh_plugins }}.zip" >> $GITHUB_ENV + echo "ARCHITECTURE_FLAG"=${{ (inputs.architecture == 'x86_64' || inputs.architecture == 'amd64') && '' || '--arm' }} >> $GITHUB_ENV if [ "${{ inputs.system }}" = "deb" ]; then if [ "${{ inputs.is_stage }}" = "true" ]; then echo "PACKAGE_NAME=wazuh-dashboard_${{ env.VERSION }}-${{ inputs.revision }}_${{ inputs.architecture }}.deb" >> $GITHUB_ENV @@ -196,11 +197,10 @@ jobs: cd ${{ env.CURRENT_DIR }}/dev-tools/build-packages bash ./build-packages.sh \ -v ${{ env.VERSION }} \ - -r ${{ inputs.revision }} \ + -r ${{ inputs.revision }} ${{env.ARCHITECTURE_FLAG}}\ -a file://${{env.CURRENT_DIR}}/artifacts/wazuh-package.zip \ -s file://${{env.CURRENT_DIR}}/artifacts/security-package.zip \ -b file://${{env.CURRENT_DIR}}/artifacts/dashboard-package.zip \ - ${{(inputs.architecture == 'x86_64' || inputs.architecture == 'amd64') && '' || '--arm'}} \ --${{ inputs.system }} --debug ${{ env.PRODUCTION }} - name: Test package From 4a4ead299b2a8ac9666d5084acdb5e8e1c689064 Mon Sep 17 00:00:00 2001 From: Nicolas Date: Thu, 24 Oct 2024 11:53:51 -0300 Subject: [PATCH 24/30] Change if condition --- .github/workflows/build_wazuh_dashboard_with_plugins.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build_wazuh_dashboard_with_plugins.yml b/.github/workflows/build_wazuh_dashboard_with_plugins.yml index a9b1f20ac169..24141d95a407 100644 --- a/.github/workflows/build_wazuh_dashboard_with_plugins.yml +++ b/.github/workflows/build_wazuh_dashboard_with_plugins.yml @@ -153,7 +153,11 @@ jobs: echo "WAZUH_DASHBOARD_SLIM=wazuh-dashboard_${{ env.VERSION }}-${{ env.REVISION }}_${{(inputs.ARCHITECTURE == 'x86_64' || inputs.ARCHITECTURE == 'amd64') && 'x64' || 'arm64'}}.tar.gz" >> $GITHUB_ENV echo "WAZUH_SECURITY_PLUGIN=wazuh-security-dashboards-plugin_${{ env.VERSION }}-${{ env.REVISION }}_${{ inputs.reference_security_plugins }}.zip" >> $GITHUB_ENV echo "WAZUH_PLUGINS=wazuh-dashboard-plugins_${{ env.VERSION }}-${{ env.REVISION }}_${{ inputs.reference_wazuh_plugins }}.zip" >> $GITHUB_ENV - echo "ARCHITECTURE_FLAG"=${{ (inputs.architecture == 'x86_64' || inputs.architecture == 'amd64') && '' || '--arm' }} >> $GITHUB_ENV + if [[ "${{ inputs.architecture }}" == "x86_64" || "${{ inputs.architecture }}" == "amd64" ]]; then + echo "ARCHITECTURE_FLAG=" >> $GITHUB_ENV + else + echo "ARCHITECTURE_FLAG=--arm" >> $GITHUB_ENV + fi if [ "${{ inputs.system }}" = "deb" ]; then if [ "${{ inputs.is_stage }}" = "true" ]; then echo "PACKAGE_NAME=wazuh-dashboard_${{ env.VERSION }}-${{ inputs.revision }}_${{ inputs.architecture }}.deb" >> $GITHUB_ENV From 8eec4bcc293f0f281c74953da7f0e22c3ff0e840 Mon Sep 17 00:00:00 2001 From: Nicolas Date: Thu, 24 Oct 2024 15:01:51 -0300 Subject: [PATCH 25/30] Restore reference for build-base workflow --- .github/workflows/build_wazuh_dashboard_with_plugins.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build_wazuh_dashboard_with_plugins.yml b/.github/workflows/build_wazuh_dashboard_with_plugins.yml index 24141d95a407..f55a16767374 100644 --- a/.github/workflows/build_wazuh_dashboard_with_plugins.yml +++ b/.github/workflows/build_wazuh_dashboard_with_plugins.yml @@ -105,7 +105,7 @@ jobs: build-base: needs: [validate-inputs] name: Build dashboard - uses: wazuh/wazuh-dashboard/.github/workflows/build_base.yml@change/337-support-arm-packages-generation + uses: wazuh/wazuh-dashboard/.github/workflows/build_base.yml@4.10.2 with: CHECKOUT_TO: ${{ github.head_ref || github.ref_name }} ARCHITECTURE: ${{ inputs.architecture }} From d4c298cfc9c38ec1c43fe69ec1b0c14d42c4bf70 Mon Sep 17 00:00:00 2001 From: Nicolas Date: Fri, 25 Oct 2024 07:36:29 -0300 Subject: [PATCH 26/30] Change default input value for build_base --- .github/workflows/build_base.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build_base.yml b/.github/workflows/build_base.yml index c6be8c903279..665a7e4f69f8 100644 --- a/.github/workflows/build_base.yml +++ b/.github/workflows/build_base.yml @@ -13,7 +13,7 @@ on: ARCHITECTURE: description: 'The architecture to build the package for' required: true - default: 'x64' + default: 'amd64' type: string workflow_dispatch: @@ -25,7 +25,7 @@ on: ARCHITECTURE: description: 'The architecture to build the package for' required: true - default: 'x64' + default: 'amd64' type: string jobs: From 6a853002f3e67017b8c677eb41f3b6bd0eed0b78 Mon Sep 17 00:00:00 2001 From: Nicolas Date: Fri, 25 Oct 2024 07:56:48 -0300 Subject: [PATCH 27/30] Change directory of building files --- dev-tools/build-packages/deb/Docker/Dockerfile | 2 +- dev-tools/build-packages/deb/deb-builder.sh | 4 ++-- dev-tools/build-packages/rpm/Docker/Dockerfile | 2 +- dev-tools/build-packages/rpm/rpm-builder.sh | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/dev-tools/build-packages/deb/Docker/Dockerfile b/dev-tools/build-packages/deb/Docker/Dockerfile index ed88a214d5b1..6289cd35d3ad 100644 --- a/dev-tools/build-packages/deb/Docker/Dockerfile +++ b/dev-tools/build-packages/deb/Docker/Dockerfile @@ -10,7 +10,7 @@ RUN apt-get update && apt-get install -y --allow-change-held-packages apt-utils # Add the script to build the Debian package ADD deb-builder.sh /usr/local/bin/builder -ADD debian /usr/local/bin/debian +ADD debian /usr/local/src/debian RUN chmod +x /usr/local/bin/builder # Set the entrypoint diff --git a/dev-tools/build-packages/deb/deb-builder.sh b/dev-tools/build-packages/deb/deb-builder.sh index 1bcaa53f0773..3e0e993d8c7a 100755 --- a/dev-tools/build-packages/deb/deb-builder.sh +++ b/dev-tools/build-packages/deb/deb-builder.sh @@ -74,8 +74,8 @@ final_name="${target}_${version}-${revision}_${architecture}_${commit_sha}.deb" mkdir -p ${source_dir}/debian -# Including spec file -cp -r /usr/local/bin/debian/* ${source_dir}/debian/ +# Including spec files +cp -r /usr/local/src/debian/* ${source_dir}/debian/ # Generating directory structure to build the .deb package cd ${build_dir}/${target} && tar -czf ${pkg_name}.orig.tar.gz "${pkg_name}" diff --git a/dev-tools/build-packages/rpm/Docker/Dockerfile b/dev-tools/build-packages/rpm/Docker/Dockerfile index 1c719166a7de..c62abf3820c1 100644 --- a/dev-tools/build-packages/rpm/Docker/Dockerfile +++ b/dev-tools/build-packages/rpm/Docker/Dockerfile @@ -15,7 +15,7 @@ RUN ln -fs /usr/bin/python3.6 /usr/bin/python # Add the scripts to build the RPM package ADD rpm-builder.sh /usr/local/bin/builder -ADD wazuh-dashboard.spec /usr/local/bin/wazuh-dashboard.spec +ADD wazuh-dashboard.spec /usr/local/src/wazuh-dashboard.spec RUN chmod +x /usr/local/bin/builder # Set the entrypoint diff --git a/dev-tools/build-packages/rpm/rpm-builder.sh b/dev-tools/build-packages/rpm/rpm-builder.sh index 51c1712766e0..180139b121ff 100644 --- a/dev-tools/build-packages/rpm/rpm-builder.sh +++ b/dev-tools/build-packages/rpm/rpm-builder.sh @@ -89,7 +89,7 @@ mkdir -p ${rpm_build_dir}/{BUILD,BUILDROOT,RPMS,SOURCES,SPECS,SRPMS} mkdir ${build_dir}/${pkg_name} # Including spec file -cp /usr/local/bin/${target}.spec ${rpm_build_dir}/SPECS/${pkg_name}.spec +cp /usr/local/src/${target}.spec ${rpm_build_dir}/SPECS/${pkg_name}.spec cd ${build_dir} && tar czf "${rpm_build_dir}/SOURCES/${pkg_name}.tar.gz" "${pkg_name}" log "Building RPM..." From 69feca24e575676eb3cd05321d5d4e89e6df7e6e Mon Sep 17 00:00:00 2001 From: Nicolas Date: Fri, 25 Oct 2024 10:12:15 -0300 Subject: [PATCH 28/30] Update readme --- dev-tools/build-packages/README.md | 90 +++++++++++++----------------- 1 file changed, 38 insertions(+), 52 deletions(-) diff --git a/dev-tools/build-packages/README.md b/dev-tools/build-packages/README.md index 16f085dde78f..31bb1618f3de 100644 --- a/dev-tools/build-packages/README.md +++ b/dev-tools/build-packages/README.md @@ -1,70 +1,56 @@ # Package building -This folder contains tools used to create `rpm` and `deb` packages. + +This folder contains tools used to create `tar`, `rpm` and `deb` packages. ## Requirements - - A system with Docker. - - Internet connection (to download the docker images the first time). -## Builders +- A system with Docker. +- Internet connection (to download the docker images the first time). -### Tarball +## How to build packages -To system packages (deb and rpm), a tarball of Wazuh dashboard `.tar.gz` is required. -This tarball contains the [Wazuh plugin][wazuh-plugin], the [Wazuh Security plugin][wazuh-security-plugin], -a set of OpenSearch plugins and the default configuration for the app. +The script `build-packages.sh` is in charge of coordinating the different steps to build each type of packages. -The `generate_base.sh` script generates a `.tar.gz` file using the following inputs: -- `-a` | `--app`: URL to the zipped Wazuh plugin.* -- `-b` | `--base`: URL to the Wazuh dashboard `.tar.gz`, as generated with `yarn build --skip-os-packages --release`.* -- `-s` | `--security`: URL to the zipped Wazuh Security plugin, as generated with `yarn build`.* -- `-v` | `--version`: the Wazuh version of the package. -- `-r` | `--revision`: [Optional] Set the revision of the build. By default, it is set to 1. -- `-o` | `--output` [Optional] Set the destination path of package. By default, an output folder will be created in the same directory as the script. +### Pre-requisites -*Note:* use `file://` to indicate a local file. Otherwise, the script will try to download the file from the given URL. +The script needs 3 different zip files, containing the following respectively: -Example: -```bash -bash generate_base.sh \ - --app https://packages-dev.wazuh.com/pre-release/ui/dashboard/wazuh-4.6.0-1.zip \ - --base file:///home/user/wazuh-dashboard/target/opensearch-dashboards-2.4.1-linux-x64.tar.gz \ - --security file:///home/user/wazuh-security-dashboards-plugin/build/security-dashboards-2.4.1.0.zip \ - --version 4.6.0 -``` +- The base of Wazuh Dashboard, generated by running `yarn build --linux --skip-os-packages --release` or `yarn build --linux-arm --skip-os-packages --release` for arm packages +- The build of each plugin in `wazuh-dashboard-plugins` repo +- The build of the `wazuh-security-dashboards-plugin` repo -### DEB +### Building packages -The `launcher.sh` script generates a `.deb` package based on the previously generated `.tar.gz`. -A Docker container is used to generate the package. It takes the following inputs: -- `-v` | `--version`: the Wazuh version of the package. -- `-p` | `--package`: the location of the `.tar.gz` file. It can be a URL or a PATH, with the format `file://` -- `-r` | `--revision`: [Optional] Set the revision of the build. By default, it is set to 1. -- `-o` | `--output` [Optional] Set the destination path of package. By default, an output folder will be created in the same directory as the script. -- `--dont-build-docker`: [Optional] Locally built Docker image will be used instead of generating a new one. +The script can build a `.tar.gz` (former base), and `rpm` and `deb` packages. This can be for x64 and arm architectures (it is not cross-architecture building. You need to run the script in a machine of the same architecture that you are building). -Example: -```bash -bash launcher.sh \ - --version 4.6.0 \ - --package file:///home/user/wazuh-dashboard/dev_tools/build_packages/base/output/wazuh-dashboard-4.6.0-1-linux-x64.tar.gz -``` +The inputs are the following: + +- `-a`, `--app`: URL or path to the zip that contains the `wazuh-dashboard-plugins` plugins build. +- `-b`, `--base`: URL or path to the zip that contains the `wazuh-dashboard build`. +- `-s`, `--security`: URL or path to the zip that contains the `wazuh-security-dashboards-plugin` build. +- `-v`, `--version`: Set the version of this build. +- `-r`, `--revision`: [Optional] Set the revision of this build. By default, it is set to 1. +- `--all-platforms`: Build all platforms. +- `--deb`: Build deb. +- `--rpm`: Build rpm. +- `--tar`: Build tar.gz. +- `--production`:[Optional] The naming of the package will be ready for production. Otherwise, it will include the hash of the current commit. +- `--arm`: [Optional] Build for arm64 instead of x64. +- `--debug`: [Optional] Enables debug mode, which will show detailed information during the script run. +- `--silent`: [Optional] Enables silent mode, which will show the minimum possible information during the script run. `--debug` has priority over this. -### RPM +> [!IMPORTANT] +> In the inputs where a local path is available, use `file://` to indicate it. -The `launcher.sh` script generates a `.rpm` package based on the previously generated `.tar.gz`. -A Docker container is used to generate the package. It takes the following inputs: -- `-v` | `--version`: the Wazuh version of the package. -- `-p` | `--package`: the location of the `.tar.gz` file. It can be a URL or a PATH, with the format `file://` -- `-r` | `--revision`: [Optional] Set the revision of the build. By default, it is set to 1. -- `-o` | `--output` [Optional] Set the destination path of package. By default, an output folder will be created in the same directory as the script. -- `--dont-build-docker`: [Optional] Locally built Docker image will be used instead of generating a new one. +> [!WARNING] +> To build `arm` packages, you need to run the script in an arm machine, and use an arm build of the wazuh-dashboard base with `-b` Example: + ```bash -bash launcher.sh \ - --version 4.6.0 \ - --package file:///home/user/wazuh-dashboard/dev_tools/build_packages/base/output/wazuh-dashboard-4.6.0-1-linux-x64.tar.gz +bash build-packages.sh \ + --app file:///home/user/packages/wazuh-package.zip \ + --base file:///home/user/packages/dashboard-package.zip \ + --security file:///home/user/packages/security-package.zip \ + --version 4.10.0 --revision 2 --deb --silent ``` - -[wazuh-plugin]: https://github.com/wazuh/wazuh-kibana-app -[wazuh-security-plugin]: https://github.com/wazuh/wazuh-security-dashboards-plugin \ No newline at end of file From 6432a881af9cd1279608a4c8dd29fe25fcc392f1 Mon Sep 17 00:00:00 2001 From: Nicolas Date: Fri, 25 Oct 2024 10:17:03 -0300 Subject: [PATCH 29/30] Apply categories order change to prevent issues --- dev-tools/build-packages/base/base-builder.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev-tools/build-packages/base/base-builder.sh b/dev-tools/build-packages/base/base-builder.sh index e54015c0beb9..89ae12037e15 100755 --- a/dev-tools/build-packages/base/base-builder.sh +++ b/dev-tools/build-packages/base/base-builder.sh @@ -100,7 +100,7 @@ log "Replacing application categories" log category_explore='{id:"explore",label:"Explore",order:100,euiIconType:"search"}' -category_dashboard_management='{id:"management",label:"Index management",order:5e3,euiIconType:"managementApp"}' +category_dashboard_management='{id:"management",label:"Indexer management",order:6e3,euiIconType:"managementApp"}' # Replace app category to Reporting app sed -i -e "s|category:{id:\"opensearch\",label:_i18n.i18n.translate(\"opensearch.reports.categoryName\",{defaultMessage:\"OpenSearch Plugins\"}),order:2e3}|category:${category_explore}|" ./plugins/reportsDashboards/target/public/reportsDashboards.plugin.js From a749631d62083022575413d5697700007363a3da Mon Sep 17 00:00:00 2001 From: Nicolas Date: Fri, 25 Oct 2024 12:50:11 -0300 Subject: [PATCH 30/30] Fix variable in script --- dev-tools/build-packages/build-packages.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev-tools/build-packages/build-packages.sh b/dev-tools/build-packages/build-packages.sh index f7705da53de4..71100a6429af 100755 --- a/dev-tools/build-packages/build-packages.sh +++ b/dev-tools/build-packages/build-packages.sh @@ -153,7 +153,7 @@ build(){ if [ "$tar" == "no" ]; then echo "Removing tar package..." - rm -r $(find $output -name "*.tar.gz") + rm -r $(find $output_dir -name "*.tar.gz") fi }