Skip to content

Commit 294ff7f

Browse files
committed
Add docker compose environment (#66)
* Add very basic Docker environment That will do for now * Add latest changes * Update Docker environment - Remove build.md which was included by mistake. - Improve dev.sh script. - Update .gitignore to exclude artifacts folder. - Create .dockerignore file. - Replace get_version.sh script with inline command. - Reduce image size by using alpine as base image. --------- Signed-off-by: Álex Ruiz <[email protected]>
1 parent 6b05fe5 commit 294ff7f

File tree

5 files changed

+238
-0
lines changed

5 files changed

+238
-0
lines changed

docker/README.md

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Frontend development environments
2+
3+
Install [Docker Desktop][docker-desktop] as per its instructions, available for Windows, Mac
4+
and Linux (Ubuntu, Debian & Fedora).
5+
This ensures that the development experience between Linux, Mac and Windows is as
6+
similar as possible.
7+
8+
> IMPORTANT: be methodic during the installation of Docker Desktop, and proceed
9+
> step by step as described in their documentation. Make sure that your system
10+
> meets the system requirements before installing Docker Desktop, and read any
11+
> post-installation note, specially on Linux: [Differences between
12+
> Docker Desktop for Linux and Docker Engine][docker-variant].
13+
14+
## Pre-requisites
15+
16+
1. Assign resources to [Docker Desktop][docker-desktop]. The requirements for the
17+
environments are:
18+
19+
- 8 GB of RAM (minimum)
20+
- 4 cores
21+
22+
The more resources the better ☺
23+
24+
2. Clone the [wazuh-indexer][wi-repo].
25+
26+
3. Set up user permissions
27+
28+
The Docker volumes will be created by the internal Docker user, making them
29+
read-only. To prevent this, a new group named `docker-desktop` and GUID 100999
30+
needs to be created, then added to your user and the source code folder:
31+
32+
```bash
33+
sudo groupadd -g 100999 docker-desktop
34+
sudo useradd -u 100999 -g 100999 -M docker-desktop
35+
sudo chown -R docker-desktop:docker-desktop $WZD_HOME
36+
sudo usermod -aG docker-desktop $USER
37+
```
38+
39+
## Understanding Docker contexts
40+
41+
Before we begin starting Docker containers, we need to understand the
42+
differences between Docker Engine and Docker Desktop, more precisely, that the
43+
use different contexts.
44+
45+
Carefully read these two sections of the Docker documentation:
46+
47+
- [Differences between Docker Desktop for Linux and Docker Engine][docker-variant].
48+
- [Switch between Docker Desktop and Docker Engine][docker-context].
49+
50+
Docker Desktop will change to its context automatically at start, so be sure
51+
that any existing Docker container using the default context is **stopped**
52+
before starting Docker Desktop and any of the environments in this folder.
53+
54+
## Starting up the environments
55+
56+
Use the sh script to up the environment.
57+
58+
Example:
59+
60+
```bash
61+
Usage: ./dev.sh {up|down|stop} [security]
62+
```
63+
64+
Once the `wazuh-indexer` container is up, attach a shell to it and run `./gradlew run`
65+
to start the application.
66+
67+
68+
[docker-desktop]: https://docs.docker.com/get-docker
69+
[docker-variant]: https://docs.docker.com/desktop/install/linux-install/#differences-between-docker-desktop-for-linux-and-docker-engine
70+
[docker-context]: https://docs.docker.com/desktop/install/linux-install/#context
71+
[wi-repo]: https://github.com/wazuh/wazuh-indexer

docker/dev.sh

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/bin/bash
2+
3+
# Attaches the project as a volume to a JDK 17 container
4+
# Requires Docker
5+
# Script usage: bash ./dev.sh
6+
7+
set -e
8+
9+
# ====
10+
# Checks that the script is run from the intended location
11+
# ====
12+
function check_project_root_folder () {
13+
if [[ "$0" != "./dev.sh" && "$0" != "dev.sh" ]]; then
14+
echo "Run the script from its location"
15+
usage
16+
exit 1
17+
fi
18+
# Change working directory to the root of the repository
19+
cd ..
20+
}
21+
22+
# ====
23+
# Displays usage
24+
# ====
25+
function usage() {
26+
echo "Usage: ./dev.sh {up|down|stop}"
27+
}
28+
29+
# ====
30+
# Main function
31+
# ====
32+
function main() {
33+
check_project_root_folder "$@"
34+
compose_file=docker/dev.yml
35+
compose_cmd="docker compose -f $compose_file"
36+
REPO_PATH=$(pwd)
37+
VERSION=$(cat VERSION)
38+
export REPO_PATH
39+
export VERSION
40+
41+
case $1 in
42+
up)
43+
$compose_cmd up -d
44+
;;
45+
down)
46+
$compose_cmd down
47+
;;
48+
stop)
49+
$compose_cmd stop
50+
;;
51+
*)
52+
usage
53+
exit 1
54+
;;
55+
esac
56+
}
57+
58+
main "$@"

