Merge pull request #2177 from wazuh/enh/2164-Allow_building_separate_targets

Allow building separate targets
This commit is contained in:
Gonzalo Acuña
2026-01-26 11:41:27 -03:00
committed by GitHub
3 changed files with 148 additions and 14 deletions
@@ -11,6 +11,11 @@ on:
docker_reference:
description: 'wazuh-docker reference'
required: true
products:
description: 'Comma-separated list of the image names to build and push'
default: 'wazuh-manager,wazuh-dashboard,wazuh-indexer,wazuh-agent'
required: false
type: string
revision:
description: 'Package revision'
default: '1'
@@ -39,6 +44,11 @@ on:
description: 'wazuh-docker reference'
required: false
type: string
products:
description: 'Comma-separated list of the image names to build and push'
default: 'wazuh-manager,wazuh-dashboard,wazuh-indexer,wazuh-agent'
required: false
type: string
revision:
description: 'Package revision'
default: '1'
@@ -59,17 +69,15 @@ on:
required: false
jobs:
build-and-push:
setup:
runs-on: ubuntu-22.04
permissions:
id-token: write
contents: read
env:
IMAGE_REGISTRY: ${{ inputs.dev && vars.IMAGE_REGISTRY_DEV || vars.IMAGE_REGISTRY_PROD }}
IMAGE_TAG: ${{ inputs.image_tag }}
REVISION: ${{ inputs.revision }}
outputs:
WAZUH_COMPONENTS: ${{ steps.compute-outputs.outputs.WAZUH_COMPONENTS }}
steps:
- name: Print inputs
@@ -85,11 +93,52 @@ jobs:
echo "* id: ${{ inputs.id }}"
echo "* image_tag: ${{ inputs.image_tag }}"
echo "* docker_reference: ${{ inputs.docker_reference }}"
echo "* products: ${{ inputs.products }}"
echo "* revision: ${{ inputs.revision }}"
echo "* dev: ${{ inputs.dev }}"
echo "* dev reference: ${{ inputs.reference }}"
echo "---------------------------------------------"
- name: Set up variables
id: compute-outputs
run: |
if [[ "${{ inputs.products }}" != "null" && "${{ inputs.products }}" != "" ]]; then
# Convert comma-separated list to JSON array format
IFS=',' read -ra COMPONENTS <<< "${{ inputs.products }}"
JSON_ARRAY="["
for i in "${!COMPONENTS[@]}"; do
if [ $i -gt 0 ]; then
JSON_ARRAY+=","
fi
JSON_ARRAY+="\"${COMPONENTS[$i]}\""
done
JSON_ARRAY+="]"
echo "WAZUH_COMPONENTS=$JSON_ARRAY" >> $GITHUB_OUTPUT
else
echo "WAZUH_COMPONENTS=[\"wazuh-manager\",\"wazuh-dashboard\",\"wazuh-indexer\",\"wazuh-agent\"]" >> $GITHUB_OUTPUT
fi
build-and-push:
runs-on: ubuntu-22.04
permissions:
id-token: write
contents: read
needs:
- setup
strategy:
fail-fast: false # all jobs will run even if one fails
matrix:
wazuh_component: ${{ fromJson(needs.setup.outputs.WAZUH_COMPONENTS) }}
env:
IMAGE_REGISTRY: ${{ inputs.dev && vars.IMAGE_REGISTRY_DEV || vars.IMAGE_REGISTRY_PROD }}
IMAGE_TAG: ${{ inputs.image_tag }}
REVISION: ${{ inputs.revision }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
@@ -161,15 +210,15 @@ jobs:
DEV_STAGE=${tokens[1]}
WAZUH_VER=${tokens[0]}
if [ "${{ inputs.dev }}" = true ]; then
./build-images.sh -v $WAZUH_VER -r $REVISION -d $DEV_STAGE -rg $IMAGE_REGISTRY -m -ref ${{ inputs.reference }}
else
./build-images.sh -v $WAZUH_VER -r $REVISION -d $DEV_STAGE -rg $IMAGE_REGISTRY -m
./build-images.sh -v $WAZUH_VER -r $REVISION -d $DEV_STAGE -rg $IMAGE_REGISTRY -m -ref ${{ inputs.reference }} -c ${{ matrix.wazuh_component }}
else
./build-images.sh -v $WAZUH_VER -r $REVISION -d $DEV_STAGE -rg $IMAGE_REGISTRY -m -c ${{ matrix.wazuh_component }}
fi
else
if [ "${{ inputs.dev }}" = true ]; then
./build-images.sh -v $IMAGE_TAG -r $REVISION -rg $IMAGE_REGISTRY -m -ref ${{ inputs.reference }}
./build-images.sh -v $IMAGE_TAG -r $REVISION -rg $IMAGE_REGISTRY -m -ref ${{ inputs.reference }} -c ${{ matrix.wazuh_component }}
else
./build-images.sh -v $IMAGE_TAG -r $REVISION -rg $IMAGE_REGISTRY -m
./build-images.sh -v $IMAGE_TAG -r $REVISION -rg $IMAGE_REGISTRY -m -c ${{ matrix.wazuh_component }}
fi
fi
# Save .env file (generated by build-images.sh) contents to $GITHUB_ENV
+1
View File
@@ -9,6 +9,7 @@ All notable changes to this project will be documented in this file.
### Changed
- Allow building separate targets ([#2177](https://github.com/wazuh/wazuh-docker/pull/2177))
- Add developement option when tag name is only version without stage ([#2179](https://github.com/wazuh/wazuh-docker/pull/2179))
- Add IMAGE_TAG stage reference ([#2178](https://github.com/wazuh/wazuh-docker/pull/2178))
- Delete Wazuh agent configuration files ([#2173](https://github.com/wazuh/wazuh-docker/pull/2173))
+88 -4
View File
@@ -61,7 +61,7 @@ build() {
fi
fi
awk -F':' '{name=$1; val=substr($0,length(name)+3); gsub(/[-.]/,"_",name); print name "=" val}' $ARTIFACT_URLS_FILE > artifacts_env.txt
awk -F':' '!/^#/ && NF>1 {name=$1; val=substr($0,length(name)+3); gsub(/[-.]/,"_",name); print name "=" val}' $ARTIFACT_URLS_FILE > artifacts_env.txt
if [ "${WAZUH_DEV_STAGE}" ];then
if [ "${WAZUH_TAG_REFERENCE}" ];then
@@ -89,11 +89,86 @@ build() {
source ./artifacts_env.txt
set +a
if [ "${MULTIARCH}" ];then
docker buildx bake --file build-images.yml --push --set *.platform=linux/amd64,linux/arm64 --no-cache|| clean 1
# Define all available components
local all_components=("wazuh-indexer" "wazuh-manager" "wazuh-dashboard" "wazuh-agent")
local components_to_build=()
# Determine which components to build
if [ -z "${WAZUH_COMPONENT}" ]; then
echo "No component specified. Building all components..."
components_to_build=("${all_components[@]}")
else
docker buildx bake --file build-images.yml --no-cache|| clean 1
# Validate component
case "${WAZUH_COMPONENT}" in
wazuh-indexer|wazuh-manager|wazuh-dashboard|wazuh-agent)
components_to_build=("${WAZUH_COMPONENT}")
;;
*)
echo "Error: Unknown component '${WAZUH_COMPONENT}'" >&2
clean 1
;;
esac
fi
# Determine build command and base options
if [ "${MULTIARCH}" ]; then
build_cmd="docker buildx build --platform linux/amd64,linux/arm64 --push --no-cache"
else
build_cmd="docker build --no-cache"
fi
# Build each component
for component in "${components_to_build[@]}"; do
echo "Building ${component} image..."
# Build common args (used by all components)
build_args=(
-t "${WAZUH_REGISTRY}/wazuh/${component}:${IMAGE_TAG}"
--build-arg WAZUH_VERSION="${WAZUH_IMAGE_VERSION}"
--build-arg WAZUH_TAG_REVISION="${WAZUH_TAG_REVISION}"
)
# Add component-specific args
case "${component}" in
wazuh-indexer)
build_args+=(
--build-arg wazuh_indexer_url_amd64_rpm="${wazuh_indexer_url_x86_64_rpm}"
--build-arg wazuh_indexer_url_arm64_rpm="${wazuh_indexer_url_aarch64_rpm}"
--build-arg wazuh_certs_tool="${wazuh_certs_tool}"
--build-arg wazuh_config_yml="${wazuh_config_yml}"
)
;;
wazuh-manager)
build_args+=(
--build-arg wazuh_manager_url_amd64_rpm="${wazuh_manager_url_x86_64_rpm}"
--build-arg wazuh_manager_url_arm64_rpm="${wazuh_manager_url_aarch64_rpm}"
)
;;
wazuh-dashboard)
build_args+=(
--build-arg WAZUH_UI_REVISION="${WAZUH_UI_REVISION}"
--build-arg wazuh_dashboard_url_amd64_rpm="${wazuh_dashboard_url_x86_64_rpm}"
--build-arg wazuh_dashboard_url_arm64_rpm="${wazuh_dashboard_url_aarch64_rpm}"
--build-arg wazuh_certs_tool="${wazuh_certs_tool}"
--build-arg wazuh_config_yml="${wazuh_config_yml}"
)
;;
wazuh-agent)
build_args+=(
--build-arg wazuh_agent_url_amd64_rpm="${wazuh_agent_url_x86_64_rpm}"
--build-arg wazuh_agent_url_arm64_rpm="${wazuh_agent_url_aarch64_rpm}"
)
;;
esac
# Execute build
$build_cmd "${build_args[@]}" ${component}/ || clean 1
echo "${component} image built successfully!"
done
echo ""
echo "Image build process completed!"
return 0
}
@@ -107,6 +182,7 @@ help() {
echo " -r, --revision <rev> [Optional] Package revision. By default ${WAZUH_TAG_REVISION}"
echo " -ref, --reference <ref> [Optional] Set the Wazuh reference to build development images. By default, the latest stable release."
echo " -rg, --registry <reg> [Optional] Set the Docker registry to push the images."
echo " -c, --component <comp> [Required] Set the Wazuh component to build. Accepted values: 'wazuh-indexer', 'wazuh-manager', 'wazuh-dashboard', 'wazuh-agent'."
echo " -v, --version <ver> [Optional] Set the Wazuh version should be builded. By default, ${WAZUH_IMAGE_VERSION}."
echo " -m, --multiarch [Optional] Enable multi-architecture builds."
echo " -h, --help Show this help."
@@ -167,6 +243,14 @@ main() {
help 1
fi
;;
"-c"|"--component")
if [ -n "${2}" ]; then
WAZUH_COMPONENT="${2}"
shift 2
else
help 1
fi
;;
*)
help 1
esac