Skip to content

Commit

Permalink
Add install-plugins and entrypoint to wzd.dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
yenienserrano committed Oct 30, 2024
1 parent 8ecae44 commit 8d68801
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 47 deletions.
40 changes: 40 additions & 0 deletions dev-tools/build-dev-image/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
## Images

To setup the crendentials (**this only has to be done once**):

1. Login to Quay.io and navigate to User Settings.
2. Click on `CLI Password: Generate Encrypted Password`
3. In the new window that opens, click on `Docker Configuration` and follow the steps.

To build an image, use the docker build command like:

Use the `--build-arg` flag to specify the version of Node and the version of
the platform. The version of Node to use is defined in the `.nvmrc` file. Use
the Node version defined in that file for the target platform version, as the
version of Node might be increased between platfform's versions.

For example, to build the image for OpenSearch Dashboards `5.0.0`:

```bash
# Usage:
docker build \
--build-arg NODE_VERSION=18.19.0 \
--build-arg OPENSEARCH_DASHBOARD_VERSION=2.17.1.0 \
--build-arg WAZUH_DASHBOARD_BRANCH=5.0.0 \
--build-arg WAZUH_DASHBOARD_SECURITY_BRANCH=5.0.0 \
--build-arg WAZUH_DASHBOARD_REPORTING_BRANCH=5.0.0 \
--build-arg WAZUH_DASHBOARD_PLUGINS_BRANCH=5.0.0 \
-t quay.io/wazuh/osd-dev:2.17.1 \
-f wzd.dockerfile .
```

For arm architecture if you have amd architecture you need to add `--platform linux/arm64` and if you have arm for amd architecture you need to add `--platform linux/amd64`

Push the image to Quay:

```bash
docker push quay.io/wazuh/image-name:version
```

If you're creating a new image, copy one of the ones already present
in the directory, and adapt it to the new version.
38 changes: 8 additions & 30 deletions dev-tools/build-dev-image/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,34 +1,12 @@
plugins=$(cat /home/node/plugins)
wazuh_dashboard_plugins=$(cat /home/node/wazuh-dashboard-plugins)
#!/bin/bash
base_path_plugins="/home/node/kbn/plugins"
plugins=$(ls $base_path_plugins)
for plugin in $plugins; do
echo "Cloning $plugin"
cd /home/node/kbn/plugins
if [[ $plugin =~ wazuh* ]]; then

if [[ $plugin == "wazuh-security-dashboards-plugin" ]]; then
git clone --depth 1 --branch ${WAZUH_DASHBOARD_SECURITY_BRANCH} https://github.com/wazuh/$plugin.git
fi

if [[ $plugin == "wazuh-dashboards-reporting" ]]; then
git clone --depth 1 --branch ${WAZUH_DASHBOARD_REPORTING_BRANCH} https://github.com/wazuh/$plugin.git
fi

