-
Notifications
You must be signed in to change notification settings - Fork 406
144 lines (133 loc) · 4.67 KB
/
Procedure_push_docker_images.yml
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
run-name: Launch Push Docker Images - ${{ inputs.id }}
name: Push Docker Images
on:
workflow_dispatch:
inputs:
IMAGE_TAG:
description: 'Docker image tag'
default: '4.10.0'
required: true
PRODUCTS:
description: 'Comma-separated list of the image names to build and push'
default: 'wazuh-manager,wazuh-dashboard,wazuh-indexer'
required: true
FILEBEAT_MODULE_VERSION:
description: 'Filebeat module version'
required: true
REVISION:
description: 'Package revision'
default: '1'
required: true
PUSH_IMAGES:
description: 'Push images'
type: boolean
default: true
required: true
ID:
description: "ID used to identify the workflow uniquely."
type: string
required: false
workflow_call:
inputs:
IMAGE_TAG:
description: 'Docker image tag'
default: '4.10.0'
required: true
type: string
PRODUCTS:
description: 'Comma-separated list of the image names to build and push'
default: 'wazuh-manager,wazuh-dashboard,wazuh-indexer'
required: true
type: string
FILEBEAT_MODULE_VERSION:
description: 'Filebeat module version'
required: true
type: string
REVISION:
description: 'Package revision'
default: '1'
required: true
type: string
PUSH_IMAGES:
description: 'Push images'
type: boolean
default: true
required: true
ID:
description: "ID used to identify the workflow uniquely."
type: string
required: false
jobs:
build-and-push:
runs-on: ubuntu-latest
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 "* PRODUCTS: ${{ inputs.PRODUCTS }}"
echo "* FILEBEAT_MODULE_VERSION: ${{ inputs.FILEBEAT_MODULE_VERSION }}"
echo "* REVISION: ${{ inputs.REVISION }}"
echo "* PUSH_IMAGES: ${{ inputs.PUSH_IMAGES }}"
echo "---------------------------------------------"
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{ github.ref }}
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Install Docker Compose
run: |
sudo apt-get update
sudo apt-get install -y docker-compose
echo "Installed Docker Compose version: $(docker-compose --version)"
- name: Build Wazuh images
run: |
IMAGE_TAG=${{ inputs.IMAGE_TAG }}
FILEBEAT_MODULE_VERSION=${{ inputs.FILEBEAT_MODULE_VERSION }}
REVISION=${{ inputs.REVISION }}
PUSH_IMAGES=${{ inputs.PUSH_IMAGES }}
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]}
./build-docker-images/build-images.sh -v $WAZUH_VER -r $REVISION -d $DEV_STAGE -f $FILEBEAT_MODULE_VERSION
else
./build-docker-images/build-images.sh -v $IMAGE_TAG -r $REVISION -f $FILEBEAT_MODULE_VERSION
fi
ENV_FILE_PATH=".env"
# Save .env file contents to $GITHUB_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
- name: Tag and Push Wazuh images
if: ${{ inputs.PUSH_IMAGES }}
run: |
IMAGE_TAG=${{ inputs.IMAGE_TAG }}
IMAGE_NAMES=${{ inputs.PRODUCTS }}
IFS=',' read -r -a images <<< "$IMAGE_NAMES"
for image in "${images[@]}"; do
echo "Tagging and pushing wazuh/$image:${WAZUH_VERSION} to wazuh/$image:$IMAGE_TAG"
docker tag wazuh/$image:${WAZUH_VERSION} ${{ secrets.DOCKERHUB_USERNAME }}/$image:$IMAGE_TAG
docker push ${{ secrets.DOCKERHUB_USERNAME }}/$image:$IMAGE_TAG
done