-
Notifications
You must be signed in to change notification settings - Fork 0
152 lines (132 loc) · 5.7 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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
name: Release observability images
on:
workflow_dispatch:
env:
PACKER_VERSION: "latest"
ENV_FILE_PATH: .github/shared-variables/.env
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
permissions:
id-token: write
contents: read
jobs:
get-observability-version:
runs-on: ubuntu-latest
environment: release-node-images
outputs:
observability_version: ${{ steps.observability.outputs.version }}
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Load and Increment OBSERVABILITY_VERSION
id: observability
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)))
echo "version=${NEW_VERSION}" >> $GITHUB_OUTPUT
release-observability-image:
runs-on: ubuntu-latest
environment: release-node-images
needs: [get-observability-version]
strategy:
matrix:
cloud_provider: ['gcp', 'aws']
defaults:
run:
working-directory: ./packer
steps:
- name: Checkout Code
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: ${{ env.GCP_SERVICE_ACCOUNT }}
- 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-${{ needs.get-observability-version.outputs.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
remote-git-changes:
runs-on: ubuntu-latest
needs: [ release-observability-image, get-observability-version]
environment: release-node-images
env:
OBSERVABILITY_VERSION: ${{ needs.get-observability-version.outputs.observability_version }}
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: Alter observability version
run: |
sed -i "s/^OBSERVABILITY_VERSION=.*/OBSERVABILITY_VERSION=${{ env.OBSERVABILITY_VERSION }}/" ${{ env.ENV_FILE_PATH }}
echo "::notice::OBSERVABILITY_VERSION=${{ env.OBSERVABILITY_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 ${{ env.OBSERVABILITY_VERSION }}"
git tag -m "Release observability version ${{ env.OBSERVABILITY_VERSION }}" observability/${{ env.OBSERVABILITY_VERSION }}
git push origin HEAD --follow-tags