forked from wazuh/wazuh-docker
Merge branch 'enh/2164-Allow_building_separate_targets'
This commit is contained in:
@@ -11,6 +11,10 @@ on:
|
|||||||
docker_reference:
|
docker_reference:
|
||||||
description: 'wazuh-docker reference'
|
description: 'wazuh-docker reference'
|
||||||
required: true
|
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
|
||||||
revision:
|
revision:
|
||||||
description: 'Package revision'
|
description: 'Package revision'
|
||||||
default: '1'
|
default: '1'
|
||||||
@@ -39,6 +43,11 @@ on:
|
|||||||
description: 'wazuh-docker reference'
|
description: 'wazuh-docker reference'
|
||||||
required: false
|
required: false
|
||||||
type: string
|
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:
|
revision:
|
||||||
description: 'Package revision'
|
description: 'Package revision'
|
||||||
default: '1'
|
default: '1'
|
||||||
@@ -59,17 +68,15 @@ on:
|
|||||||
required: false
|
required: false
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build-and-push:
|
setup:
|
||||||
runs-on: ubuntu-22.04
|
runs-on: ubuntu-22.04
|
||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
id-token: write
|
id-token: write
|
||||||
contents: read
|
contents: read
|
||||||
|
|
||||||
env:
|
outputs:
|
||||||
IMAGE_REGISTRY: ${{ inputs.dev && vars.IMAGE_REGISTRY_DEV || vars.IMAGE_REGISTRY_PROD }}
|
WAZUH_COMPONENTS: ${{ steps.compute-outputs.outputs.WAZUH_COMPONENTS }}
|
||||||
IMAGE_TAG: ${{ inputs.image_tag }}
|
|
||||||
REVISION: ${{ inputs.revision }}
|
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Print inputs
|
- name: Print inputs
|
||||||
@@ -85,11 +92,52 @@ jobs:
|
|||||||
echo "* id: ${{ inputs.id }}"
|
echo "* id: ${{ inputs.id }}"
|
||||||
echo "* image_tag: ${{ inputs.image_tag }}"
|
echo "* image_tag: ${{ inputs.image_tag }}"
|
||||||
echo "* docker_reference: ${{ inputs.docker_reference }}"
|
echo "* docker_reference: ${{ inputs.docker_reference }}"
|
||||||
|
echo "* products: ${{ inputs.products }}"
|
||||||
echo "* revision: ${{ inputs.revision }}"
|
echo "* revision: ${{ inputs.revision }}"
|
||||||
echo "* dev: ${{ inputs.dev }}"
|
echo "* dev: ${{ inputs.dev }}"
|
||||||
echo "* dev reference: ${{ inputs.reference }}"
|
echo "* dev reference: ${{ inputs.reference }}"
|
||||||
echo "---------------------------------------------"
|
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
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
@@ -161,15 +209,15 @@ jobs:
|
|||||||
DEV_STAGE=${tokens[1]}
|
DEV_STAGE=${tokens[1]}
|
||||||
WAZUH_VER=${tokens[0]}
|
WAZUH_VER=${tokens[0]}
|
||||||
if [ "${{ inputs.dev }}" = true ]; then
|
if [ "${{ inputs.dev }}" = true ]; then
|
||||||
./build-images.sh -v $WAZUH_VER -r $REVISION -d $DEV_STAGE -rg $IMAGE_REGISTRY -m -ref ${{ inputs.reference }}
|
./build-images.sh -v $WAZUH_VER -r $REVISION -d $DEV_STAGE -rg $IMAGE_REGISTRY -m -ref ${{ inputs.reference }} -c ${{ matrix.wazuh_component }}
|
||||||
else
|
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 -c ${{ matrix.wazuh_component }}
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
if [ "${{ inputs.dev }}" = true ]; then
|
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
|
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
|
||||||
fi
|
fi
|
||||||
# Save .env file (generated by build-images.sh) contents to $GITHUB_ENV
|
# Save .env file (generated by build-images.sh) contents to $GITHUB_ENV
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ All notable changes to this project will be documented in this file.
|
|||||||
|
|
||||||
### Changed
|
### 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 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))
|
- 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))
|
- Delete Wazuh agent configuration files ([#2173](https://github.com/wazuh/wazuh-docker/pull/2173))
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ build() {
|
|||||||
fi
|
fi
|
||||||
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_DEV_STAGE}" ];then
|
||||||
if [ "${WAZUH_TAG_REFERENCE}" ];then
|
if [ "${WAZUH_TAG_REFERENCE}" ];then
|
||||||
@@ -89,11 +89,86 @@ build() {
|
|||||||
source ./artifacts_env.txt
|
source ./artifacts_env.txt
|
||||||
set +a
|
set +a
|
||||||
|
|
||||||
if [ "${MULTIARCH}" ];then
|
# Define all available components
|
||||||
docker buildx bake --file build-images.yml --push --set *.platform=linux/amd64,linux/arm64 --no-cache|| clean 1
|
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
|
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
|
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
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -107,6 +182,7 @@ help() {
|
|||||||
echo " -r, --revision <rev> [Optional] Package revision. By default ${WAZUH_TAG_REVISION}"
|
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 " -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 " -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 " -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 " -m, --multiarch [Optional] Enable multi-architecture builds."
|
||||||
echo " -h, --help Show this help."
|
echo " -h, --help Show this help."
|
||||||
@@ -167,6 +243,14 @@ main() {
|
|||||||
help 1
|
help 1
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
|
"-c"|"--component")
|
||||||
|
if [ -n "${2}" ]; then
|
||||||
|
WAZUH_COMPONENT="${2}"
|
||||||
|
shift 2
|
||||||
|
else
|
||||||
|
help 1
|
||||||
|
fi
|
||||||
|
;;
|
||||||
*)
|
*)
|
||||||
help 1
|
help 1
|
||||||
esac
|
esac
|
||||||
|
|||||||
Reference in New Issue
Block a user