forked from wazuh/wazuh-docker
Merge pull request #2184 from wazuh/enh/2164-Allow_building_separate_targets--4.14.4
Backport from 5.0.0: Allow building separate targets #2177
This commit is contained in:
@@ -15,6 +15,12 @@ on:
|
|||||||
description: 'Filebeat module version'
|
description: 'Filebeat module version'
|
||||||
default: '0.5'
|
default: '0.5'
|
||||||
required: true
|
required: true
|
||||||
|
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'
|
||||||
@@ -44,6 +50,11 @@ on:
|
|||||||
default: '0.5'
|
default: '0.5'
|
||||||
required: true
|
required: true
|
||||||
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'
|
||||||
@@ -60,7 +71,7 @@ on:
|
|||||||
required: false
|
required: false
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build-and-push:
|
setup:
|
||||||
runs-on: ubuntu-22.04
|
runs-on: ubuntu-22.04
|
||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
@@ -73,6 +84,9 @@ jobs:
|
|||||||
FILEBEAT_MODULE_VERSION: ${{ inputs.filebeat_module_version }}
|
FILEBEAT_MODULE_VERSION: ${{ inputs.filebeat_module_version }}
|
||||||
REVISION: ${{ inputs.revision }}
|
REVISION: ${{ inputs.revision }}
|
||||||
|
|
||||||
|
outputs:
|
||||||
|
WAZUH_COMPONENTS: ${{ steps.compute-outputs.outputs.WAZUH_COMPONENTS }}
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Print inputs
|
- name: Print inputs
|
||||||
run: |
|
run: |
|
||||||
@@ -88,10 +102,51 @@ jobs:
|
|||||||
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 "* filebeat_module_version: ${{ inputs.filebeat_module_version }}"
|
echo "* filebeat_module_version: ${{ inputs.filebeat_module_version }}"
|
||||||
|
echo "* products: ${{ inputs.products }}"
|
||||||
echo "* revision: ${{ inputs.revision }}"
|
echo "* revision: ${{ inputs.revision }}"
|
||||||
echo "* dev: ${{ inputs.dev }}"
|
echo "* dev: ${{ inputs.dev }}"
|
||||||
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:
|
||||||
@@ -138,9 +193,9 @@ jobs:
|
|||||||
fi
|
fi
|
||||||
DEV_STAGE=${tokens[1]}
|
DEV_STAGE=${tokens[1]}
|
||||||
WAZUH_VER=${tokens[0]}
|
WAZUH_VER=${tokens[0]}
|
||||||
./build-images.sh -v $WAZUH_VER -r $REVISION -d $DEV_STAGE -f $FILEBEAT_MODULE_VERSION -rg $IMAGE_REGISTRY -m
|
./build-images.sh -v $WAZUH_VER -r $REVISION -d $DEV_STAGE -f $FILEBEAT_MODULE_VERSION -rg $IMAGE_REGISTRY -m -c ${{ matrix.wazuh_component }}
|
||||||
else
|
else
|
||||||
./build-images.sh -v $IMAGE_TAG -r $REVISION -f $FILEBEAT_MODULE_VERSION -rg $IMAGE_REGISTRY -m
|
./build-images.sh -v $IMAGE_TAG -r $REVISION -f $FILEBEAT_MODULE_VERSION -rg $IMAGE_REGISTRY -m -c ${{ matrix.wazuh_component }}
|
||||||
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
|
||||||
|
|||||||
+1
-1
@@ -9,7 +9,7 @@ All notable changes to this project will be documented in this file.
|
|||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
- None
|
- Backport from 5.0.0: Backport from 5.0.0: Allow building separate targets #2177 ([#2184](https://github.com/wazuh/wazuh-docker/pull/2184))
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
|
|||||||
@@ -61,7 +61,6 @@ build() {
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
echo WAZUH_VERSION=$WAZUH_IMAGE_VERSION > ../.env
|
echo WAZUH_VERSION=$WAZUH_IMAGE_VERSION > ../.env
|
||||||
echo WAZUH_IMAGE_VERSION=$WAZUH_IMAGE_VERSION >> ../.env
|
echo WAZUH_IMAGE_VERSION=$WAZUH_IMAGE_VERSION >> ../.env
|
||||||
echo WAZUH_TAG_REVISION=$WAZUH_TAG_REVISION >> ../.env
|
echo WAZUH_TAG_REVISION=$WAZUH_TAG_REVISION >> ../.env
|
||||||
@@ -75,18 +74,74 @@ build() {
|
|||||||
source ../.env
|
source ../.env
|
||||||
set +a
|
set +a
|
||||||
|
|
||||||
if [ "${MULTIARCH}" ];then
|
# Define all available components
|
||||||
docker buildx bake \
|
local all_components=("wazuh-indexer" "wazuh-manager" "wazuh-dashboard" "wazuh-agent")
|
||||||
--file build-images.yml \
|
local components_to_build=()
|
||||||
--push \
|
|
||||||
--set *.platform=linux/amd64,linux/arm64 \
|
# Determine which components to build
|
||||||
--no-cache || clean 1
|
if [ -z "${WAZUH_COMPONENT}" ]; then
|
||||||
|
echo "No component specified. Building all components..."
|
||||||
|
components_to_build=("${all_components[@]}")
|
||||||
else
|
else
|
||||||
docker buildx bake \
|
# Validate component
|
||||||
--file build-images.yml \
|
case "${WAZUH_COMPONENT}" in
|
||||||
--load \
|
wazuh-indexer|wazuh-manager|wazuh-dashboard|wazuh-agent)
|
||||||
--no-cache || clean 1
|
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)
|
||||||
|
# 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
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,6 +155,7 @@ help() {
|
|||||||
echo " -f, --filebeat-module <ref> [Optional] Set Filebeat module version. By default ${FILEBEAT_MODULE_VERSION}."
|
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 " -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 " -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."
|
||||||
@@ -160,6 +216,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