Merge branch 'enh/2164-Allow_building_separate_targets'

This commit is contained in:
Jesus Garcia
2026-01-21 19:07:39 -05:00
3 changed files with 150 additions and 17 deletions
+91 -7
View File
@@ -60,12 +60,12 @@ 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
if [ "${WAZUH_DEV_STAGE}" ];then
if [ "${WAZUH_TAG_REFERENCE}" ];then
IMAGE_TAG="${WAZUH_IMAGE_VERSION}-${WAZUH_DEV_STAGE,,}-${WAZUH_TAG_REFERENCE}"
IMAGE_TAG="${WAZUH_IMAGE_VERSION}-${WAZUH_DEV_STAGE,,}-${WAZUH_TAG_REFERENCE}"
else
IMAGE_TAG="${WAZUH_IMAGE_VERSION}-${WAZUH_DEV_STAGE,,}"
fi
@@ -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