if [[ $plugin == "wazuh-dashboard-plugins" ]]; then
git clone --depth 1 --branch ${WAZUH_DASHBOARD_PLUGINS_BRANCH} https://github.com/wazuh/$plugin.git
mv $plugin/plugins/* ./
for wazuh_dashboard_plugin in $wazuh_dashboard_plugins; do
cd /home/node/kbn/plugins/$wazuh_dashboard_plugin
yarn install
done
cd /home/node/kbn/plugins
rm -rf $plugin
fi

else
git clone --depth 1 --branch ${OPENSEARCH_DASHBOARD_VERSION} https://github.com/opensearch-project/$plugin.git
fi
if [[ $plugin != "wazuh-dashboard-plugins" ]]; then
cd $plugin
if [ ! -d "$base_path_plugins/$plugin/node_modules" ]; then
cd $base_path_plugins/$plugin
echo "Installing dependencies for $plugin"
yarn install
fi
done

tail -f /dev/null
63 changes: 63 additions & 0 deletions dev-tools/build-dev-image/install-plugins.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
plugins=$(cat /home/node/plugins)
base_path_plugins="/home/node/kbn/plugins"
category_explore="id: 'explore',label: 'Explore',order: 100,euiIconType: 'search',"
category_dashboard_management='{id:"management",label:"Indexer management",order:5e3,euiIconType:"managementApp"}'
old_category_default="DEFAULT_APP_CATEGORIES\.management,"
old_category_object="id: 'opensearch',/{
N
N
s/id: 'opensearch',\n\s*label: 'OpenSearch Plugins',\n\s*order: 2000,"
for plugin in $plugins; do
cd $base_path_plugins
if [[ $plugin =~ wazuh* ]]; then
# Clone the Wazuh security plugin
if [[ $plugin == "wazuh-security-dashboards-plugin" ]]; then
git clone --depth 1 --branch ${WAZUH_DASHBOARD_SECURITY_BRANCH} https://github.com/wazuh/$plugin.git
fi
# Clone the Wazuh dashboards reporting plugin
if [[ $plugin == "wazuh-dashboards-reporting" ]]; then
git clone --depth 1 --branch ${WAZUH_DASHBOARD_REPORTING_BRANCH} https://github.com/wazuh/$plugin.git
fi
# Clone the Wazuh dashboards plugins and move the plugins to the plugins folder
if [[ $plugin == "wazuh-dashboard-plugins" ]]; then
git clone --depth 1 --branch ${WAZUH_DASHBOARD_PLUGINS_BRANCH} https://github.com/wazuh/$plugin.git
wazuh_dashboard_plugins=$(ls $base_path_plugins/$plugin/plugins)
mv $plugin/plugins/* ./
for wazuh_dashboard_plugin in $wazuh_dashboard_plugins; do
cd $base_path_plugins/$wazuh_dashboard_plugin
yarn install
done
cd $base_path_plugins
rm -rf $plugin
fi

else
git clone --depth 1 --branch ${OPENSEARCH_DASHBOARD_VERSION} https://github.com/opensearch-project/$plugin.git
cd $base_path_plugins/$plugin/public

# Notification plugin: Modify the plugin.ts file to add the Explore category
if [[ $plugin == "dashboards-notifications" ]]; then
sed -i -e "s/${old_category_default}/{${category_explore}},/g" ./plugin.ts
fi

# Alerting plugin: Modify the plugin.ts file to add the Explore category
if [[ $plugin == "alerting-dashboards-plugin" ]]; then
sed -i -e "/${old_category_object}/${category_explore}/}" plugin.tsx
fi

# Maps plugin: Modify the plugin.ts file to add the Explore category
if [[ $plugin == "dashboards-maps" ]]; then
sed -i -e "/${old_category_object}/${category_explore}/}" plugin.tsx
fi

# Index Management plugin: Modify the plugin.ts file to add the Explore category
if [[ $plugin == "index-management-dashboards-plugin" ]]; then
sed -i -e "s/${old_category_default}/${category_dashboard_management},/g" ./plugin.ts
fi

fi
if [[ $plugin != "wazuh-dashboard-plugins" ]]; then
cd $base_path_plugins/$plugin
yarn install
fi
done
4 changes: 2 additions & 2 deletions dev-tools/build-dev-image/plugins
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
dashboards-notifications
alerting-dashboards-plugin
dashboards-maps.git
index-management-dashboards-plugin.git
dashboards-maps
index-management-dashboards-plugin
dashboards-visualizations
dashboards-observability
wazuh-security-dashboards-plugin
Expand Down
5 changes: 0 additions & 5 deletions dev-tools/build-dev-image/wazuh-dashboard-plugins

This file was deleted.

17 changes: 7 additions & 10 deletions dev-tools/build-dev-image/wzd.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,17 @@ RUN yarn osd bootstrap --production

WORKDIR /home/node/kbn/plugins

ADD ./entrypoint.sh /home/node/entrypoint.sh
ADD ./install-plugins.sh /home/node/install-plugins.sh
ADD ./plugins /home/node/plugins
ADD ./wazuh-dashboard-plugins /home/node/wazuh-dashboard-plugins

USER root
RUN chmod +x /home/node/entrypoint.sh
USER node
ENTRYPOINT ["/home/node/entrypoint.sh"]

RUN bash /home/node/entrypoint.sh

RUN bash /home/node/install-plugins.sh
RUN mkdir -p /home/node/kbn/data/wazuh/config

FROM node:${NODE_VERSION}
USER node
COPY --chown=node:node --from=base /home/node/kbn /home/node/kbn
WORKDIR /home/node/kbn
ADD ./entrypoint.sh /home/node/entrypoint.sh
USER root
RUN chmod +x /home/node/entrypoint.sh
USER node
ENTRYPOINT [ "/home/node/entrypoint.sh" ]

0 comments on commit 8d68801

Please sign in to comment.