-
-
Notifications
You must be signed in to change notification settings - Fork 0
234 lines (194 loc) · 6.62 KB
/
tiles-worker.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
230
231
232
233
234
name: Tiles Worker
on:
workflow_dispatch:
pull_request:
push:
branches: [main]
concurrency:
group: ${{ github.workflow }}
cancel-in-progress: true
env:
tofu_version: '1.7.1'
tg_version: '0.58.12'
jobs:
test:
name: Test
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./tiles
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version-file: './tiles/.nvmrc'
- name: Run npm install
run: npm ci
- name: Run linter
run: npm run lint
if: ${{ !cancelled() }}
- name: Run formatter
run: npm run format
if: ${{ !cancelled() }}
- name: Run tsc
run: npm run check
if: ${{ !cancelled() }}
- name: Run unit tests & coverage
run: npm run test:cov
if: ${{ !cancelled() }}
build:
name: Build
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./tiles
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version-file: './tiles/.nvmrc'
- name: Run npm install
run: npm ci
- name: Run tsc
run: npm run check
if: ${{ !cancelled() }}
- name: Wrangler build
run: npm run build
if: ${{ !cancelled() }}
- name: Upload build output
uses: actions/upload-artifact@v4
with:
name: tiles-build-output
path: tiles/dist
retention-days: 14
if: ${{ !cancelled() }}
check-terragrunt:
name: Check Terragrunt
runs-on: ubuntu-latest
defaults:
run:
working-directory: deployment
steps:
- name: 'Checkout'
uses: actions/checkout@main
- name: Install 1Password CLI
uses: 1password/install-cli-action@v1
- name: Install Terragrunt
uses: eLco/setup-terragrunt@v1
with:
terragrunt_version: ${{ env.tg_version }}
- name: 'Install OpenTofu'
uses: opentofu/setup-opentofu@v1
with:
tofu_version: ${{ env.tofu_version }}
tofu_wrapper: false
- name: Check Formatting
run: terragrunt hclfmt --terragrunt-check --terragrunt-diff
- name: Check TF fmt
env:
ENVIRONMENT: dev
OP_SERVICE_ACCOUNT_TOKEN: ${{ matrix.environment == 'prod' && secrets.OP_TF_PROD_ENV || secrets.OP_TF_DEV_ENV }}
TF_VAR_tiles_build_dir: "${{ github.workspace }}/dist"
run: op run --env-file=".env" -- terragrunt run-all fmt -diff -check
plan-terragrunt:
needs: build
name: Plan Terragrunt
runs-on: ubuntu-latest
strategy:
max-parallel: 1
matrix:
environment: [dev, prod]
if: github.ref != 'refs/heads/main' && github.event_name != 'workflow_dispatch'
steps:
- name: 'Checkout'
uses: actions/checkout@main
- name: Install Terragrunt
uses: eLco/setup-terragrunt@v1
with:
terragrunt_version: ${{ env.tg_version }}
- name: Install 1Password CLI
uses: 1password/install-cli-action@v1
- name: 'Install OpenTofu'
uses: opentofu/setup-opentofu@v1
with:
tofu_version: ${{ env.tofu_version }}
tofu_wrapper: false
- name: 'Get build artifact'
uses: actions/download-artifact@v4
with:
name: tiles-build-output
path: "${{ github.workspace }}/dist"
- name: Plan All
working-directory: ${{ github.workspace }}/deployment
env:
ENVIRONMENT: ${{ matrix.environment }}
OP_SERVICE_ACCOUNT_TOKEN: ${{ matrix.environment == 'prod' && secrets.OP_TF_PROD_ENV || secrets.OP_TF_DEV_ENV }}
TF_VAR_tiles_build_dir: "${{ github.workspace }}/dist"
run: op run --env-file=".env" -- terragrunt run-all plan -no-color 2>&1 | tee "${{github.workspace}}/plan_output.txt" && exit ${PIPESTATUS[0]};
kv-warming:
needs: [build, test]
name: KV Warming
runs-on: mich
if: github.event_name == 'workflow_dispatch' || github.ref == 'refs/heads/main'
defaults:
run:
working-directory: ./tiles
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version-file: './tiles/.nvmrc'
- name: Run npm install
run: npm ci
- name: Get tiles.json
run: echo "TILES_JSON=$(jq -c . < ${{ github.workspace }}/deployment/modules/cloudflare/tiles-worker/tiles.tfvars.json)" >> $GITHUB_ENV
- name: Run kv warming
env:
S3_ACCESS_KEY: ${{ secrets.CLOUDFLARE_TILES_R2_KV_TOKEN_ID }}
S3_SECRET_KEY: ${{ secrets.CLOUDFLARE_TILES_R2_KV_TOKEN_HASHED_VALUE }}
S3_ENDPOINT: https://${{ secrets.CLOUDFLARE_ACCOUNT_ID }}.r2.cloudflarestorage.com
KV_API_KEY: ${{ secrets.CLOUDFLARE_TILES_R2_KV_TOKEN_VALUE }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
# Figure out how to extract this from terraform at some point or get it into github vars
KV_NAMESPACE_ID: 5a4b82694e8b490db8b8904cdaea4f00
BUCKET_KEY: tiles-weur
DEPLOYMENT_KEY: ${{ fromJson(env.TILES_JSON).pmtiles_deployment_key }}
run: npm run kv:warm
deploy-terragrunt:
needs: [build, test, kv-warming]
name: Deploy Terragrunt
runs-on: ubuntu-latest
if: github.event_name == 'workflow_dispatch' || github.ref == 'refs/heads/main'
env:
ENVIRONMENT: ${{ github.ref == 'refs/heads/main' && 'prod' || 'dev' }}
steps:
- name: 'Checkout'
uses: actions/checkout@main
- name: Install 1Password CLI
uses: 1password/install-cli-action@v1
- name: Install Terragrunt
uses: eLco/setup-terragrunt@v1
with:
terragrunt_version: ${{ env.tg_version }}
- name: 'Install OpenTofu'
uses: opentofu/setup-opentofu@v1
with:
tofu_version: ${{ env.tofu_version }}
tofu_wrapper: false
- name: 'Get build artifact'
uses: actions/download-artifact@v4
with:
name: tiles-build-output
path: "${{ github.workspace }}/dist"
- name: Deploy All
working-directory: ${{ github.workspace }}/deployment
env:
OP_SERVICE_ACCOUNT_TOKEN: ${{ github.ref == 'refs/heads/main' && secrets.OP_TF_PROD_ENV || secrets.OP_TF_DEV_ENV }}
TF_VAR_tiles_build_dir: "${{ github.workspace }}/dist"
run: op run --env-file=".env" -- terragrunt run-all apply --terragrunt-non-interactive