Enhance build-images.sh script to handle multiple components

This commit is contained in:
Jesus Garcia
2026-01-19 08:23:24 -05:00
parent a9e602439d
commit 7991ad6284
+23 -10
View File
@@ -74,19 +74,26 @@ build() {
source ./artifacts_env.txt source ./artifacts_env.txt
set +a set +a
if [ -z "${WAZUH_COMPONENT}" ]; then # Define all available components
echo "Error: WAZUH_COMPONENT is not set" >&2 local all_components=("wazuh-indexer" "wazuh-manager" "wazuh-dashboard" "wazuh-agent")
clean 1 local components_to_build=()
fi
# Determine which components to build
if [ -z "${WAZUH_COMPONENT}" ]; then
echo "No component specified. Building all components..."
components_to_build=("${all_components[@]}")
else
# Validate component # Validate component
case "${WAZUH_COMPONENT}" in case "${WAZUH_COMPONENT}" in
wazuh-indexer|wazuh-manager|wazuh-dashboard|wazuh-agent) ;; wazuh-indexer|wazuh-manager|wazuh-dashboard|wazuh-agent)
components_to_build=("${WAZUH_COMPONENT}")
;;
*) *)
echo "Error: Unknown component '${WAZUH_COMPONENT}'" >&2 echo "Error: Unknown component '${WAZUH_COMPONENT}'" >&2
clean 1 clean 1
;; ;;
esac esac
fi
# Determine build command and base options # Determine build command and base options
if [ "${MULTIARCH}" ]; then if [ "${MULTIARCH}" ]; then
@@ -95,15 +102,19 @@ build() {
build_cmd="docker build --no-cache" build_cmd="docker build --no-cache"
fi fi
# Build each component
for component in "${components_to_build[@]}"; do
echo "Building ${component} image..."
# Build common args (used by all components) # Build common args (used by all components)
build_args=( build_args=(
-t "${WAZUH_REGISTRY}/wazuh/${WAZUH_COMPONENT}:${IMAGE_TAG}" -t "${WAZUH_REGISTRY}/wazuh/${component}:${IMAGE_TAG}"
--build-arg WAZUH_VERSION="${WAZUH_IMAGE_VERSION}" --build-arg WAZUH_VERSION="${WAZUH_IMAGE_VERSION}"
--build-arg WAZUH_TAG_REVISION="${WAZUH_TAG_REVISION}" --build-arg WAZUH_TAG_REVISION="${WAZUH_TAG_REVISION}"
) )
# Add component-specific args # Add component-specific args
case "${WAZUH_COMPONENT}" in case "${component}" in
wazuh-indexer) wazuh-indexer)
build_args+=( build_args+=(
--build-arg wazuh_indexer_url_amd64_rpm="${wazuh_indexer_url_x86_64_rpm}" --build-arg wazuh_indexer_url_amd64_rpm="${wazuh_indexer_url_x86_64_rpm}"
@@ -136,10 +147,12 @@ build() {
esac esac
# Execute build # Execute build
echo "Building ${WAZUH_COMPONENT} image..." $build_cmd "${build_args[@]}" ${component}/ || clean 1
$build_cmd "${build_args[@]}" ${WAZUH_COMPONENT}/ || clean 1 echo "${component} image built successfully!"
done
echo "Image built successfully!" echo ""
echo "Image build process completed!"
return 0 return 0
} }