-
Notifications
You must be signed in to change notification settings - Fork 553
Expand file tree
/
Copy pathProcedure_push_docker_images.yml
More file actions
501 lines (448 loc) · 18.4 KB
/
Procedure_push_docker_images.yml
File metadata and controls
501 lines (448 loc) · 18.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
run-name: Launch Push Docker Images - ${{ inputs.id }}
name: Push Docker Images
on:
workflow_dispatch:
inputs:
image_tag:
description: 'Docker image tag'
default: '5.0.0'
required: true
docker_reference:
description: 'wazuh-docker reference'
required: true
wazuh_automation_reference:
description: 'Branch or tag of the wazuh-automation repository'
required: false
default: 'main'
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
commit_list:
description: 'Wazuh components revisions (only for dev): json array with commit-hash for each product'
type: string
default: '["latest", "latest", "latest", "latest"]'
assistant_revision:
description: 'Revision for Wazuh installation assistant tools like Wazuh password tool (only for dev)'
type: string
default: 'latest'
required: false
id:
description: "ID used to identify the workflow uniquely."
type: string
required: false
dev:
description: "Add tag suffix '-dev' to the image tag ?"
type: boolean
default: true
required: false
workflow_call:
inputs:
image_tag:
description: 'Docker image tag'
default: '5.0.0'
required: true
type: string
docker_reference:
description: 'wazuh-docker reference'
required: false
type: string
wazuh_automation_reference:
description: 'Branch or tag of the wazuh-automation repository'
required: false
default: 'main'
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
commit_list:
description: 'Wazuh components revisions (only for dev): json array with commit-hash for each product'
type: string
default: '["latest", "latest", "latest", "latest"]'
assistant_revision:
description: 'Revision for Wazuh installation assistant tools like Wazuh password tool (only for dev)'
type: string
default: 'latest'
required: false
id:
description: "ID used to identify the workflow uniquely."
type: string
required: false
dev:
description: "Add tag suffix '-dev' to the image tag ?"
type: boolean
default: false
required: false
permissions:
id-token: write
contents: read
jobs:
setup:
runs-on:
group: wz-linux-amd64
outputs:
WAZUH_COMPONENTS: ${{ steps.compute-outputs.outputs.WAZUH_COMPONENTS }}
COMMIT_LIST: ${{ steps.compute-outputs.outputs.COMMIT_LIST }}
ALL_PRODUCTS_SELECTED: ${{ steps.compute-outputs.outputs.ALL_PRODUCTS_SELECTED }}
steps:
- name: Print inputs
run: |
echo "---------------------------------------------"
echo "Running Procedure_push_docker_images workflow"
echo "---------------------------------------------"
echo "* BRANCH: ${{ github.ref }}"
echo "* COMMIT: ${{ github.sha }}"
echo "---------------------------------------------"
echo "Inputs provided:"
echo "---------------------------------------------"
echo "* id: ${{ inputs.id }}"
echo "* image_tag: ${{ inputs.image_tag }}"
echo "* docker_reference: ${{ inputs.docker_reference }}"
echo "* wazuh_automation_reference: ${{ inputs.wazuh_automation_reference }}"
echo "* products: ${{ inputs.products }}"
echo "* dev: ${{ inputs.dev }}"
echo "* commit_list: ${{ inputs.commit_list }}"
echo "* assistant_revision: ${{ inputs.assistant_revision }}"
echo "---------------------------------------------"
- name: Set up variables
id: compute-outputs
run: |
# Use the default list if products is empty
PRODUCTS="${{ inputs.products }}"
if [[ -z "$PRODUCTS" || "$PRODUCTS" == "null" ]]; then
PRODUCTS="wazuh-manager,wazuh-dashboard,wazuh-indexer,wazuh-agent"
fi
# Check if all 4 core components are present in the string
if [[ "$PRODUCTS" == *"wazuh-manager"* && "$PRODUCTS" == *"wazuh-dashboard"* && "$PRODUCTS" == *"wazuh-indexer"* && "$PRODUCTS" == *"wazuh-agent"* ]]; then
echo "ALL_PRODUCTS_SELECTED=true" >> $GITHUB_OUTPUT
else
echo "ALL_PRODUCTS_SELECTED=false" >> $GITHUB_OUTPUT
fi
# Set WAZUH_COMPONENTS
# Convert to JSON for the matrix (Your existing logic)
IFS=',' read -ra COMPONENTS <<< "$PRODUCTS"
JSON_ARRAY=$(printf '%s\n' "${COMPONENTS[@]}" | jq -R . | jq -s -c .)
echo "WAZUH_COMPONENTS=$JSON_ARRAY" >> $GITHUB_OUTPUT
# Set COMMIT_LIST
WC_COMMIT_LIST=""
if [[ "${{ inputs.dev }}" == "true" ]]; then
if [[ "${{ inputs.commit_list }}" != "null" && "${{ inputs.commit_list }}" != "" ]]; then
WC_COMMIT_LIST='${{ inputs.commit_list }}'
else
# Set commit list to "latest" for all components using WAZUH_COMPONENTS
COMPONENTS=($(echo "$WC_JSON_ARRAY" | jq -r '.[]'))
WC_COMMIT_LIST="["
for i in "${!COMPONENTS[@]}"; do
if [ $i -gt 0 ]; then
WC_COMMIT_LIST+=" ,"
fi
WC_COMMIT_LIST+="\"latest\""
done
WC_COMMIT_LIST+="]"
fi
echo "Revision list: $WC_COMMIT_LIST"
fi
echo "COMMIT_LIST=$WC_COMMIT_LIST" >> $GITHUB_OUTPUT
package-urls:
name: generate package urls
runs-on:
group: wz-linux-amd64
needs: setup
env:
WORKFLOW_VENV: "${{ github.workspace }}/workflow_venv"
GENERATE_PRESIGNED_URLS_SCRIPT_PATH: ${{ github.workspace }}/wazuh-automation/tools/sign_urls/generate_presigned_dev_urls.py
PRESIGNED_URLS_SCRIPT_PROCESS: "build_docker"
LOCAL_ARTIFACT_URLS_FILEPATH: /tmp/${{ vars.ARTIFACT_URL_FILE_NAME }}
COMMIT_LIST: ${{ inputs.commit_list }}
ASSISTANT_REVISION: ${{ inputs.assistant_revision }}
steps:
- name: Checkout repository
if: ${{ inputs.dev == true }}
uses: actions/checkout@v4
with:
ref: ${{ inputs.docker_reference }}
- name: Checkout wazuh/wazuh-automation repository
if: ${{ inputs.dev == true }}
uses: actions/checkout@v4
with:
repository: wazuh/wazuh-automation
ref: ${{ inputs.wazuh_automation_reference }}
token: ${{ secrets.GH_CLONE_TOKEN }}
path: wazuh-automation
- name: Configure AWS credentials
if: ${{ inputs.dev == true }}
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_IAM_DOCKER_ROLE }}
aws-region: ${{ secrets.AWS_REGION }}
- name: Set up Python
if: ${{ inputs.dev == true }}
uses: actions/setup-python@v6
with:
python-version: '3.12'
- name: Install and configure python and workflow dependencies
if: ${{ inputs.dev == true }}
run: |
sudo apt-get update
sudo apt-get install -y jq
# Install yq
sudo curl -sL "https://github.com/mikefarah/yq/releases/download/v4.44.3/yq_linux_amd64" -o /usr/local/bin/yq
sudo chmod +x /usr/local/bin/yq
sudo apt-get install -y python3-venv
python3 -m venv ${{ env.WORKFLOW_VENV }}
source ${{ env.WORKFLOW_VENV }}/bin/activate
pip install --upgrade pip
pip install pyyaml
- name: Get Wazuh version
if: ${{ inputs.dev == true }}
run: |
WAZUH_VERSION=$(jq -r '.version' VERSION.json)
WAZUH_MAJOR=$(echo "$WAZUH_VERSION" | cut -d '.' -f 1)
WAZUH_MINOR=$(echo "$WAZUH_VERSION" | cut -d '.' -f 1-2)
echo WAZUH_VERSION=$WAZUH_VERSION >> $GITHUB_ENV
echo WAZUH_MAJOR=$WAZUH_MAJOR >> $GITHUB_ENV
echo WAZUH_MINOR=$WAZUH_MINOR >> $GITHUB_ENV
- name: Get artifacts URLs file
if: ${{ inputs.dev == true }}
run: |
LOCAL_AWS_S3_BUCKET_DEV=${{ vars.AWS_S3_BUCKET_DEV }}
echo LOCAL_AWS_S3_BUCKET_DEV=$LOCAL_AWS_S3_BUCKET_DEV >> $GITHUB_ENV
- name: Generate presigned URLs for artifacts for dev packages
if: ${{ inputs.dev == true }}
run: |
source ${{ env.WORKFLOW_VENV }}/bin/activate
WAZUH_COMPONENTS='${{ needs.setup.outputs.WAZUH_COMPONENTS }}'
COMMIT_LIST='${{ needs.setup.outputs.COMMIT_LIST }}'
# Parse components and their revisions
COMPONENTS=($(echo "$WAZUH_COMPONENTS" | jq -r '.[]'))
REVISIONS=($(echo "$COMMIT_LIST" | jq -r '.[]'))
# Ensure the number of components matches the number of revisions
if [[ ${#COMPONENTS[@]} -ne ${#REVISIONS[@]} ]]; then
echo "Error: WAZUH_COMPONENTS and COMMIT_LIST length mismatch." >&2
echo " Components: ${#COMPONENTS[@]}, Revisions: ${#REVISIONS[@]}." >&2
echo " WAZUH_COMPONENTS=${WAZUH_COMPONENTS}" >&2
echo " COMMIT_LIST=${COMMIT_LIST}" >&2
exit 1
fi
# Map revisions to component names
for i in "${!COMPONENTS[@]}"; do
case "${COMPONENTS[$i]}" in
wazuh-manager)
MANAGER_REVISION="${REVISIONS[$i]}"
;;
wazuh-dashboard)
DASHBOARD_REVISION="${REVISIONS[$i]}"
;;
wazuh-indexer)
INDEXER_REVISION="${REVISIONS[$i]}"
;;
wazuh-agent)
AGENT_REVISION="${REVISIONS[$i]}"
;;
esac
done
python ${{ env.GENERATE_PRESIGNED_URLS_SCRIPT_PATH }} \
--process ${{ env.PRESIGNED_URLS_SCRIPT_PROCESS }} \
--wazuh-version ${{ env.WAZUH_VERSION }} \
--aws-s3-bucket-dev ${{ env.LOCAL_AWS_S3_BUCKET_DEV }} \
--indexer-revision $INDEXER_REVISION \
--manager-revision $MANAGER_REVISION \
--dashboard-revision $DASHBOARD_REVISION \
--agent-revision $AGENT_REVISION \
--assistant-revision $ASSISTANT_REVISION
- name: Save presigned URLs file to artifact
if: ${{ inputs.dev == true }}
uses: actions/upload-artifact@v4
with:
name: presigned-artifact-urls-${{ github.run_id }}
path: ${{ env.LOCAL_ARTIFACT_URLS_FILEPATH }}
build-and-push:
runs-on:
group: wz-linux-amd64
needs:
- setup
- package-urls
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 }}
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
ref: ${{ inputs.docker_reference }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Configure aws credentials
if: ${{ inputs.dev == true }}
uses: aws-actions/configure-aws-credentials@v6
with:
role-to-assume: ${{ secrets.AWS_IAM_DOCKER_ROLE }}
aws-region: "${{ secrets.AWS_REGION }}"
- name: Log in to Amazon ECR
if: ${{ inputs.dev == true }}
uses: aws-actions/amazon-ecr-login@v2
- name: Log in to Docker Hub
if: ${{ inputs.dev == false }}
uses: docker/login-action@v4
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Download artifact_urls.yaml (dev)
if: ${{ inputs.dev == true }}
uses: actions/download-artifact@v4
with:
name: presigned-artifact-urls-${{ github.run_id }}
path: ./build-docker-images
- name: Compute component reference (dev)
if: ${{ inputs.dev == true }}
run: |
COMPONENT='${{ matrix.wazuh_component }}'
WAZUH_COMPONENTS='${{ needs.setup.outputs.WAZUH_COMPONENTS }}'
COMMIT_LIST='${{ needs.setup.outputs.COMMIT_LIST }}'
idx=$(jq -r --arg c "$COMPONENT" 'index($c)' <<<"$WAZUH_COMPONENTS")
ref=$(jq -r --argjson i "$idx" '.[ $i ]' <<<"$COMMIT_LIST")
echo "COMPONENT_REFS_JSON=[\"$ref\"]" >> "$GITHUB_ENV"
echo "Using component ref for $COMPONENT: $ref"
- name: Build Wazuh images
run: |
if [[ "$IMAGE_TAG" == *"-"* ]]; then
IFS='-' read -r -a tokens <<< "$IMAGE_TAG"
if [ -z "${tokens[1]}" ]; then
echo "Invalid image tag: $IMAGE_TAG"
exit 1
fi
DEV_STAGE=${tokens[1]}
WAZUH_VER=${tokens[0]}
if [ "${{ inputs.dev }}" = true ]; then
./build-images.sh \
-v $WAZUH_VER \
-d $DEV_STAGE \
-rg $IMAGE_REGISTRY \
-m \
--dev \
-refs "$COMPONENT_REFS_JSON" \
-c ${{ matrix.wazuh_component }}
else
./build-images.sh \
-v $WAZUH_VER \
-d $DEV_STAGE \
-rg $IMAGE_REGISTRY \
-m \
-c ${{ matrix.wazuh_component }}
fi
else
if [ "${{ inputs.dev }}" = true ]; then
./build-images.sh \
-v $IMAGE_TAG \
-rg $IMAGE_REGISTRY \
-m \
--dev \
-refs "$COMPONENT_REFS_JSON" \
-c ${{ matrix.wazuh_component }}
else
./build-images.sh \
-v $IMAGE_TAG \
-rg $IMAGE_REGISTRY \
-m \
-c ${{ matrix.wazuh_component }}
fi
fi
# Save .env file (generated by build-images.sh) contents to $GITHUB_ENV
ENV_FILE_PATH="../.env"
if [ -f $ENV_FILE_PATH ]; then
while IFS= read -r line || [ -n "$line" ]; do
echo "$line" >> $GITHUB_ENV
done < $ENV_FILE_PATH
else
echo "The environment file $ENV_FILE_PATH does not exist!"
exit 1
fi
working-directory: ./build-docker-images
notify:
runs-on: ubuntu-22.04
needs: [setup, build-and-push]
# Only run if NOT dev AND all products were selected
if: ${{ inputs.dev == false && needs.setup.outputs.ALL_PRODUCTS_SELECTED == 'true' }}
steps:
- name: Image exists validation
id: validation
run: |
IMAGE_TAG=${{ inputs.image_tag }}
IMAGE_REGISTRY="${{ vars.IMAGE_REGISTRY_PROD }}"
PURPOSE=""
if [[ "$IMAGE_TAG" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
if docker manifest inspect $IMAGE_REGISTRY/wazuh/wazuh-manager:$IMAGE_TAG > /dev/null 2>&1; then
PURPOSE="regeneration"
echo "Image wazuh/wazuh-manager:$IMAGE_TAG exists. Setting PURPOSE to 'regeneration'"
else
PURPOSE="new release"
echo "Image wazuh/wazuh-manager:$IMAGE_TAG does NOT exist. Setting PURPOSE to 'new release'"
fi
echo "✅ Release tag: '$IMAGE_TAG'"
elif [[ "$IMAGE_TAG" =~ ^[0-9]+\.[0-9]+\.[0-9]+-(alpha|beta|rc)[0-9]+$ ]]; then
PURPOSE="new stage"
echo "✅ Stage tag: '$IMAGE_TAG'. Setting PURPOSE to 'new stage'"
else
echo "❌ No release or stage tag ('$IMAGE_TAG'), the GH issue will not be created"
fi
echo "purpose=$PURPOSE" >> $GITHUB_OUTPUT
- name: GH issue notification
if: ${{ steps.validation.outputs.purpose != '' }}
env:
GH_TOKEN: ${{ secrets.NOTIFICATION_GH_ARTIFACT_TOKEN }}
run: |
IMAGE_TAG=${{ inputs.image_tag }}
PURPOSE="${{ steps.validation.outputs.purpose }}"
GH_TITLE=""
GH_MESSAGE=""
## Setting GH issue title
GH_TITLE="Artifactory vulnerabilities update \`v$IMAGE_TAG\`"
## Setting GH issue body
GH_MESSAGE=$(cat <<- EOF | tr -d '\r' | sed 's/^[[:space:]]*//'
### Description
- [ ] Update the [Artifactory vulnerabilities](${{ secrets.NOTIFICATION_SHEET_URL }}) sheet with the \`v$IMAGE_TAG\` vulnerabilities.
**Purpose**: $PURPOSE
>[!NOTE]
>To update the \`Tentative Release\` column, follow these steps:
https://github.com/wazuh/${{ secrets.NOTIFICATION_REPO }}/issues/2049#issuecomment-2671590268
EOF
)
# Print the GH Variables content
echo "--- Variable Content ---"
echo "$GH_TITLE"
echo "------------------------"
echo "--- Variable Content ---"
echo "$GH_MESSAGE"
echo "------------------------"
## GH issue creation
ISSUE_URL=$(gh issue create \
-R wazuh/${{ secrets.NOTIFICATION_REPO }} \
--title "$GH_TITLE" \
--body "$GH_MESSAGE" \
--label "level/task" \
--label "type/maintenance" \
--label "request/operational")
## Adding the issue to the team project
PROJECT_ITEM_ID=$(gh project item-add \
${{ secrets.NOTIFICATION_PROJECT_NUMBER }} \
--url $ISSUE_URL \
--owner wazuh \
--format json \
| jq -r '.id')
## Setting Objective
gh project item-edit --id $PROJECT_ITEM_ID --project-id ${{ secrets.NOTIFICATION_PROJECT_ID }} --field-id ${{ secrets.NOTIFICATION_PROJECT_OBJECTIVE_ID }} --text "Security scans"
## Setting Priority
gh project item-edit --id $PROJECT_ITEM_ID --project-id ${{ secrets.NOTIFICATION_PROJECT_ID }} --field-id ${{ secrets.NOTIFICATION_PROJECT_PRIORITY_ID }} --single-select-option-id ${{ secrets.NOTIFICATION_PROJECT_PRIORITY_OPTION_ID }}
## Setting Size
gh project item-edit --id $PROJECT_ITEM_ID --project-id ${{ secrets.NOTIFICATION_PROJECT_ID }} --field-id ${{ secrets.NOTIFICATION_PROJECT_SIZE_ID }} --single-select-option-id ${{ secrets.NOTIFICATION_PROJECT_SIZE_OPTION_ID }}
## Setting Subteam
gh project item-edit --id $PROJECT_ITEM_ID --project-id ${{ secrets.NOTIFICATION_PROJECT_ID }} --field-id ${{ secrets.NOTIFICATION_PROJECT_SUBTEAM_ID }} --single-select-option-id ${{ secrets.NOTIFICATION_PROJECT_SUBTEAM_OPTION_ID }}