-
Notifications
You must be signed in to change notification settings - Fork 0
135 lines (118 loc) · 4.98 KB
/
release-observability-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
name: Create and upload packer generated images
on:
push:
branches:
- 'main'
- 'lma/release/tags'
env:
PACKER_VERSION: "latest"
AWS_ROLE_ARN: "arn:aws:iam::192549843005:role/github-devops-cd"
permissions:
id-token: write
contents: read
jobs:
update-observability-version:
runs-on: ubuntu-latest
environment: release-node-images
env:
ENV_FILE_PATH: .github/shared-variables/.env
steps:
- uses: actions/create-github-app-token@v1
id: app-token
with:
app-id: 1086655
private-key: ${{ secrets.APP_PRIVATE_KEY }}
- name: Checkout Code
uses: actions/checkout@v4
with:
token: ${{ steps.app-token.outputs.token }}
- name: Load and Increment OBSERVABILITY_VERSION
run: |
if [ ! -f ${{ env.ENV_FILE_PATH }} ]; then
echo "::error::${{ env.ENV_FILE_PATH }} file not found!"
exit 1
fi
OBSERVABILITY_VERSION=$(grep '^OBSERVABILITY_VERSION=' .github/shared-variables/.env | cut -d '=' -f2)
if [ -z "$OBSERVABILITY_VERSION" ]; then
echo "::error::OBSERVABILITY_VERSION not found in .${{ env.ENV_FILE_PATH }}!"
exit 1
fi
NEW_VERSION=$(printf "%05d" $((10#$OBSERVABILITY_VERSION + 1)))
sed -i "s/^OBSERVABILITY_VERSION=.*/OBSERVABILITY_VERSION=${NEW_VERSION}/" ${{ env.ENV_FILE_PATH }}
echo "::notice::OBSERVABILITY_VERSION=${NEW_VERSION}"
- name: Commit and Push Changes
run: |
git config user.name "github-actions[bot]"
git config user.email "[email protected]"
git commit -am "Increment OBSERVABILITY_VERSION to ${NEW_VERSION}"
git push origin HEAD
release-observability-image:
runs-on: ubuntu-latest
environment: release-node-images
needs: [update-observability-version]
strategy:
matrix:
cloud_provider: ['gcp', 'aws']
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: Configure Cloud Credentials
if: matrix.cloud_provider == 'gcp'
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
if: matrix.cloud_provider == 'aws'
uses: aws-actions/configure-aws-credentials@v4
with:
aws-region: ${{ env.OBSERVABILITY_AWS_REGION }}
role-to-assume: ${{ env.AWS_ROLE_ARN }}
role-session-name: ReleaseObservabilityImageSession
- name: Setup Packer
uses: hashicorp/setup-packer@main
id: setup
with:
version: ${{ env.PACKER_VERSION }}
- name: Initialize Packer
run: packer init observability
- name: Determine Image Name
run: echo "IMAGE_NAME=concordium-observability-node-${{ env.OBSERVABILITY_VERSION }}-${{ matrix.cloud_provider == 'gcp' && 'x86-64' || 'x86_64' }}" >> $GITHUB_ENV
- name: Check if Image Already Exists
run: |
if [ "${{ matrix.cloud_provider }}" == "gcp" ]; then
IMAGE_ID=$(gcloud compute images list --project="concordium-mgmt-0" --filter="name=(${IMAGE_NAME})" --format="value(name)")
elif [ "${{ matrix.cloud_provider }}" == "aws" ]; then
IMAGE_ID=$(aws ec2 describe-images --filters Name=name,Values=$IMAGE_NAME --query 'Images[*].ImageId' --output text)
else
echo "::error::Unknown cloud provider: ${{ matrix.cloud_provider }}"
exit 1
fi
echo "IMAGE_ID=$IMAGE_ID" >> $GITHUB_ENV
- name: Setup subnet id
if: ${{ matrix.cloud_provider == 'aws' }}
run: |
VALUE=$(echo '${{ env.REGION_TO_SUBNET }}' | jq -r --arg key "${{ env.OBSERVABILITY_AWS_REGION }}" '.[$key]')
if [[ $VALUE == "null" ]]; then
echo "::error::Key '${{ env.AWS_ENVIRONMENT_REGION }}' not found in ${{ env.REGION_TO_SUBNET }}"
exit 1
fi
echo "AWS_SUBNET_ID=$VALUE" >> $GITHUB_ENV
- name: Set variables
if: ${{ env.IMAGE_ID == '' }}
run: |
export AMI_USERS='["727113945353"]'
export CLOUD_PROVIDER=${{ matrix.cloud_provider }}
export TARGET_AWS_REGIONS=$(echo '${{ env.ENVIRONMENT_TO_AWS_REGION }}' | jq -r -c --arg region "$AWS_REGION" '[..|strings]|unique | map(select(. != $region))')
envsubst < observability/variables.pkrvars.hcl.template > variables.pkrvars.hcl
- name: Build Image
if: ${{ env.IMAGE_ID == '' }}
run: |
set -eo pipefail
packer build -machine-readable -var-file=./variables.pkrvars.hcl observability | tee build-output.log