diff --git a/.gitignore b/.gitignore index b8559c25273c..7117a9591831 100644 --- a/.gitignore +++ b/.gitignore @@ -73,3 +73,6 @@ snapshots.js # Ignore the generated antlr files /src/plugins/data/public/antlr/opensearch_sql/grammar/.antlr + +# Ignore the generated packages +/dev-tools/build-packages/base-packages-to-base/packages diff --git a/dev-tools/build-packages/base-packages-to-base/README.md b/dev-tools/build-packages/base-packages-to-base/README.md new file mode 100644 index 000000000000..67a785580d0b --- /dev/null +++ b/dev-tools/build-packages/base-packages-to-base/README.md @@ -0,0 +1,37 @@ +# Package building + +This folder contains the tools used to create packages from the different repositories necessary for the creation of deb and rpm packages. + +## Requirements + +- A system with Docker. +- Internet connection (to download the docker images the first time). + +## How to build packages + +The script `run-docker-compose.sh` is in charge of coordinating the different steps to build each package. + +### Building packages + +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). + +The inputs are the following: + +- `-a`, `--app`: Set the `wazuh-dashboard-plugins` branch. +- `-b`, `--base`: Set the `wazuh-dashboard` branch. +- `-s`, `--security`: Set the `wazuh-security-dashboards-plugin` branch. +- `--node-version`: [Optional] Set the node version. +- `--arm`: [Optional] Build for arm64 instead of x64. + +Example: + +```bash +bash run-docker-compose.sh \ + --app 4.10.2 \ + --base 4.10.2 \ + --security 4.10.2 \ + --arm \ + --node-version 18.19.0 +``` + +This example will create a packages folder that inside will have the packages divided by repository of the 4.10.2 branch of each one. \ No newline at end of file diff --git a/dev-tools/build-packages/base-packages-to-base/base-packages.Dockerfile b/dev-tools/build-packages/base-packages-to-base/base-packages.Dockerfile new file mode 100644 index 000000000000..420aead16c5b --- /dev/null +++ b/dev-tools/build-packages/base-packages-to-base/base-packages.Dockerfile @@ -0,0 +1,31 @@ +# Usage: +# docker build \ +# --build-arg NODE_VERSION=18.19.0 \ +# --build-arg WAZUH_DASHBOARD_BRANCH=4.10.2 \ +# --build-arg WAZUH_DASHBOARD_SECURITY_BRANCH=4.10.2 \ +# --build-arg WAZUH_DASHBOARD_PLUGINS_BRANCH=4.10.2 \ +# --build-arg ARCHITECTURE=arm \ +# -t wazuh-packages-to-base:4.10.2 \ +# -f base-packages.Dockerfile . + +ARG NODE_VERSION=18.19.0 +FROM node:${NODE_VERSION} AS base +ARG ARCHITECTURE='amd' +ARG WAZUH_DASHBOARD_BRANCH +ARG WAZUH_DASHBOARD_SECURITY_BRANCH +ARG WAZUH_DASHBOARD_PLUGINS_BRANCH +ENV OPENSEARCH_DASHBOARDS_VERSION=2.16.0 +ENV ENV_ARCHITECTURE=${ARCHITECTURE} +USER root +RUN apt-get update && apt-get install -y jq +USER node +ADD ./clone-plugins.sh /home/node/clone-plugins.sh +ADD ./repositories/wazuh-dashboard.sh /home/node/repositories/wazuh-dashboard.sh +ADD ./repositories/plugins/wazuh-security-dashboards-plugin.sh /home/node/repositories/plugins/wazuh-security-dashboards-plugin.sh +ADD ./repositories/plugins/wazuh-dashboard-plugins.sh /home/node/repositories/plugins/wazuh-dashboard-plugins.sh +RUN bash /home/node/clone-plugins.sh + +FROM node:${NODE_VERSION} +USER node +COPY --chown=node:node --from=base /home/node/packages /home/node/packages +WORKDIR /home/node/packages diff --git a/dev-tools/build-packages/base-packages-to-base/clone-plugins.sh b/dev-tools/build-packages/base-packages-to-base/clone-plugins.sh new file mode 100644 index 000000000000..2a70c6f141fd --- /dev/null +++ b/dev-tools/build-packages/base-packages-to-base/clone-plugins.sh @@ -0,0 +1,16 @@ +base_path_plugins="/home/node/app/plugins" +base_path_repositories_scripts="/home/node/repositories" +base_path_repositories_plugins_scripts="/home/node/repositories/plugins" +plugins=$(ls $base_path_repositories_plugins_scripts) + +mkdir /home/node/packages +echo "Cloning Wazuh dashboards" +source $base_path_repositories_scripts/wazuh-dashboard.sh + +for plugin in $plugins; do + echo "Cloning $plugin" + source $base_path_repositories_plugins_scripts/$plugin +done + + + diff --git a/dev-tools/build-packages/base-packages-to-base/docker-compose.yml b/dev-tools/build-packages/base-packages-to-base/docker-compose.yml new file mode 100644 index 000000000000..06b9ea7df485 --- /dev/null +++ b/dev-tools/build-packages/base-packages-to-base/docker-compose.yml @@ -0,0 +1,22 @@ + +services: + base: + image: base-${WAZUH_DASHBOARD_BRANCH}-${WAZUH_SECURITY_PLUGIN_BRANCH}-${WAZUH_DASHBOARD_PLUGINS_BRANCH}-${ARCHITECTURE} + build: + context: . + dockerfile: base-packages.Dockerfile + args: + NODE_VERSION: ${NODE_VERSION} + WAZUH_DASHBOARD_BRANCH: ${WAZUH_DASHBOARD_BRANCH} + WAZUH_DASHBOARD_SECURITY_BRANCH: ${WAZUH_SECURITY_PLUGIN_BRANCH} + WAZUH_DASHBOARD_PLUGINS_BRANCH: ${WAZUH_DASHBOARD_PLUGINS_BRANCH} + ARCHITECTURE: ${ARCHITECTURE} + container_name: base-${WAZUH_DASHBOARD_BRANCH}-${WAZUH_SECURITY_PLUGIN_BRANCH}-${WAZUH_DASHBOARD_PLUGINS_BRANCH}-${ARCHITECTURE} + environment: + OPENSEARCH_DASHBOARDS_VERSION: 2.16.0 + volumes: + - ./:/home/node/output + command: > + bash -c ' + cp -r /home/node/packages /home/node/output + ' diff --git a/dev-tools/build-packages/base-packages-to-base/repositories/plugins/wazuh-dashboard-plugins.sh b/dev-tools/build-packages/base-packages-to-base/repositories/plugins/wazuh-dashboard-plugins.sh new file mode 100644 index 000000000000..7bde0a71da4b --- /dev/null +++ b/dev-tools/build-packages/base-packages-to-base/repositories/plugins/wazuh-dashboard-plugins.sh @@ -0,0 +1,17 @@ +base_path_plugins="/home/node/app/plugins" +cd $base_path_plugins +git clone --depth 1 --branch ${WAZUH_DASHBOARD_PLUGINS_BRANCH} https://github.com/wazuh/wazuh-dashboard-plugins.git +wazuh_dashboard_plugins=$(ls $base_path_plugins/wazuh-dashboard-plugins/plugins) +mv wazuh-dashboard-plugins/plugins/* ./ +mkdir /home/node/packages/wazuh-dashboard-plugins +for wazuh_dashboard_plugin in $wazuh_dashboard_plugins; do + cd $base_path_plugins/$wazuh_dashboard_plugin + yarn install + echo "Building $wazuh_dashboard_plugin" + yarn build + echo "Copying $wazuh_dashboard_plugin" + package_name=$(jq -r '.id' ./opensearch_dashboards.json) + cp $base_path_plugins/$wazuh_dashboard_plugin/build/$package_name-$OPENSEARCH_DASHBOARDS_VERSION.zip /home/node/packages/wazuh-dashboard-plugins/$package_name-$OPENSEARCH_DASHBOARDS_VERSION.zip +done +cd $base_path_plugins +rm -rf wazuh-dashboard-plugins diff --git a/dev-tools/build-packages/base-packages-to-base/repositories/plugins/wazuh-security-dashboards-plugin.sh b/dev-tools/build-packages/base-packages-to-base/repositories/plugins/wazuh-security-dashboards-plugin.sh new file mode 100644 index 000000000000..6ccbb4c0a5b1 --- /dev/null +++ b/dev-tools/build-packages/base-packages-to-base/repositories/plugins/wazuh-security-dashboards-plugin.sh @@ -0,0 +1,10 @@ +# Clone the Wazuh security plugin +cd /home/node/app/plugins +git clone --depth 1 --branch ${WAZUH_DASHBOARD_SECURITY_BRANCH} https://github.com/wazuh/wazuh-security-dashboards-plugin.git +cd wazuh-security-dashboards-plugin +yarn install +echo "Building Wazuh security plugin" +yarn build +echo "Copying Wazuh security plugin" +mkdir /home/node/packages/wazuh-security-dashboards-plugin +cp -r build/* /home/node/packages/wazuh-security-dashboards-plugin diff --git a/dev-tools/build-packages/base-packages-to-base/repositories/wazuh-dashboard.sh b/dev-tools/build-packages/base-packages-to-base/repositories/wazuh-dashboard.sh new file mode 100644 index 000000000000..967dd36268de --- /dev/null +++ b/dev-tools/build-packages/base-packages-to-base/repositories/wazuh-dashboard.sh @@ -0,0 +1,13 @@ +git clone --depth 1 --branch ${WAZUH_DASHBOARD_BRANCH} https://github.com/wazuh/wazuh-dashboard.git /home/node/app +cd /home/node/app +yarn osd bootstrap --production +echo "Building Wazuh dashboards" +if [ $ENV_ARCHITECTURE == "arm" ]; then + yarn build-platform --linux-arm --skip-os-packages --release +else + yarn build-platform --linux --skip-os-packages --release +fi +mkdir /home/node/packages/wazuh-dashboard +echo "Copying Wazuh dashboards" +ls -la /home/node/app/target +cp -r /home/node/app/target/*.tar.gz /home/node/packages/wazuh-dashboard diff --git a/dev-tools/build-packages/base-packages-to-base/run-docker-compose.sh b/dev-tools/build-packages/base-packages-to-base/run-docker-compose.sh new file mode 100644 index 000000000000..cdb20ccdeb11 --- /dev/null +++ b/dev-tools/build-packages/base-packages-to-base/run-docker-compose.sh @@ -0,0 +1,94 @@ +#!/bin/bash + +export WAZUH_DASHBOARD_PLUGINS_BRANCH="" +export WAZUH_DASHBOARD_BRANCH="" +export WAZUH_SECURITY_PLUGIN_BRANCH="" +export ARCHITECTURE="amd" +export NODE_VERSION="18.19.0" + + +run_docker_compose() { + echo "WAZUH_DASHBOARD_PLUGINS_BRANCH: $WAZUH_DASHBOARD_PLUGINS_BRANCH" + echo "WAZUH_SECURITY_PLUGIN_BRANCH: $WAZUH_SECURITY_PLUGIN_BRANCH" + echo "WAZUH_DASHBOARD_BRANCH: $WAZUH_DASHBOARD_BRANCH" + echo "ARCHITECTURE: $ARCHITECTURE" + echo "NODE_VERSION: $NODE_VERSION" + docker-compose up -d +} + +help() { + echo + echo "Usage: $0 [OPTIONS]" + echo " -a, --app Set the Wazuh plugin branch." + echo " -b, --base Set the wazuh-dashboard branch." + echo " -s, --security Set the wazuh-security-dashboards-plugin branch." + echo " --arm [Optional] Build for arm64 instead of x64." + echo " --node-version [Optional] Set the node version." + 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 + WAZUH_DASHBOARD_PLUGINS_BRANCH="$2" + shift 2 + else + help 1 + fi + ;; + "-s" | "--security") + if [ -n "${2}" ]; then + WAZUH_SECURITY_PLUGIN_BRANCH="${2}" + shift 2 + else + help 0 + fi + ;; + "-b" | "--base") + if [ -n "${2}" ]; then + WAZUH_DASHBOARD_BRANCH="${2}" + shift 2 + else + help 0 + fi + ;; + "--arm") + ARCHITECTURE="arm" + shift 1 + ;; + "--node-version") + if [ -n "${2}" ]; then + NODE_VERSION="${2}" + shift 2 + else + help 0 + fi + ;; + *) + echo "help" + + help 1 + ;; + esac + done + + if [ -z "$WAZUH_DASHBOARD_PLUGINS_BRANCH" ] | [ -z "$WAZUH_DASHBOARD_BRANCH" ] | [ -z "$WAZUH_SECURITY_PLUGIN_BRANCH" ]; then + echo "You must specify the app, base, security." + help 1 + fi + + run_docker_compose || exit 1 + + exit 0 +} + +main "$@" diff --git a/dev-tools/build-packages/wazuh-dashboard.Dockerfile b/dev-tools/build-packages/wazuh-dashboard.Dockerfile deleted file mode 100644 index 6f5279077491..000000000000 --- a/dev-tools/build-packages/wazuh-dashboard.Dockerfile +++ /dev/null @@ -1,56 +0,0 @@ -# Usage: docker build --build-arg NODE_VERSION=18.19.0 --build-arg WAZUH_DASHBOARDS_BRANCH=4.10.0 --build-arg WAZUH_DASHBOARDS_PLUGINS=4.10.0 --build-arg WAZUH_SECURITY_DASHBOARDS_PLUGIN_BRANCH=4.10.0 --build-arg OPENSEARCH_DASHBOARDS_VERSION=2.13.0 -t wzd:4.10.0 -f wazuh-dashboard.Dockerfile . - -ARG NODE_VERSION -FROM node:${NODE_VERSION} AS base -ARG OPENSEARCH_DASHBOARDS_VERSION -ARG WAZUH_DASHBOARDS_BRANCH -ARG WAZUH_DASHBOARDS_PLUGINS -ARG WAZUH_SECURITY_DASHBOARDS_PLUGIN_BRANCH -ENV OPENSEARCH_DASHBOARDS_VERSION=${OPENSEARCH_DASHBOARDS_VERSION} -USER root -RUN apt-get update && apt-get install -y git zip unzip curl brotli jq -USER node -RUN git clone --depth 1 --branch ${WAZUH_DASHBOARDS_BRANCH} https://github.com/wazuh/wazuh-dashboard.git /home/node/wzd -RUN chown node.node /home/node/wzd - -WORKDIR /home/node/wzd -RUN yarn osd bootstrap --production -RUN yarn build --linux --skip-os-packages --release - - -WORKDIR /home/node/wzd/plugins -RUN git clone --depth 1 --branch ${WAZUH_SECURITY_DASHBOARDS_PLUGIN_BRANCH} https://github.com/wazuh/wazuh-security-dashboards-plugin.git -RUN git clone --depth 1 --branch ${WAZUH_DASHBOARDS_PLUGINS} https://github.com/wazuh/wazuh-dashboard-plugins.git -WORKDIR /home/node/wzd/plugins/wazuh-security-dashboards-plugin -RUN yarn -RUN yarn build -WORKDIR /home/node/wzd/plugins -RUN mv ./wazuh-dashboard-plugins/plugins/main ./wazuh -RUN mv ./wazuh-dashboard-plugins/plugins/wazuh-core ./wazuh-core -RUN mv ./wazuh-dashboard-plugins/plugins/wazuh-check-updates ./wazuh-check-updates -WORKDIR /home/node/wzd/plugins/wazuh -RUN yarn -RUN yarn build -WORKDIR /home/node/wzd/plugins/wazuh-core -RUN yarn -RUN yarn build -WORKDIR /home/node/wzd/plugins/wazuh-check-updates -RUN yarn -RUN yarn build -WORKDIR /home/node/ -RUN mkdir packages -WORKDIR /home/node/packages -RUN zip -r -j ./dashboard-package.zip ../wzd/target/opensearch-dashboards-${OPENSEARCH_DASHBOARDS_VERSION}-linux-x64.tar.gz -RUN zip -r -j ./security-package.zip ../wzd/plugins/wazuh-security-dashboards-plugin/build/security-dashboards-${OPENSEARCH_DASHBOARDS_VERSION}.0.zip -RUN zip -r -j ./wazuh-package.zip ../wzd/plugins/wazuh-check-updates/build/wazuhCheckUpdates-${OPENSEARCH_DASHBOARDS_VERSION}.zip ../wzd/plugins/wazuh/build/wazuh-${OPENSEARCH_DASHBOARDS_VERSION}.zip ../wzd/plugins/wazuh-core/build/wazuhCore-${OPENSEARCH_DASHBOARDS_VERSION}.zip -WORKDIR /home/node/wzd/dev-tools/build-packages/base -RUN ./generate_base.sh -v 4.10.2 -r 1 -a file:///home/node/packages/wazuh-package.zip -s file:///home/node/packages/security-package.zip -b file:///home/node/packages/dashboard-package.zip -WORKDIR /home/node/wzd/dev-tools/build-packages/base/output -RUN cp ./* /home/node/packages/ - - -FROM node:${NODE_VERSION} -USER node -COPY --chown=node:node --from=base /home/node/wzd /home/node/wzd -COPY --chown=node:node --from=base /home/node/packages /home/node/packages -WORKDIR /home/node/wzd