diff --git a/indexer-certs-creator/README.md b/indexer-certs-creator/README.md index 8ddccdf5..04808a5d 100644 --- a/indexer-certs-creator/README.md +++ b/indexer-certs-creator/README.md @@ -1,9 +1,27 @@ -# Certificate creation image build +# Certificate Creation Image Build -The dockerfile hosted in this directory is used to build the image used to boot Wazuh's single node and multi node stacks. +The dockerfile hosted in this directory is used to build the image required for generating Wazuh Docker single-node and multi-node certificate files -To create the image, the following command must be executed: +## Pre-requisites +### QEMU + +Set up QEMU to enable building multi-architecture Docker images + +Useful documentation: + +- https://www.qemu.org/download/ +- https://docs.docker.com/build/building/multi-platform/#qemu + +## Procedure + +Run the following script to build the wazuh-certs-generator docker image + +```console +./build-image.sh -v [-m] [-rg ] ``` -$ docker build -t wazuh/wazuh-certs-generator:0.0.3 . -``` + +Replace with the new image desired tag. +Use the `-m` flag to build a multi-architecture image (supports both `amd64` and `arm64`) +Use the `-rg ` parameter to specify a custom Docker registry (default is Docker Hub) + By default, the script will attempt to push the image to the registry and will only work if credentials are properly configured. diff --git a/indexer-certs-creator/build-image.sh b/indexer-certs-creator/build-image.sh new file mode 100755 index 00000000..925d15a6 --- /dev/null +++ b/indexer-certs-creator/build-image.sh @@ -0,0 +1,102 @@ +#!/bin/bash + +# Wazuh package generator +# Copyright (C) 2023, Wazuh Inc. +# +# This program is a free software; you can redistribute it +# and/or modify it under the terms of the GNU General Public +# License (version 2) as published by the FSF - Free Software +# Foundation. + +WAZUH_CERTS_IMAGE_VERSION="0.0.4" +WAZUH_REGISTRY="docker.io" + +# ----------------------------------------------------------------------------- + +trap ctrl_c INT + +clean() { + exit_code=$1 + exit ${exit_code} +} + +ctrl_c() { + clean 1 +} + +# ----------------------------------------------------------------------------- + +build() { + IMAGE_TAG="${WAZUH_CERTS_IMAGE_VERSION}" + + echo WAZUH_REGISTRY=$WAZUH_REGISTRY > .env + echo IMAGE_TAG=$IMAGE_TAG >> .env + + set -a + source .env + set +a + + if [ "${MULTIARCH}" ]; then + docker buildx bake --file build-image.yml \ + --set *.platform=linux/amd64,linux/arm64 \ + --no-cache || clean 1 + else + docker buildx bake --file build-image.yml --no-cache || clean 1 + fi + return 0 +} + +# ----------------------------------------------------------------------------- + +help() { + echo + echo "Usage: $0 [OPTIONS]" + echo + echo " -v, --version [Optional] Set the image version. By default ${WAZUH_CERTS_IMAGE_VERSION}." + echo " -rg, --registry [Optional] Set the Docker registry to push the images." + echo " -m, --multiarch [Optional] Enable multi-architecture builds." + echo " -h, --help Show this help." + echo + exit $1 +} + +# ----------------------------------------------------------------------------- + +main() { + while [ -n "${1}" ] + do + case "${1}" in + "-h"|"--help") + help 0 + ;; + "-m"|"--multiarch") + MULTIARCH="true" + shift + ;; + "-rg"|"--registry") + if [ -n "${2}" ]; then + WAZUH_REGISTRY="${2}" + shift 2 + else + help 1 + fi + ;; + "-v"|"--version") + if [ -n "$2" ]; then + WAZUH_CERTS_IMAGE_VERSION="$2" + shift 2 + else + help 1 + fi + ;; + *) + help 1 + esac + done + + build || clean 1 + + clean 0 +} + +main "$@" \ No newline at end of file diff --git a/indexer-certs-creator/build-image.yml b/indexer-certs-creator/build-image.yml new file mode 100644 index 00000000..58bb13cf --- /dev/null +++ b/indexer-certs-creator/build-image.yml @@ -0,0 +1,8 @@ +# Wazuh App Copyright (C) 2017, Wazuh Inc. (License GPLv2) +services: + wazuh.certs.generator: + build: + context: . + dockerfile: Dockerfile + image: ${WAZUH_REGISTRY}/wazuh/wazuh-certs-generator:${IMAGE_TAG} + hostname: wazuh-certs-generator