Skip to content

Commit

Permalink
Get Wazuh version from VERSION file (#122)
Browse files Browse the repository at this point in the history
* Add function to look for VERSION in the correct path

* Update assemble.sh

Adds wget as dependency

* Download files using curl instead of wget

* Update assemble.sh

Revert assembly with minimal plugins for testing

Signed-off-by: Álex Ruiz <[email protected]>

* Add Dockerfile and docker-compose for the package assembly stage

* Assemble packages with minimal plugin set when "test" variable is set to "true"

* Update README with assemble.sh docker image

* Fixing env variable naming convention and removing wget dependency

* Improve Docker environments

Adds environments to build packages

* Fix small typos

* More fixes

* Add documentation

* Adding -p flag to mkdir so it doesnt fail when the folder is already present

* Format files

---------

Signed-off-by: Álex Ruiz <[email protected]>
Co-authored-by: Álex Ruiz <[email protected]>
  • Loading branch information
f-galland and AlexRuiz7 committed Sep 9, 2024
1 parent 828c2f8 commit 1ba2351
Show file tree
Hide file tree
Showing 13 changed files with 283 additions and 121 deletions.
17 changes: 13 additions & 4 deletions docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,28 @@ Docker Desktop will change to its context automatically at start, so be sure
that any existing Docker container using the default context is **stopped**
before starting Docker Desktop and any of the environments in this folder.

## Starting up the environments
## Development environments

Use the sh script to up the environment.
Use the `dev/dev.sh` script to start a development environment.

Example:

```bash
Usage: ./dev.sh {up|down|stop} [security]
Usage: ./dev.sh {up|down|stop}
```

Once the `wazuh-indexer` container is up, attach a shell to it and run `./gradlew run`
Once the `wi-dev:x.y.z` container is up, attach a shell to it and run `./gradlew run`
to start the application.

## Containers to generate packages

Use the `ci/ci.sh` script to start provisioned containers to generate packages.

```bash
Usage: ./ci.sh {up|down|stop} [ci]
```

Refer to [scripts/README.md](../scripts/README.md) for details about how to build packages.

[docker-desktop]: https://docs.docker.com/get-docker
[docker-variant]: https://docs.docker.com/desktop/install/linux-install/#differences-between-docker-desktop-for-linux-and-docker-engine
Expand Down
62 changes: 62 additions & 0 deletions docker/ci/ci.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/bin/bash

# Start container with required tools to build packages
# Requires Docker
# Script usage: bash ./ci.sh

set -e

# ====
# Checks that the script is run from the intended location
# ====
function check_project_root_folder() {
current=$(basename "$(pwd)")

if [[ "$0" != "./ci.sh" && "$0" != "ci.sh" ]]; then
echo "Run the script from its location"
usage
exit 1
fi
# Change working directory to the root of the repository
cd ../..
}

# ====
# Displays usage
# ====
function usage() {
echo "Usage: ./ci.sh {up|down|stop}"
}

# ====
# Main function
# ====
function main() {
check_project_root_folder "$@"
compose_file="docker/${current}/ci.yml"
compose_cmd="docker compose -f $compose_file"
REPO_PATH=$(pwd)
VERSION=$(cat VERSION)
export REPO_PATH
export VERSION

case $1 in
up)
# Main folder created here to grant access to both containers
mkdir -p artifacts
$compose_cmd up -d
;;
down)
$compose_cmd down
;;
stop)
$compose_cmd stop
;;
*)
usage
exit 1
;;
esac
}

main "$@"
29 changes: 29 additions & 0 deletions docker/ci/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
version: "3.9"

services:
# Essentially wi-dev, but doesn't expose port 9200
wi-build:
image: wi-build:${VERSION}
container_name: wi-build_${VERSION}
build:
context: ./../..
dockerfile: ${REPO_PATH}/docker/dev/images/Dockerfile
volumes:
- ${REPO_PATH}:/home/wazuh-indexer
entrypoint: ["tail", "-f", "/dev/null"]
user: "1000:1000"
working_dir: /home/wazuh-indexer

wi-assemble:
image: wi-assemble:${VERSION}
container_name: wi-assemble_${VERSION}
build:
context: ./../..
dockerfile: ${REPO_PATH}/docker/ci/images/Dockerfile
volumes:
- ${REPO_PATH}/scripts:/home/wazuh-indexer/scripts
- ${REPO_PATH}/artifacts:/home/wazuh-indexer/artifacts
- ${REPO_PATH}/distribution/packages/src:/home/wazuh-indexer/distribution/packages/src
entrypoint: ["tail", "-f", "/dev/null"]
user: "1000:1000"
working_dir: /home/wazuh-indexer
File renamed without changes.
17 changes: 17 additions & 0 deletions docker/ci/images/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM ubuntu:jammy
RUN mkdir /home/wazuh-indexer && \
apt-get update -y && \
apt-get install curl gnupg2 -y && \
curl -o- https://www.aptly.info/pubkey.txt | apt-key add - && \
echo "deb http://repo.aptly.info/ squeeze main" | tee -a /etc/apt/sources.list.d/aptly.list && \
apt-get update -y && \
apt-get upgrade -y && \
apt-get install -y aptly build-essential cpio debhelper-compat debmake freeglut3 libasound2 libatk-bridge2.0-0 libatk1.0-0 libatspi2.0-dev libcairo2 libcairo2-dev libcups2 libdrm2 libgbm-dev libgconf-2-4 libnspr4 libnspr4-dev libnss3 libpangocairo-1.0-0 libxcomposite-dev libxdamage1 libxfixes-dev libxfixes3 libxi6 libxkbcommon-x11-0 libxrandr2 libxrender1 libxtst6 rpm rpm2cpio && \
apt-get clean -y && \
dpkg -r lintian && \
addgroup --gid 1000 wazuh-indexer && \
adduser --uid 1000 --ingroup wazuh-indexer --disabled-password --home /home/wazuh-indexer wazuh-indexer && \
chmod 0775 /home/wazuh-indexer && \
chown -R 1000:1000 /home/wazuh-indexer
USER wazuh-indexer
WORKDIR /home/wazuh-indexer
26 changes: 0 additions & 26 deletions docker/dev.yml

