Skip to content

Commit

Permalink
Add Dockerfile to obtain the necessary files locally (#391)
Browse files Browse the repository at this point in the history
  • Loading branch information
yenienserrano authored Nov 5, 2024
1 parent 71b85b8 commit 1627daa
Show file tree
Hide file tree
Showing 10 changed files with 243 additions and 56 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
37 changes: 37 additions & 0 deletions dev-tools/build-packages/base-packages-to-base/README.md
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
@@ -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
16 changes: 16 additions & 0 deletions dev-tools/build-packages/base-packages-to-base/clone-plugins.sh
Original file line number Diff line number Diff line change
@@ -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



22 changes: 22 additions & 0 deletions dev-tools/build-packages/base-packages-to-base/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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
'
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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 <url/path> Set the Wazuh plugin branch."
echo " -b, --base <url/path> Set the wazuh-dashboard branch."
echo " -s, --security <url/path> Set the wazuh-security-dashboards-plugin branch."
echo " --arm [Optional] Build for arm64 instead of x64."
echo " --node-version <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 "$@"
56 changes: 0 additions & 56 deletions dev-tools/build-packages/wazuh-dashboard.Dockerfile

This file was deleted.

0 comments on commit 1627daa

Please sign in to comment.