Add support for building multiple Wazuh components separately

This commit is contained in:
Jesus Garcia
2026-01-16 15:13:59 -05:00
parent a9b612f6c9
commit a9e602439d
2 changed files with 132 additions and 13 deletions
+76 -5
View File
@@ -60,7 +60,7 @@ build() {
curl -fsSL -o "$ARTIFACT_URLS_FILE" "https://packages-dev.wazuh.com/${WAZUH_MINOR_VERSION}/${ARTIFACT_URLS_FILE}"
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
echo WAZUH_VERSION=$WAZUH_IMAGE_VERSION > ../.env
echo WAZUH_IMAGE_VERSION=$WAZUH_IMAGE_VERSION >> ../.env
@@ -74,11 +74,73 @@ 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
else
docker buildx bake --file build-images.yml --no-cache|| clean 1
if [ -z "${WAZUH_COMPONENT}" ]; then
echo "Error: WAZUH_COMPONENT is not set" >&2
clean 1
fi
# Validate component
case "${WAZUH_COMPONENT}" in
wazuh-indexer|wazuh-manager|wazuh-dashboard|wazuh-agent) ;;
*)
echo "Error: Unknown component '${WAZUH_COMPONENT}'" >&2
clean 1
;;
esac
# 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 common args (used by all components)
build_args=(
-t "${WAZUH_REGISTRY}/wazuh/${WAZUH_COMPONENT}:${IMAGE_TAG}"
--build-arg WAZUH_VERSION="${WAZUH_IMAGE_VERSION}"
--build-arg WAZUH_TAG_REVISION="${WAZUH_TAG_REVISION}"
)
# Add component-specific args
case "${WAZUH_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
echo "Building ${WAZUH_COMPONENT} image..."
$build_cmd "${build_args[@]}" ${WAZUH_COMPONENT}/ || clean 1
echo "Image built successfully!"
return 0
}
@@ -92,6 +154,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."
@@ -152,6 +215,14 @@ main() {
help 1
fi
;;
"-c"|"--component")
if [ -n "${2}" ]; then
WAZUH_COMPONENT="${2}"
shift 2
else
help 1
fi
;;
*)
help 1
esac