-
Notifications
You must be signed in to change notification settings - Fork 0
229 lines (221 loc) · 7.25 KB
/
deploy.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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
name: 'Deploy'
on:
push:
branches:
- 'main'
paths-ignore:
- 'go/proxy/**'
env:
WORKSPACE_ARTIFACT_API: 'explore_flights_api_artifact'
WORKSPACE_ARTIFACT_CRON: 'explore_flights_cron_artifact'
WORKSPACE_ARTIFACT_UI: 'explore_flights_ui_artifact'
WORKSPACE_ARTIFACT_OTEL_COLLECTOR: 'otel_collector_artifact'
WORKSPACE_ARTIFACT_CDK: 'explore_flights_cdk_artifact'
jobs:
build_and_test_api:
name: 'Build and test API'
runs-on: ubuntu-latest
steps:
- name: 'Checkout'
uses: actions/checkout@v4
- name: 'Setup go'
uses: actions/setup-go@v5
with:
go-version-file: 'go/api/go.mod'
cache-dependency-path: 'go/api/go.sum'
- name: 'Test'
working-directory: 'go/api'
run: 'go test ./...'
- name: 'Build'
working-directory: 'go/api'
env:
GOOS: 'linux'
GOARCH: 'arm64' # keep this in sync with the arch configured in CDK!
CGO_ENABLED: '0'
run: |
go build -o bootstrap -tags "lambda"
- name: 'Store API artifact'
uses: actions/upload-artifact@v4
with:
name: ${{ env.WORKSPACE_ARTIFACT_API }}
path: 'go/api/bootstrap'
retention-days: 1
build_and_test_cron:
name: 'Build and test cron'
runs-on: ubuntu-latest
steps:
- name: 'Checkout'
uses: actions/checkout@v4
- name: 'Setup go'
uses: actions/setup-go@v5
with:
go-version-file: 'go/cron/go.mod'
cache-dependency-path: 'go/cron/go.sum'
- name: 'Test'
working-directory: 'go/cron'
run: 'go test ./...'
- name: 'Build'
working-directory: 'go/cron'
env:
GOOS: 'linux'
GOARCH: 'arm64' # keep this in sync with the arch configured in CDK!
CGO_ENABLED: '0'
run: |
go build -o bootstrap -tags "lambda,lambda.norpc"
- name: 'Store cron artifact'
uses: actions/upload-artifact@v4
with:
name: ${{ env.WORKSPACE_ARTIFACT_CRON }}
path: 'go/cron/bootstrap'
retention-days: 1
build_ui:
name: 'Build UI'
runs-on: ubuntu-latest
steps:
- name: 'Checkout'
uses: actions/checkout@v4
- name: 'Setup node'
uses: actions/setup-node@v4
with:
node-version: '20'
- name: 'Install npm dependencies'
working-directory: 'ui'
run: 'npm install'
- name: 'Build'
working-directory: 'ui'
run: 'npm run build'
- name: 'Prepare UI resources bundle'
working-directory: 'ui/dist'
run: 'zip -r ../${{ env.WORKSPACE_ARTIFACT_UI }}.zip .'
- name: 'Store UI artifact'
uses: actions/upload-artifact@v4
with:
name: ${{ env.WORKSPACE_ARTIFACT_UI }}
path: 'ui/${{ env.WORKSPACE_ARTIFACT_UI }}.zip'
retention-days: 1
build_otel_collector:
name: 'Build otel collector'
runs-on: ubuntu-latest
steps:
- name: 'Checkout'
uses: actions/checkout@v4
with:
submodules: 'true'
- name: 'Setup go'
uses: actions/setup-go@v5
with:
go-version-file: 'opentelemetry-lambda/collector/go.mod'
cache-dependency-path: 'opentelemetry-lambda/collector/go.sum'
- name: 'Build'
working-directory: 'opentelemetry-lambda/collector'
env:
GOOS: 'linux'
GOARCH: 'arm64' # keep this in sync with the arch configured in CDK!
CGO_ENABLED: '0'
BUILDTAGS: 'lambdacomponents.custom,lambdacomponents.receiver.otlp,lambdacomponents.processor.decouple,lambdacomponents.exporter.otlphttp'
run: |
make build
- name: 'Store otel collector artifact'
uses: actions/upload-artifact@v4
with:
name: ${{ env.WORKSPACE_ARTIFACT_OTEL_COLLECTOR }}
path: 'opentelemetry-lambda/collector/build/extensions/collector'
retention-days: 1
build_and_synth_cdk:
name: 'Build and synth cdk'
runs-on: ubuntu-latest
needs:
- build_and_test_api
- build_and_test_cron
- build_ui
- build_otel_collector
steps:
- name: 'Checkout'
uses: actions/checkout@v4
- name: 'Download API artifact'
uses: actions/download-artifact@v4
with:
name: ${{ env.WORKSPACE_ARTIFACT_API }}
path: .
- name: 'Prepare API lambda bundle'
run: '(chmod +x bootstrap && zip -q cdk/api_lambda_bundle.zip bootstrap && rm bootstrap)'
- name: 'Download cron artifact'
uses: actions/download-artifact@v4
with:
name: ${{ env.WORKSPACE_ARTIFACT_CRON }}
path: .
- name: 'Prepare cron lambda bundle'
run: '(chmod +x bootstrap && zip -q cdk/cron_lambda_bundle.zip bootstrap && rm bootstrap)'
- name: 'Download UI artifact'
uses: actions/download-artifact@v4
with:
name: ${{ env.WORKSPACE_ARTIFACT_UI }}
path: 'cdk/'
- name: 'Download otel collector artifact'
uses: actions/download-artifact@v4
with:
name: ${{ env.WORKSPACE_ARTIFACT_OTEL_COLLECTOR }}
path: .
- name: 'Prepare otel collector lambda extension bundle'
run: |
mkdir lambda_layer_bundle
mkdir lambda_layer_bundle/extensions
mv collector lambda_layer_bundle/extensions/layer
cp collector.yaml lambda_layer_bundle/
chmod +x lambda_layer_bundle/extensions/layer
(cd lambda_layer_bundle && zip -r ../cdk/otel_collector_layer_bundle.zip .)
rm -rf lambda_layer_bundle
- name: 'Setup node'
uses: actions/setup-node@v4
with:
node-version: '20'
- name: 'Install npm dependencies'
working-directory: 'cdk'
run: 'npm install'
- name: 'Build'
working-directory: 'cdk'
run: 'npm run build'
- name: 'Install cdk'
working-directory: 'cdk'
run: 'npm install -g aws-cdk'
- name: 'Synth cdk'
working-directory: 'cdk'
run: 'cdk synth --app bin/cdk.js'
- name: 'Store cdk synth artifact'
uses: actions/upload-artifact@v4
with:
name: ${{ env.WORKSPACE_ARTIFACT_CDK }}
path: |
cdk/cdk.out/
cdk/cdk.json
retention-days: 1
deploy:
name: 'Deploy'
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
environment:
name: 'prod'
permissions:
id-token: write
needs:
- build_and_synth_cdk
steps:
- name: 'Download cdk synth artifact'
uses: actions/download-artifact@v4
with:
name: ${{ env.WORKSPACE_ARTIFACT_CDK }}
path: .
- name: 'Setup node'
uses: actions/setup-node@v4
with:
node-version: '20'
- name: 'Install cdk'
run: 'npm install -g aws-cdk'
- name: 'AWS Credentials'
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_CDK_ROLE }}
aws-region: ${{ secrets.AWS_CDK_REGION }}
- name: 'Deploy'
run: |
cdk --app ./cdk.out deploy --require-approval never "Data-Prod" "Website-Prod" "Cron-Prod" "Route53-Prod" --parameters "Cron-Prod:webhookUrl=${{ secrets.WEBHOOK_URL }}"