forked from wazuh/wazuh-docker
Backport from 5.0.0: Allow building separate targets #2177
This commit is contained in:
@@ -61,7 +61,6 @@ build() {
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
echo WAZUH_VERSION=$WAZUH_IMAGE_VERSION > ../.env
|
||||
echo WAZUH_IMAGE_VERSION=$WAZUH_IMAGE_VERSION >> ../.env
|
||||
echo WAZUH_TAG_REVISION=$WAZUH_TAG_REVISION >> ../.env
|
||||
@@ -75,18 +74,74 @@ build() {
|
||||
source ../.env
|
||||
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 \
|
||||
--load \
|
||||
--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)
|
||||
# No additional args for wazuh-indexer
|
||||
;;
|
||||
wazuh-manager)
|
||||
build_args+=(
|
||||
--build-arg FILEBEAT_TEMPLATE_BRANCH="${FILEBEAT_TEMPLATE_BRANCH}"
|
||||
--build-arg WAZUH_FILEBEAT_MODULE="${WAZUH_FILEBEAT_MODULE}"
|
||||
)
|
||||
;;
|
||||
wazuh-dashboard)
|
||||
build_args+=(
|
||||
--build-arg WAZUH_UI_REVISION="${WAZUH_UI_REVISION}"
|
||||
)
|
||||
;;
|
||||
wazuh-agent)
|
||||
# No additional args for wazuh-agent
|
||||
;;
|
||||
esac
|
||||
|
||||
# Execute build
|
||||
$build_cmd "${build_args[@]}" ${component}/ || clean 1
|
||||
echo "${component} image built successfully!"
|
||||
done
|
||||
|
||||
echo ""
|
||||
echo "Image build process completed!"
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
@@ -100,6 +155,7 @@ help() {
|
||||
echo " -f, --filebeat-module <ref> [Optional] Set Filebeat module version. By default ${FILEBEAT_MODULE_VERSION}."
|
||||
echo " -r, --revision <rev> [Optional] Package revision. By default ${WAZUH_TAG_REVISION}"
|
||||
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."
|
||||
@@ -160,6 +216,14 @@ main() {
|
||||
help 1
|
||||
fi
|
||||
;;
|
||||
"-c"|"--component")
|
||||
if [ -n "${2}" ]; then
|
||||
WAZUH_COMPONENT="${2}"
|
||||
shift 2
|
||||
else
|
||||
help 1
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
help 1
|
||||
esac
|
||||
|
||||
Reference in New Issue
Block a user