docker/dev.yml

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
version: "3.9"
2+
3+
services:
4+
5+
wazuh-indexer:
6+
image: wazuh-indexer-dev:${VERSION}
7+
container_name: wazuh-indexer-dev-${VERSION}
8+
build:
9+
context: ./..
10+
dockerfile: ${REPO_PATH}/docker/images/wi-dev.Dockerfile
11+
ports:
12+
# OpenSearch REST API
13+
- 9200:9200
14+
# Cross-cluster search
15+
# - 9250:9250
16+
# Node communication and transport
17+
# - 9300:9300
18+
# Performance Analyzer
19+
# - 9600:9600
20+
expose:
21+
- 9200
22+
volumes:
23+
- ${REPO_PATH}:/home/wazuh-indexer/app
24+
entrypoint: ['tail', '-f', '/dev/null']
25+
user: "1000:1000"
26+
working_dir: /home/wazuh-indexer/app

docker/images/.dockerignore

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
artifacts/
2+
3+
# intellij files
4+
.idea/
5+
*.iml
6+
*.ipr
7+
*.iws
8+
build-idea/
9+
out/
10+
11+
# include shared intellij config
12+
!.idea/inspectionProfiles/Project_Default.xml
13+
!.idea/runConfigurations/Debug_OpenSearch.xml
14+
!.idea/vcs.xml
15+
16+
# These files are generated in the main tree by annotation processors
17+
benchmarks/src/main/generated/*
18+
benchmarks/bin/*
19+
benchmarks/build-eclipse-default/*
20+
server/bin/*
21+
server/build-eclipse-default/*
22+
test/framework/build-eclipse-default/*
23+
24+
# eclipse files
25+
.project
26+
.classpath
27+
.settings
28+
build-eclipse/
29+
30+
# netbeans files
31+
nb-configuration.xml
32+
nbactions.xml
33+
34+
# gradle stuff
35+
.gradle/
36+
build/
37+
38+
# vscode stuff
39+
.vscode/
40+
41+
# testing stuff
42+
**/.local*
43+
.vagrant/
44+
/logs/
45+
46+
# osx stuff
47+
.DS_Store
48+
49+
# default folders in which the create_bwc_index.py expects to find old es versions in
50+
/backwards
51+
/dev-tools/backwards
52+
53+
# needed in case docs build is run...maybe we can configure doc build to generate files under build?
54+
html_docs
55+
56+
# random old stuff that we should look at the necessity of...
57+
/tmp/
58+
eclipse-build
59+
60+
# projects using testfixtures
61+
testfixtures_shared/
62+
63+
# These are generated from .ci/jobs.t
64+
.ci/jobs/
65+
66+
# build files generated
67+
doc-tools/missing-doclet/bin/

docker/images/wi-dev.Dockerfile

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
FROM gradle:jdk17-alpine AS builder
2+
USER gradle
3+
WORKDIR /home/wazuh-indexer/app
4+
COPY --chown=gradle:gradle . /home/wazuh-indexer/app
5+
RUN gradle clean
6+
7+
8+
FROM eclipse-temurin:17-jdk-alpine
9+
RUN addgroup -g 1000 wazuh-indexer && \
10+
adduser -u 1000 -G wazuh-indexer -D -h /home/wazuh-indexer wazuh-indexer && \
11+
chmod 0775 /home/wazuh-indexer && \
12+
chown -R 1000:0 /home/wazuh-indexer
13+
USER wazuh-indexer
14+
COPY --from=builder --chown=1000:0 /home/wazuh-indexer/app /home/wazuh-indexer/app
15+
WORKDIR /home/wazuh-indexer/app
16+
EXPOSE 9200 9300

0 commit comments

Comments
 (0)