Repository navigation
281 lines (281 loc) · 11 KB
/
Copy pathdeploy.yml
File metadata and controls
281 lines (281 loc) · 11 KB
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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
name: deploy
on:
push:
branches: [main]
workflow_dispatch:
permissions:
contents: read
concurrency:
group: production-release
cancel-in-progress: false
jobs:
changes:
runs-on: ubuntu-latest
outputs:
assets: ${{ steps.diff.outputs.assets }}
deploy: ${{ steps.diff.outputs.deploy }}
client: ${{ steps.diff.outputs.client }}
server: ${{ steps.diff.outputs.server }}
steps:
- uses: actions/checkout@v7
with:
fetch-depth: 2
filter: blob:none
sparse-checkout: .github
- id: diff
env:
BEFORE: ${{ github.event.before }}
EVENT: ${{ github.event_name }}
run: |
assets=false
client=false
server=false
if [ "$EVENT" = workflow_dispatch ] || [ "$BEFORE" = 0000000000000000000000000000000000000000 ] || ! git cat-file -e "$BEFORE^{commit}" 2>/dev/null; then
assets=true
client=true
server=true
else
if git diff --quiet "$BEFORE" HEAD -- package.json bun.lock bunfig.toml patches packages/protocol packages/simulation .github/workflows/deploy.yml scripts/smoke-container.py; then
:
else
client=true
server=true
fi
if ! git diff --quiet "$BEFORE" HEAD -- packages/assets .github/workflows/deploy.yml; then
assets=true
client=true
fi
if ! git diff --quiet "$BEFORE" HEAD -- apps/game scripts/build-assets.mjs scripts/service-worker.js turbo.json; then
client=true
fi
if ! git diff --quiet "$BEFORE" HEAD -- apps/server Dockerfile .dockerignore 'packages/assets/public/models/maps/*-physics.glb.gz' 'packages/assets/public/models/maps/*-nav.json' 'packages/assets/public/models/maps/*-bomb.bin.gz' 'packages/assets/public/models/maps/*-breakables.json' 'packages/assets/public/models/maps/*-doors.json'; then
server=true
fi
fi
# A code-only push can reference assets whose earlier sync failed.
# The assets job checks the exact published receipt before downloading.
if [ "$client" = true ]; then
assets=true
fi
{
echo "assets=$assets"
echo "deploy=$client"
echo "client=$client"
echo "server=$server"
} >> "$GITHUB_OUTPUT"
assets:
name: Wait for server asset publication
needs: changes
if: needs.changes.outputs.assets == 'true'
runs-on: ubuntu-latest
timeout-minutes: 120
steps:
- uses: actions/checkout@v7
with:
filter: blob:none
sparse-checkout-cone-mode: false
sparse-checkout: /packages/assets/manifest.json
- name: Wait for the independent na1 sync service
env:
ASSET_CDN_URL: ${{ vars.ASSET_CDN_URL }}
run: |
node --input-type=module <<'JAVASCRIPT'
import { readFileSync } from 'node:fs';
import { execFileSync } from 'node:child_process';
const body = readFileSync('packages/assets/manifest.json', 'utf8');
const manifest = JSON.parse(body);
const tree = execFileSync('git', ['rev-parse', 'HEAD:packages/assets'], { encoding: 'utf8' }).trim();
const base = `${process.env.ASSET_CDN_URL.replace(/\/$/, '')}/releases/${manifest.release}`;
const deadline = Date.now() + 115 * 60_000;
while (Date.now() < deadline) {
try {
const receipt = await fetch(`${base}/verified/${tree}.json`, { signal: AbortSignal.timeout(30_000) });
if (receipt.ok && await receipt.text() === body) {
const release = await fetch(`${base}/manifest.json`, { signal: AbortSignal.timeout(30_000) });
if (release.ok && await release.text() === body) {
console.log(`Server published verified asset tree ${tree}`);
process.exit(0);
}
}
} catch (error) {
console.log(`Publication check will retry: ${error.message}`);
}
console.log(`Waiting for na1 to publish ${manifest.release}`);
await new Promise(resolve => setTimeout(resolve, 30_000));
}
throw new Error('Server asset publication timed out; inspect cs2go-assets-sync.service on na1');
JAVASCRIPT
deploy:
needs: [changes, assets]
if: always() && !cancelled() && needs.changes.result == 'success' && needs.changes.outputs.deploy == 'true' && (needs.assets.result == 'success' || needs.assets.result == 'skipped')
runs-on: ubuntu-latest
env:
VERCEL_ORG_ID: ${{ vars.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ vars.VERCEL_PROJECT_ID }}
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
ASSET_CDN_URL: ${{ vars.ASSET_CDN_URL }}
steps:
- uses: actions/checkout@v7
with:
filter: blob:none
sparse-checkout-cone-mode: false
sparse-checkout: |
/apps/
/scripts/
/package.json
/bun.lock
/bunfig.toml
/patches/
/turbo.json
/packages/protocol/
/packages/simulation/
/packages/assets/package.json
/packages/assets/manifest.json
/packages/assets/pipeline.mjs
- uses: oven-sh/setup-bun@v2
- run: |
test -n "$VERCEL_TOKEN" && test -n "$VERCEL_ORG_ID" && test -n "$VERCEL_PROJECT_ID" && test -n "$ASSET_CDN_URL" || {
echo 'Configure Vercel and R2 repository variables/secrets; see docs/deployment.md.'
exit 1
}
- run: bun install --frozen-lockfile
- uses: actions/cache@v6
with:
path: .turbo
key: turbo-${{ runner.os }}-${{ github.sha }}
restore-keys: turbo-${{ runner.os }}-
- run: bunx --bun vercel@65.8.0 pull --yes --environment=production --token="$VERCEL_TOKEN"
- run: bunx --bun vercel@65.8.0 build --prod --token="$VERCEL_TOKEN"
- run: bunx --bun vercel@65.8.0 deploy --prebuilt --prod --token="$VERCEL_TOKEN"
server-image:
name: Publish server image
needs: changes
if: needs.changes.outputs.server == 'true'
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v7
with:
filter: blob:none
sparse-checkout-cone-mode: false
sparse-checkout: |
/package.json
/bun.lock
/bunfig.toml
/patches/
/apps/game/package.json
/apps/server/package.json
/packages/assets/package.json
/packages/protocol/
/packages/simulation/
/scripts/smoke-container.py
/Dockerfile
/.dockerignore
/apps/server/
/packages/assets/public/models/maps/*-physics.glb.gz
/packages/assets/public/models/maps/*-nav.json
/packages/assets/public/models/maps/*-bomb.bin.gz
/packages/assets/public/models/maps/*-breakables.json
/packages/assets/public/models/maps/*-doors.json
- uses: docker/setup-buildx-action@v4
- name: Log in to DHI
uses: docker/login-action@v4
with:
registry: dhi.io
username: ${{ secrets.DHI_USERNAME }}
password: ${{ secrets.DHI_TOKEN }}
- name: Log in to GHCR
uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build server
uses: docker/build-push-action@v7
with:
context: .
file: Dockerfile
platforms: linux/amd64
load: true
tags: ghcr.io/${{ github.repository }}/server:sha-${{ github.sha }}
labels: org.opencontainers.image.revision=${{ github.sha }}
cache-from: type=gha,scope=server
cache-to: type=gha,mode=max,scope=server
- name: Smoke test server image
run: python3 scripts/smoke-container.py server "ghcr.io/$GITHUB_REPOSITORY/server:sha-$GITHUB_SHA"
- name: Publish server
env:
IMAGE: ghcr.io/${{ github.repository }}/server
run: |
docker tag "$IMAGE:sha-$GITHUB_SHA" "$IMAGE:latest"
docker push "$IMAGE:sha-$GITHUB_SHA"
docker push "$IMAGE:latest"
echo "### Server image" >> "$GITHUB_STEP_SUMMARY"
echo "\`$IMAGE:latest\` and \`$IMAGE:sha-$GITHUB_SHA\`" >> "$GITHUB_STEP_SUMMARY"
client-image:
name: Publish client image
needs: [changes, assets]
if: always() && !cancelled() && needs.changes.result == 'success' && needs.changes.outputs.client == 'true' && (needs.assets.result == 'success' || needs.assets.result == 'skipped')
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v7
with:
filter: blob:none
sparse-checkout-cone-mode: false
sparse-checkout: |
/package.json
/bun.lock
/bunfig.toml
/patches/
/apps/game/package.json
/apps/server/package.json
/packages/assets/package.json
/packages/protocol/
/packages/simulation/
/scripts/smoke-container.py
/apps/game/
/scripts/build-assets.mjs
/scripts/service-worker.js
/packages/assets/manifest.json
/packages/assets/pipeline.mjs
- uses: docker/setup-buildx-action@v4
- name: Log in to DHI
uses: docker/login-action@v4
with:
registry: dhi.io
username: ${{ secrets.DHI_USERNAME }}
password: ${{ secrets.DHI_TOKEN }}
- name: Log in to GHCR
uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build client
uses: docker/build-push-action@v7
with:
context: .
file: apps/game/Dockerfile
platforms: linux/amd64
load: true
tags: ghcr.io/${{ github.repository }}/client:sha-${{ github.sha }}
labels: org.opencontainers.image.revision=${{ github.sha }}
cache-from: type=gha,scope=client
cache-to: type=gha,mode=max,scope=client
build-args: ASSET_CDN_URL=${{ vars.ASSET_CDN_URL }}
- name: Smoke test client image
run: python3 scripts/smoke-container.py client "ghcr.io/$GITHUB_REPOSITORY/client:sha-$GITHUB_SHA"
- name: Publish client
env:
IMAGE: ghcr.io/${{ github.repository }}/client
run: |
docker tag "$IMAGE:sha-$GITHUB_SHA" "$IMAGE:latest"
docker push "$IMAGE:sha-$GITHUB_SHA"
docker push "$IMAGE:latest"
echo "### Client image" >> "$GITHUB_STEP_SUMMARY"
echo "\`$IMAGE:latest\` and \`$IMAGE:sha-$GITHUB_SHA\`" >> "$GITHUB_STEP_SUMMARY"