-
Notifications
You must be signed in to change notification settings - Fork 0
180 lines (173 loc) · 5.5 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
name: 'Deploy'
on:
push:
branches:
- 'main'
env:
WORKSPACE_ARTIFACT_API: 'explore_flights_api_artifact'
WORKSPACE_ARTIFACT_CRON: 'explore_flights_cron_artifact'
WORKSPACE_ARTIFACT_UI: 'explore_flights_ui_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.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_and_synth_cdk:
name: 'Build and synth cdk'
runs-on: ubuntu-latest
needs:
- build_and_test_api
- build_and_test_cron
- build_ui
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: '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:lhApiClientId=${{ secrets.LH_API_CLIENT_ID }}" --parameters "Cron-Prod:lhApiClientSecret=${{ secrets.LH_API_CLIENT_SECRET }}"