This file was deleted.

12 changes: 7 additions & 5 deletions docker/dev.sh → docker/dev/dev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@ set -e
# ====
# Checks that the script is run from the intended location
# ====
function check_project_root_folder () {
function check_project_root_folder() {
current=$(basename "$(pwd)")

if [[ "$0" != "./dev.sh" && "$0" != "dev.sh" ]]; then
echo "Run the script from its location"
echo "Run the script from its location"
usage
exit 1
fi
# Change working directory to the root of the repository
cd ..
cd ../..
}

# ====
Expand All @@ -31,7 +33,7 @@ function usage() {
# ====
function main() {
check_project_root_folder "$@"
compose_file=docker/dev.yml
compose_file="docker/${current}/dev.yml"
compose_cmd="docker compose -f $compose_file"
REPO_PATH=$(pwd)
VERSION=$(cat VERSION)
Expand All @@ -55,4 +57,4 @@ function main() {
esac
}

main "$@"
main "$@"
19 changes: 19 additions & 0 deletions docker/dev/dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
version: "3.9"

services:
wi-dev:
image: wi-dev:${VERSION}
container_name: wi-dev_${VERSION}
build:
context: ./../..
dockerfile: ${REPO_PATH}/docker/dev/images/Dockerfile
ports:
# OpenSearch REST API
- 9200:9200
expose:
- 9200
volumes:
- ${REPO_PATH}:/home/wazuh-indexer
entrypoint: ["tail", "-f", "/dev/null"]
user: "1000:1000"
working_dir: /home/wazuh-indexer
68 changes: 68 additions & 0 deletions docker/dev/images/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
artifacts/
.git/

# intellij files
.idea/
*.iml
*.ipr
*.iws
build-idea/
out/

# include shared intellij config
!.idea/inspectionProfiles/Project_Default.xml
!.idea/runConfigurations/Debug_OpenSearch.xml
!.idea/vcs.xml

# These files are generated in the main tree by annotation processors
benchmarks/src/main/generated/*
benchmarks/bin/*
benchmarks/build-eclipse-default/*
server/bin/*
server/build-eclipse-default/*
test/framework/build-eclipse-default/*

# eclipse files
.project
.classpath
.settings
build-eclipse/

# netbeans files
nb-configuration.xml
nbactions.xml

# gradle stuff
.gradle/
build/

# vscode stuff
.vscode/

# testing stuff
**/.local*
.vagrant/
/logs/

# osx stuff
.DS_Store

# default folders in which the create_bwc_index.py expects to find old es versions in
/backwards
/dev-tools/backwards

# needed in case docs build is run...maybe we can configure doc build to generate files under build?
html_docs

# random old stuff that we should look at the necessity of...
/tmp/
eclipse-build

# projects using testfixtures
testfixtures_shared/

# These are generated from .ci/jobs.t
.ci/jobs/

# build files generated
doc-tools/missing-doclet/bin/
10 changes: 5 additions & 5 deletions docker/images/wi-dev.Dockerfile → docker/dev/images/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM gradle:jdk17-alpine AS builder
USER gradle
WORKDIR /home/wazuh-indexer/app
COPY --chown=gradle:gradle . /home/wazuh-indexer/app
WORKDIR /home/wazuh-indexer
COPY --chown=gradle:gradle . /home/wazuh-indexer
RUN gradle clean


Expand All @@ -12,7 +12,7 @@ RUN apk add git && \
chmod 0775 /home/wazuh-indexer && \
chown -R 1000:0 /home/wazuh-indexer
USER wazuh-indexer
COPY --from=builder --chown=1000:0 /home/wazuh-indexer/app /home/wazuh-indexer/app
WORKDIR /home/wazuh-indexer/app
RUN git config --global --add safe.directory /home/wazuh-indexer/app
COPY --from=builder --chown=1000:0 /home/wazuh-indexer /home/wazuh-indexer
WORKDIR /home/wazuh-indexer
RUN git config --global --add safe.directory /home/wazuh-indexer
EXPOSE 9200 9300
Loading

0 comments on commit 1ba2351

Please sign in to comment.