From 1047ad588c3a82c87adb39453049831b93e0cd94 Mon Sep 17 00:00:00 2001 From: Ian Yenien Serrano <63758389+yenienserrano@users.noreply.github.com> Date: Tue, 5 Dec 2023 17:08:37 +0100 Subject: [PATCH] Updating our package construction methods (#122) --- .gitignore | 2 +- config/opensearch_dashboards.prod.yml | 2 +- .../build-packages}/README.md | 0 .../build-packages}/base/generate_base.sh | 60 +++++- dev-tools/build-packages/build-packages.sh | 191 ++++++++++++++++++ .../build-packages}/config/default | 0 .../build-packages/config/wazuh-dashboard | 0 .../config/wazuh-dashboard.service | 0 .../build-packages}/deb/builder.sh | 2 +- .../build-packages}/deb/debian/changelog | 0 .../build-packages}/deb/debian/control | 0 .../build-packages}/deb/debian/copyright | 0 .../build-packages}/deb/debian/postinst | 0 .../build-packages}/deb/debian/postrm | 0 .../build-packages}/deb/debian/preinst | 0 .../build-packages}/deb/debian/prerm | 0 .../build-packages}/deb/debian/rules | 0 .../deb/docker/amd64/Dockerfile | 0 .../build-packages}/deb/launcher.sh | 4 +- .../build-packages}/rpm/builder.sh | 2 +- .../rpm/docker/x86_64/Dockerfile | 0 .../build-packages}/rpm/launcher.sh | 5 +- .../build-packages/rpm/wazuh-dashboard.spec | 1 + .../install-docker-dev.sh | 0 .../signoff-check.sh | 0 src/dev/precommit_hook/casing_check_config.js | 3 +- 26 files changed, 254 insertions(+), 18 deletions(-) rename {dev_tools/build_packages => dev-tools/build-packages}/README.md (100%) rename {dev_tools/build_packages => dev-tools/build-packages}/base/generate_base.sh (74%) create mode 100644 dev-tools/build-packages/build-packages.sh rename {dev_tools/build_packages => dev-tools/build-packages}/config/default (100%) rename dev_tools/build_packages/config/wazuh_dashboard => dev-tools/build-packages/config/wazuh-dashboard (100%) rename dev_tools/build_packages/config/wazuh_dashboard.service => dev-tools/build-packages/config/wazuh-dashboard.service (100%) rename {dev_tools/build_packages => dev-tools/build-packages}/deb/builder.sh (95%) rename {dev_tools/build_packages => dev-tools/build-packages}/deb/debian/changelog (100%) rename {dev_tools/build_packages => dev-tools/build-packages}/deb/debian/control (100%) rename {dev_tools/build_packages => dev-tools/build-packages}/deb/debian/copyright (100%) rename {dev_tools/build_packages => dev-tools/build-packages}/deb/debian/postinst (100%) rename {dev_tools/build_packages => dev-tools/build-packages}/deb/debian/postrm (100%) rename {dev_tools/build_packages => dev-tools/build-packages}/deb/debian/preinst (100%) rename {dev_tools/build_packages => dev-tools/build-packages}/deb/debian/prerm (100%) rename {dev_tools/build_packages => dev-tools/build-packages}/deb/debian/rules (100%) rename {dev_tools/build_packages => dev-tools/build-packages}/deb/docker/amd64/Dockerfile (100%) rename {dev_tools/build_packages => dev-tools/build-packages}/deb/launcher.sh (98%) rename {dev_tools/build_packages => dev-tools/build-packages}/rpm/builder.sh (95%) rename {dev_tools/build_packages => dev-tools/build-packages}/rpm/docker/x86_64/Dockerfile (100%) rename {dev_tools/build_packages => dev-tools/build-packages}/rpm/launcher.sh (98%) rename dev_tools/build_packages/rpm/wazuh_dashboard.spec => dev-tools/build-packages/rpm/wazuh-dashboard.spec (99%) rename dev_tools/install_docker_dev.sh => dev-tools/install-docker-dev.sh (100%) rename dev_tools/signoff_check.sh => dev-tools/signoff-check.sh (100%) diff --git a/.gitignore b/.gitignore index bb161be6f041..1add5bb6a1d2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,7 @@ .aws-config.json .signing-config.json .ackrc -/dev_tools/build_packages/*/output +/dev-tools/build-packages/*/output /.opensearch /.chromium /package.json.bak diff --git a/config/opensearch_dashboards.prod.yml b/config/opensearch_dashboards.prod.yml index 3d20951af3bc..89b23a8be11e 100644 --- a/config/opensearch_dashboards.prod.yml +++ b/config/opensearch_dashboards.prod.yml @@ -9,7 +9,7 @@ server.ssl.enabled: true server.ssl.key: "/etc/wazuh-dashboard/certs/dashboard-key.pem" server.ssl.certificate: "/etc/wazuh-dashboard/certs/dashboard.pem" opensearch.ssl.certificateAuthorities: ["/etc/wazuh-dashboard/certs/root-ca.pem"] -uiSettings.overrides.defaultRoute: /app/wazuh +uiSettings.overrides.defaultRoute: /app/wz-home opensearchDashboards.branding: useExpandedHeader: false diff --git a/dev_tools/build_packages/README.md b/dev-tools/build-packages/README.md similarity index 100% rename from dev_tools/build_packages/README.md rename to dev-tools/build-packages/README.md diff --git a/dev_tools/build_packages/base/generate_base.sh b/dev-tools/build-packages/base/generate_base.sh similarity index 74% rename from dev_tools/build_packages/base/generate_base.sh rename to dev-tools/build-packages/base/generate_base.sh index 356e602b8338..530f00a0bf39 100755 --- a/dev_tools/build_packages/base/generate_base.sh +++ b/dev-tools/build-packages/base/generate_base.sh @@ -53,34 +53,63 @@ build() { # Validate and download files to build the package valid_url='(https?|ftp|file)://[-[:alnum:]\+&@#/%?=~_|!:,.;]*[-[:alnum:]\+&@#/%=~_|]' echo - echo "Downloading files..." + echo "Downloading plugins..." echo mkdir -p $tmp_dir cd $tmp_dir + mkdir -p applications if [[ $app =~ $valid_url ]]; then - if ! curl --output app.zip --silent --fail "${app}"; then - echo "The given URL or Path to the Wazuh App is not working: ${app}" + 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 ! 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 + 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 . + rm wazuh-dashboard.zip + mv $(ls | grep wazuh-dashboard) 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 security.zip --silent --fail "${security}"; 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}" @@ -104,8 +133,15 @@ build() { bin/opensearch-dashboards-plugin install indexManagementDashboards bin/opensearch-dashboards-plugin install notificationsDashboards bin/opensearch-dashboards-plugin install reportsDashboards - bin/opensearch-dashboards-plugin install file:../security.zip - bin/opensearch-dashboards-plugin install file:../app.zip + # Install Wazuh apps and Security app + plugins=$(ls $tmp_dir/applications) + echo $plugins + for plugin in $plugins; do + echo $plugin + if [[ $plugin =~ .*\.zip ]]; then + bin/opensearch-dashboards-plugin install file:../applications/$plugin + fi + done # Enable the default configuration (renaming) cp $config_path/opensearch_dashboards.prod.yml config/opensearch_dashboards.yml @@ -121,8 +157,10 @@ build() { echo Compressing the package... echo cd .. - mkdir -p $out_dir - tar -czvf $out_dir/$working_dir.tar.gz $working_dir + if [ ! -d "$out_dir" ]; then + mkdir -p $out_dir + fi + tar -czf $out_dir/$working_dir.tar.gz $working_dir echo echo DONE! diff --git a/dev-tools/build-packages/build-packages.sh b/dev-tools/build-packages/build-packages.sh new file mode 100644 index 000000000000..9a9b4053ab53 --- /dev/null +++ b/dev-tools/build-packages/build-packages.sh @@ -0,0 +1,191 @@ +#!/bin/bash + +app="" +base="" +revision="1" +security="" +version="" +all_platforms="no" +deb="no" +rpm="no" +tar="no" +output="$( cd $(dirname $0) ; pwd -P )/output" + +current_path="$( cd $(dirname $0) ; pwd -P )" + +build_tar() { + echo "Building tar package..." + cd ./base + bash ./generate_base.sh -a $app -b $base -s $security -v $version -r $revision + + name_package_tar=$(ls ./output) + + echo "Moving tar package to $output" + mv $current_path/base/output/$name_package_tar $output/$name_package_tar + cd ../ +} + +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 + name_package_tar=$(ls ./output) + echo "Moving deb package to $output/deb" + mv $current_path/deb/output $output/deb + cd ../ +} + +build_rpm() { + echo "Building rpm package..." + name_package_tar=$(find $output -name "*.tar.gz") + cd ./rpm + bash ./launcher.sh -v $version -r $revision -p file://$name_package_tar + echo "Moving rpm package to $output/rpm" + mv $current_path/rpm/output $output/rpm + cd ../ +} + + +build() { + name_package_tar="wazuh-dashboard-$version-$revision-linux-x64.tar.gz" + + if [ ! -d "$output" ]; then + mkdir $output + fi + + if [ "$all_platforms" == "yes" ]; then + deb="yes" + rpm="yes" + tar="yes" + fi + + build_tar + cd $current_path + + if [ $deb == "yes" ]; then + echo "Building deb package..." + build_deb + fi + + if [ $rpm == "yes" ]; then + echo "Building rpm package..." + build_rpm + fi + + if [ "$tar" == "no" ]; then + echo "Removing tar package..." + rm -r $(find $output -name "*.tar.gz") + fi +} + +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 " --all-platforms Build for all platforms." + echo " --deb Build for deb." + echo " --rpm Build for rpm." + echo " --tar Build for tar." + 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 + ;; + "--all-platforms") + all_platforms="yes" + shift 1 + ;; + "--deb") + deb="yes" + shift 1 + ;; + "--rpm") + rpm="yes" + shift 1 + ;; + "--tar") + tar="yes" + shift 1 + ;; + "-o" | "--output") + if [ -n "${2}" ]; then + output="${2}" + shift 2 + fi + ;; + *) + echo "help" + + help 1 + ;; + esac + done + + if [ -z "$app" ] | [ -z "$base" ] | [ -z "$security" ] | [ -z "$version" ]; then + echo "You must specify the app, base, security and version." + help 1 + fi + + if [ "$all_platforms" == "no" ] && [ "$deb" == "no" ] && [ "$rpm" == "no" ] && [ "$tar" == "no" ]; then + echo "You must specify at least one package to build." + help 1 + fi + + build || exit 1 + + exit 0 +} + +main "$@" diff --git a/dev_tools/build_packages/config/default b/dev-tools/build-packages/config/default similarity index 100% rename from dev_tools/build_packages/config/default rename to dev-tools/build-packages/config/default diff --git a/dev_tools/build_packages/config/wazuh_dashboard b/dev-tools/build-packages/config/wazuh-dashboard similarity index 100% rename from dev_tools/build_packages/config/wazuh_dashboard rename to dev-tools/build-packages/config/wazuh-dashboard diff --git a/dev_tools/build_packages/config/wazuh_dashboard.service b/dev-tools/build-packages/config/wazuh-dashboard.service similarity index 100% rename from dev_tools/build_packages/config/wazuh_dashboard.service rename to dev-tools/build-packages/config/wazuh-dashboard.service diff --git a/dev_tools/build_packages/deb/builder.sh b/dev-tools/build-packages/deb/builder.sh similarity index 95% rename from dev_tools/build_packages/deb/builder.sh rename to dev-tools/build-packages/deb/builder.sh index f5cf7400c753..681623489fa9 100755 --- a/dev_tools/build_packages/deb/builder.sh +++ b/dev-tools/build-packages/deb/builder.sh @@ -27,7 +27,7 @@ deb_file="${target}_${version}-${revision}_${architecture}.deb" mkdir -p ${source_dir}/debian # Including spec file -cp -r /root/build_packages/deb/debian/* ${source_dir}/debian/ +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}" diff --git a/dev_tools/build_packages/deb/debian/changelog b/dev-tools/build-packages/deb/debian/changelog similarity index 100% rename from dev_tools/build_packages/deb/debian/changelog rename to dev-tools/build-packages/deb/debian/changelog diff --git a/dev_tools/build_packages/deb/debian/control b/dev-tools/build-packages/deb/debian/control similarity index 100% rename from dev_tools/build_packages/deb/debian/control rename to dev-tools/build-packages/deb/debian/control diff --git a/dev_tools/build_packages/deb/debian/copyright b/dev-tools/build-packages/deb/debian/copyright similarity index 100% rename from dev_tools/build_packages/deb/debian/copyright rename to dev-tools/build-packages/deb/debian/copyright diff --git a/dev_tools/build_packages/deb/debian/postinst b/dev-tools/build-packages/deb/debian/postinst similarity index 100% rename from dev_tools/build_packages/deb/debian/postinst rename to dev-tools/build-packages/deb/debian/postinst diff --git a/dev_tools/build_packages/deb/debian/postrm b/dev-tools/build-packages/deb/debian/postrm similarity index 100% rename from dev_tools/build_packages/deb/debian/postrm rename to dev-tools/build-packages/deb/debian/postrm diff --git a/dev_tools/build_packages/deb/debian/preinst b/dev-tools/build-packages/deb/debian/preinst similarity index 100% rename from dev_tools/build_packages/deb/debian/preinst rename to dev-tools/build-packages/deb/debian/preinst diff --git a/dev_tools/build_packages/deb/debian/prerm b/dev-tools/build-packages/deb/debian/prerm similarity index 100% rename from dev_tools/build_packages/deb/debian/prerm rename to dev-tools/build-packages/deb/debian/prerm diff --git a/dev_tools/build_packages/deb/debian/rules b/dev-tools/build-packages/deb/debian/rules similarity index 100% rename from dev_tools/build_packages/deb/debian/rules rename to dev-tools/build-packages/deb/debian/rules diff --git a/dev_tools/build_packages/deb/docker/amd64/Dockerfile b/dev-tools/build-packages/deb/docker/amd64/Dockerfile similarity index 100% rename from dev_tools/build_packages/deb/docker/amd64/Dockerfile rename to dev-tools/build-packages/deb/docker/amd64/Dockerfile diff --git a/dev_tools/build_packages/deb/launcher.sh b/dev-tools/build-packages/deb/launcher.sh similarity index 98% rename from dev_tools/build_packages/deb/launcher.sh rename to dev-tools/build-packages/deb/launcher.sh index 8e75a5e25a79..090bcb96a71b 100755 --- a/dev_tools/build_packages/deb/launcher.sh +++ b/dev-tools/build-packages/deb/launcher.sh @@ -96,7 +96,9 @@ build_deb() { fi # Build the Debian package with a Docker container - mkdir -p $out_dir + 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 \ diff --git a/dev_tools/build_packages/rpm/builder.sh b/dev-tools/build-packages/rpm/builder.sh similarity index 95% rename from dev_tools/build_packages/rpm/builder.sh rename to dev-tools/build-packages/rpm/builder.sh index 53c102771a5e..f71f9476d038 100755 --- a/dev_tools/build_packages/rpm/builder.sh +++ b/dev-tools/build-packages/rpm/builder.sh @@ -31,7 +31,7 @@ mkdir -p ${rpm_build_dir}/{BUILD,BUILDROOT,RPMS,SOURCES,SPECS,SRPMS} mkdir ${build_dir}/${pkg_name} # Including spec file -cp /root/build_packages/rpm/${target}.spec ${rpm_build_dir}/SPECS/${pkg_name}.spec +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}" diff --git a/dev_tools/build_packages/rpm/docker/x86_64/Dockerfile b/dev-tools/build-packages/rpm/docker/x86_64/Dockerfile similarity index 100% rename from dev_tools/build_packages/rpm/docker/x86_64/Dockerfile rename to dev-tools/build-packages/rpm/docker/x86_64/Dockerfile diff --git a/dev_tools/build_packages/rpm/launcher.sh b/dev-tools/build-packages/rpm/launcher.sh similarity index 98% rename from dev_tools/build_packages/rpm/launcher.sh rename to dev-tools/build-packages/rpm/launcher.sh index f5555e4bd5a5..ca9a67d4c1c4 100755 --- a/dev_tools/build_packages/rpm/launcher.sh +++ b/dev-tools/build-packages/rpm/launcher.sh @@ -98,7 +98,10 @@ build_rpm() { fi # Build the RPM package with a Docker container - mkdir -p $out_dir + + 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 \ diff --git a/dev_tools/build_packages/rpm/wazuh_dashboard.spec b/dev-tools/build-packages/rpm/wazuh-dashboard.spec similarity index 99% rename from dev_tools/build_packages/rpm/wazuh_dashboard.spec rename to dev-tools/build-packages/rpm/wazuh-dashboard.spec index 2c70fbfb3eb7..39e5c924d453 100644 --- a/dev_tools/build_packages/rpm/wazuh_dashboard.spec +++ b/dev-tools/build-packages/rpm/wazuh-dashboard.spec @@ -386,6 +386,7 @@ rm -fr %{buildroot} %attr(640, %{USER}, %{GROUP}) "%{INSTALL_DIR}/LICENSE.txt" %attr(640, %{USER}, %{GROUP}) "%{INSTALL_DIR}/NOTICE.txt" %attr(640, %{USER}, %{GROUP}) "%{INSTALL_DIR}/README.txt" +%attr(750, %{USER}, %{GROUP}) "%{INSTALL_DIR}/bin/use_node" %attr(750, %{USER}, %{GROUP}) "%{INSTALL_DIR}/bin/opensearch-dashboards" %attr(750, %{USER}, %{GROUP}) "%{INSTALL_DIR}/bin/opensearch-dashboards-plugin" %attr(750, %{USER}, %{GROUP}) "%{INSTALL_DIR}/bin/opensearch-dashboards-keystore" diff --git a/dev_tools/install_docker_dev.sh b/dev-tools/install-docker-dev.sh similarity index 100% rename from dev_tools/install_docker_dev.sh rename to dev-tools/install-docker-dev.sh diff --git a/dev_tools/signoff_check.sh b/dev-tools/signoff-check.sh similarity index 100% rename from dev_tools/signoff_check.sh rename to dev-tools/signoff-check.sh diff --git a/src/dev/precommit_hook/casing_check_config.js b/src/dev/precommit_hook/casing_check_config.js index 53dc1869bd52..eb3ceff6f9e8 100644 --- a/src/dev/precommit_hook/casing_check_config.js +++ b/src/dev/precommit_hook/casing_check_config.js @@ -66,7 +66,7 @@ export const IGNORE_FILE_GLOBS = [ 'packages/opensearch-safer-lodash-set/**/*', // TODO fix file names in APM to remove these - + 'dev-tools/**/*', // packages for the ingest manager's api integration tests could be valid semver which has dashes ]; @@ -102,6 +102,7 @@ export const IGNORE_DIRECTORY_GLOBS = [ 'test/functional/fixtures/opensearch_archiver/visualize_source-filters', 'packages/osd-pm/src/utils/__fixtures__/*', 'src/dev/build/tasks/__fixtures__/*', + 'dev-tools/*', ]; /**