forked from bcgov/supreme-court-viewer
-
Notifications
You must be signed in to change notification settings - Fork 0
206 lines (177 loc) · 5.83 KB
/
publish-lambdas.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
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
name: Deploy Lambda Functions
on:
push:
branches:
- master
paths:
- "aws/**"
workflow_dispatch:
env:
WORKING_DIRECTORY: ./aws
NODE_VERSION: 20
GITHUB_IMAGE_REPO: ghcr.io/bcgov/jasper
jobs:
get-lambdas:
runs-on: ubuntu-latest
outputs:
lambda_dir_list: ${{ steps.convert.outputs.LAMBDA_DIR_LIST }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Get Lambda directories
id: lambdas
shell: bash
working-directory: ${{ env.WORKING_DIRECTORY }}
run: |
dirs=$(find lambdas -mindepth 2 -maxdepth 2 -type d | sed 's|lambdas/||' | paste -sd ';' -) # Space-separated
echo "LAMBDA_DIRS=$dirs" >> $GITHUB_ENV
- name: Convert FOLDERS to JSON array
id: convert
shell: bash
working-directory: ${{ env.WORKING_DIRECTORY }}
run: |
LAMBDA_DIR_LIST=$(echo "${LAMBDA_DIRS}" | jq -R 'split(";")' -c)
echo "LAMBDA_DIR_LIST=$LAMBDA_DIR_LIST" >> $GITHUB_OUTPUT
deploy2gchr:
needs: get-lambdas
environment: dev
outputs:
short_sha: ${{ steps.short_sha.outputs.SHORT_SHA }}
permissions:
id-token: write
packages: write
runs-on: ubuntu-latest
strategy:
matrix:
lambda: ${{ fromJSON(needs.get-lambdas.outputs.lambda_dir_list) }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Build Lambdas codebase
uses: ./.github/workflows/actions/build-lambdas
with:
working_directory: ${{ env.WORKING_DIRECTORY }}
node_version: ${{ env.NODE_VERSION }}
- name: Log in to the GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Get short SHA
id: short_sha
run: |
echo "SHORT_SHA=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
- name: Parse Resource and Lambda Name
id: parse
run: |
echo "Lambda: ${{ matrix.lambda }}"
echo "RESOURCE=${{ matrix.lambda }%%/*}" >> $GITHUB_ENV
echo "LAMBDA=${{ matrix.lambda }##*/}" >> $GITHUB_ENV
- name: Setup Image Metadata
id: meta
uses: docker/metadata-action@v5
with:
images: |
${{ env.GITHUB_IMAGE_REPO }}/${{ env.RESOURCE }}.${{ env.LAMBDA }}
tags: |
type=raw,value=${{ steps.short_sha.outputs.SHORT_SHA }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
driver: docker
- name: Build ${{ matrix.lambda }} image
uses: docker/build-push-action@v6
with:
push: true
file: ./docker/aws/Dockerfile.release
context: ./aws
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
TARGET_FUNCTION=${{ matrix.lambda }}
NODE_VERSION=${{ env.NODE_VERSION }}
deploy2dev:
name: Deploy to DEV
needs: [get-lambdas, deploy2gchr]
env:
ENVIRONMENT: dev
permissions:
id-token: write
packages: write
runs-on: ubuntu-latest
environment: dev
strategy:
matrix:
lambda: ${{ fromJSON(needs.get-lambdas.outputs.lambda_dir_list) }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Deploy to ${{ env.ENVIRONMENT }}
uses: ./.github/workflows/actions/deploy-lambda
with:
environment: ${{ env.ENVIRONMENT }}
aws_account: ${{ vars.AWS_ACCOUNT }}
region: ${{ vars.AWS_REGION }}
app_name: ${{ vars.APP_NAME }}
aws_role_arn: ${{ vars.AWS_ROLE_ARN }}
ghcr_token: ${{ secrets.GITHUB_TOKEN }}
github_image_repo: ${{ env.GITHUB_IMAGE_REPO }}
lambda: ${{ matrix.lambda }}
short_sha: ${{ needs.deploy2gchr.outputs.short_sha }}
deploy2test:
name: Deploy to TEST
needs: [get-lambdas, deploy2gchr, deploy2dev]
env:
ENVIRONMENT: test
permissions:
id-token: write
packages: write
runs-on: ubuntu-latest
environment: test
strategy:
matrix:
lambda: ${{ fromJSON(needs.get-lambdas.outputs.lambda_dir_list) }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Deploy to ${{ env.ENVIRONMENT }}
uses: ./.github/workflows/actions/deploy-lambda
with:
environment: ${{ env.ENVIRONMENT }}
aws_account: ${{ vars.AWS_ACCOUNT }}
region: ${{ vars.AWS_REGION }}
app_name: ${{ vars.APP_NAME }}
aws_role_arn: ${{ vars.AWS_ROLE_ARN }}
ghcr_token: ${{ secrets.GITHUB_TOKEN }}
github_image_repo: ${{ env.GITHUB_IMAGE_REPO }}
lambda: ${{ matrix.lambda }}
short_sha: ${{ needs.deploy2gchr.outputs.short_sha }}
deploy2prod:
name: Deploy to PROD
needs: [get-lambdas, deploy2gchr, deploy2dev, deploy2test]
env:
ENVIRONMENT: prod
permissions:
id-token: write
packages: write
runs-on: ubuntu-latest
environment: prod
strategy:
matrix:
lambda: ${{ fromJSON(needs.get-lambdas.outputs.lambda_dir_list) }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Deploy to ${{ env.ENVIRONMENT }}
uses: ./.github/workflows/actions/deploy-lambda
with:
environment: ${{ env.ENVIRONMENT }}
aws_account: ${{ vars.AWS_ACCOUNT }}
region: ${{ vars.AWS_REGION }}
app_name: ${{ vars.APP_NAME }}
aws_role_arn: ${{ vars.AWS_ROLE_ARN }}
ghcr_token: ${{ secrets.GITHUB_TOKEN }}
github_image_repo: ${{ env.GITHUB_IMAGE_REPO }}
lambda: ${{ matrix.lambda }}
short_sha: ${{ needs.deploy2gchr.outputs.short_sha }}