-
Notifications
You must be signed in to change notification settings - Fork 0
327 lines (308 loc) · 12.8 KB
/
release-node-images.yaml
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
name: Create and upload packer generated images
on:
push:
branches:
- lma/release/tags
workflow_dispatch:
inputs:
node_version:
description: "Specify the Concordium node version to build. Use the format: x.y.z-q (e.g., 1.2.3-0), where q is the build version."
required: true
type: string
release_type:
description: "Select the type of release to be made. Options include 'alpha' or 'rc' (release candidate)."
required: true
type: choice
options:
- alpha
- rc
observability_version:
description: "The observability version. If in doubt, do not define"
required: false
type: string
env:
PACKER_VERSION: "latest"
AWS_ROLE_ARN: "arn:aws:iam::192549843005:role/github-devops-cd"
IMAGE_COUNT_UPPER_LIMIT: 20
IMAGE_COUNT_LOWER_LIMIT: 10
CONCORDIUM_NODE_VERSION: ${{ inputs.node_version }}
RELEASE_TYPE: ${{ inputs.release_type }}
permissions:
id-token: write
contents: read
jobs:
generate-matrix:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- name: Initialize Matrix with alpha environments
run: |
MATRIX_JSON=$(echo '[
{
"env": "stagenet",
"tld": "com",
"cloud_provider": "aws"
},
{
"env": "flynet",
"tld": "com",
"cloud_provider": "aws"
},
{
"env": "stagenet",
"tld": "com",
"cloud_provider": "gcp"
}
]' | jq -c)
echo "MATRIX_JSON=${MATRIX_JSON}" >> $GITHUB_ENV
- name: Release candidate environments
if: ${{ env.RELEASE_TYPE == 'rc' }}
run: |
MATRIX_JSON=$(echo "$MATRIX_JSON" | jq -c '. + [
{
"env": "testnet",
"tld": "com",
"cloud_provider": "aws"
},
{
"env": "testnet",
"tld": "com",
"cloud_provider": "gcp"
},
{
"env": "mainnet",
"tld": "software",
"cloud_provider": "aws",
"ami_users": ["727113945353"]
},
{
"env": "mainnet",
"tld": "software",
"cloud_provider": "gcp"
}
]')
echo "MATRIX_JSON=${MATRIX_JSON}" >> $GITHUB_ENV
- name: Output Matrix JSON
id: set-matrix
run: echo "matrix=$MATRIX_JSON" >> $GITHUB_OUTPUT
release-concordium-node-image:
outputs:
image_name_gcp_stagenet: ${{ steps.image_name.outputs.image_name_gcp_stagenet }}
image_name_gcp_testnet: ${{ steps.image_name.outputs.image_name_gcp_testnet }}
image_name_gcp_mainnet: ${{ steps.image_name.outputs.image_name_gcp_mainnet }}
image_name_aws_stagenet: ${{ steps.image_name.outputs.image_name_aws_stagenet }}
image_name_aws_testnet: ${{ steps.image_name.outputs.image_name_aws_testnet }}
image_name_aws_mainnet: ${{ steps.image_name.outputs.image_name_aws_mainnet }}
image_name_aws_flynet: ${{ steps.image_name.outputs.image_name_aws_flynet }}
needs: [generate-matrix]
environment: release-node-images
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include: ${{ fromJSON(needs.generate-matrix.outputs.matrix) }}
defaults:
run:
working-directory: ./packer
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Load common variables
run: cat ../.github/shared-variables/.env >> $GITHUB_ENV
# - name: Set custom observability version
# if: ${{ inputs.observability_version != "" }}
# run: echo "OBSERVABILITY_VERSION=${{ inputs.observability_version }}" >> $GITHUB_ENV
- name: Configure GCP credentials
uses: google-github-actions/auth@v2
with:
project_id: concordium-mgmt-0
workload_identity_provider: projects/761241104197/locations/global/workloadIdentityPools/github/providers/concordium
service_account: [email protected]
- name: Setup AWS REGION
run: |
VALUE=$(echo '${{ env.ENVIRONMENT_TO_AWS_REGION }}' | jq -r --arg key "${{ matrix.env }}" '.[$key]')
if [[ $VALUE == "null" || $VALUE == "" ]]; then
echo "::error::Key '${{ matrix.env }}' not found in ${{ env.ENVIRONMENT_TO_AWS_REGION }}"
exit 1
fi
echo "AWS_ENVIRONMENT_REGION=$VALUE" >> $GITHUB_ENV
- name: Setup subnet id
if: ${{ matrix.cloud_provider == 'aws' }}
run: |
VALUE=$(echo '${{ env.REGION_TO_SUBNET }}' | jq -r --arg key "${{ env.AWS_ENVIRONMENT_REGION }}" '.[$key]')
if [[ $VALUE == "null" || $VALUE == "" ]]; then
echo "::error::Key '${{ env.AWS_ENVIRONMENT_REGION }}' not found in ${{ env.REGION_TO_SUBNET }}"
exit 1
fi
echo "SUBNET_ID=$VALUE" >> $GITHUB_ENV
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-region: ${{ env.AWS_ENVIRONMENT_REGION }}
role-to-assume: ${{ env.AWS_ROLE_ARN }}
role-session-name: ReleaseConcordiumNodeImageSession
- name: Download file from S3
run: |
aws s3 cp s3://distribution.${{ matrix.env }}.concordium.${{ matrix.tld }}/deb/concordium-${{ matrix.env }}-node_${{ env.CONCORDIUM_NODE_VERSION }}_amd64.deb ./concordium-node.deb
- name: Setup image name
run: |
if [ "${{ matrix.cloud_provider }}" == "aws" ]; then
echo "IMAGE_NAME=${{ matrix.env }}-${{ env.CONCORDIUM_NODE_VERSION }}-concordium-node-${{ env.OBSERVABILITY_VERSION }}-x86_64" >> $GITHUB_ENV
elif [ "${{ matrix.cloud_provider }}" == "gcp" ]; then
VERSION_TRANSFORMED=${CONCORDIUM_NODE_VERSION//./-}
echo "IMAGE_NAME=${{ matrix.env }}-v$VERSION_TRANSFORMED-concordium-node-${{ env.OBSERVABILITY_VERSION }}-x86-64" >> $GITHUB_ENV
else
echo "::error::Unknown cloud provider: ${{ matrix.cloud_provider }}"
exit 1
fi
- name: Test if image exists
run: |
if [ "${{ matrix.cloud_provider }}" == "aws" ]; then
echo "IMAGE_ID=$(aws ec2 describe-images --filters Name=name,Values=$IMAGE_NAME --query 'Images[*].ImageId' --output text)" >> $GITHUB_ENV
elif [ "${{ matrix.cloud_provider }}" == "gcp" ]; then
echo "IMAGE_ID=$(gcloud compute images list --project="concordium-${{ matrix.env }}-0" --filter="name=($IMAGE_NAME)" --format="value(name)")" >> $GITHUB_ENV
else
echo "::error::Unknown cloud provider: ${{ matrix.cloud_provider }}"
exit 1
fi
- name: Set source image id
if: ${{ env.IMAGE_ID == '' }}
run: |
if [ "${{ matrix.cloud_provider }}" == "aws" ]; then
SOURCE_IMAGE_ID=$(aws ec2 describe-images --filters Name=name,Values=concordium-observability-node-${{ env.OBSERVABILITY_VERSION }}-x86_64 --query 'Images[*].ImageId' --output text)
elif [ "${{ matrix.cloud_provider }}" == "gcp" ]; then
SOURCE_IMAGE_ID=$(gcloud compute images list --project="concordium-mgmt-0" --filter="name=(concordium-observability-node-${{ env.OBSERVABILITY_VERSION }}-x86-64)" --format="value(name)")
else
echo "::error::Unknown cloud provider: ${{ matrix.cloud_provider }}"
exit 1
fi
echo "SOURCE_IMAGE_ID=$SOURCE_IMAGE_ID" >> $GITHUB_ENV
- name: Packer concordium-node init
if: ${{ env.IMAGE_ID == '' }}
run: packer init concordium-node
- name: Set variables
if: ${{ env.IMAGE_ID == '' }}
run: |
export CLOUD_PROVIDER=${{ matrix.cloud_provider }}
export ENVIRONMENT=${{ matrix.env }}
export CONCORDIUM_NODE_PATH=./concordium-node.deb
export AWS_SUBNET_ID=${{ env.SUBNET_ID }}
export AMI_USERS='${{ matrix.ami_users }}'
if [ "$AMI_USERS" == "" ]; then
export AMI_USERS='[]'
fi
envsubst < concordium-node/variables.pkrvars.hcl.template > variables.pkrvars.hcl
- name: Build concordium-node image
if: ${{ env.IMAGE_ID == '' }}
run: packer build -var-file=./variables.pkrvars.hcl concordium-node
- name: Output image name
if: ${{ env.IMAGE_ID == '' }}
id: image_name
run: |
echo "image_name_${{ matrix.cloud_provider }}_${{ matrix.env }}=$IMAGE_NAME" >> $GITHUB_OUTPUT
remote-git-changes:
runs-on: ubuntu-latest
environment: release-node-images
needs: [release-concordium-node-image]
steps:
- uses: actions/create-github-app-token@v1
id: app-token
with:
app-id: ${{ vars.APP_ID }}
private-key: ${{ secrets.APP_PRIVATE_KEY }}
- name: Checkout Code
uses: actions/checkout@v4
with:
token: ${{ steps.app-token.outputs.token }}
- name: Commit and Push Changes
run: |
git config user.name "github-actions[bot]"
git config user.email "[email protected]"
git tag node/${{ env.CONCORDIUM_NODE_VERSION }}
git push origin --follow-tags
notify-slack-changes:
needs: [release-concordium-node-image]
environment: release-node-images
runs-on: ubuntu-latest
if: ${{ always() }}
steps:
- name: Sample updated Image IDs
run: |
echo '${{ toJson(needs.release-concordium-node-image.outputs) }}' > info.json
UPDATED_IMAGE_IDS=$(cat info.json | jq -c | jq -R | sed 's/^"//;s/"$//')
echo "UPDATED_IMAGE_IDS=$UPDATED_IMAGE_IDS" >> $GITHUB_ENV
- name: Send updated image ids to slack
if: ${{ env.UPDATED_IMAGE_IDS != '{}' && env.UPDATED_IMAGE_IDS != '' }}
uses: slackapi/[email protected]
with:
payload: >-
{
"text": "The following image ids has been updated: ${{ env.UPDATED_IMAGE_IDS }}"
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_URL }}
fetch-images:
needs: [release-concordium-node-image]
runs-on: ubuntu-latest
environment: release-node-images
outputs:
images: ${{ steps.fetch-images.outputs.images }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Load common variables
run: cat .github/shared-variables/.env >> $GITHUB_ENV
- name: Configure GCP credentials
uses: google-github-actions/auth@v2
with:
project_id: concordium-mgmt-0
workload_identity_provider: projects/761241104197/locations/global/workloadIdentityPools/github/providers/concordium
service_account: [email protected]
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-region: ${{ env.OBSERVABILITY_AWS_REGION }}
role-to-assume: ${{ env.AWS_ROLE_ARN }}
role-session-name: ReleaseConcordiumNodeImageSession
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Fetch images to be deleted
id: fetch-images
run: |
set -e
TARGET_AWS_REGIONS=$(echo '${{ env.ENVIRONMENT_TO_AWS_REGION }}' | jq -r -c '[..|strings]|unique| join(" ")')
IMAGES=$(python scripts/find_images.py --image_count_lower_limit ${{ env.IMAGE_COUNT_LOWER_LIMIT }} --image_count_upper_limit ${{ env.IMAGE_COUNT_UPPER_LIMIT }} --aws_regions $TARGET_AWS_REGIONS)
echo "images=$(echo $IMAGES | jq '@json' | sed 's/^"\(.*\)"$/\1/')" >> $GITHUB_OUTPUT
notify-slack-on-image-deletions:
needs: [fetch-images]
environment: release-node-images
runs-on: ubuntu-latest
if: ${{ needs.fetch-images.outputs.images != '{}' }}
steps:
- name: Send GitHub Action trigger data to Slack workflow
uses: slackapi/[email protected]
with:
payload: >-
{
"text": "There are image which should be deleted: ```$INFRA_IMAGES_REPOSITORY_PATH/scripts/delete_amis.sh '${{ needs.fetch-images.outputs.images }}'```"
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_URL }}
notify-slack-on-failure:
needs: [release-concordium-node-image]
environment: release-node-images
runs-on: ubuntu-latest
if: ${{ failure() }}
steps:
- name: Send GitHub Action trigger data to Slack workflow
uses: slackapi/[email protected]
with:
payload: >-
{
"text": "One or more GitHub Actions jobs failed: <${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|Click here> to see the run."
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_URL }}