|
1 | 1 | import { parseArgs } from 'node:util' |
2 | 2 | import { printLog, runMain, timeout } from '../lib/executionUtils.ts' |
3 | 3 | import { command } from '../lib/command.ts' |
4 | | -import { siteByDatacenter } from '../lib/datacenter.ts' |
| 4 | +import { getAllMinorDcs, getAllPrivateDcs } from '../lib/datacenter.ts' |
5 | 5 |
|
6 | 6 | /** |
7 | 7 | * Orchestrate the deployments of the artifacts for specific DCs |
@@ -33,39 +33,56 @@ export async function main(...args: string[]): Promise<void> { |
33 | 33 | }) |
34 | 34 |
|
35 | 35 | const version = positionals[0] |
36 | | - const uploadPath = positionals[1] === 'minor-dcs' ? getAllMinorDcs().join(',') : positionals[1] |
| 36 | + const datacenters = getDatacenters(positionals[1]) |
37 | 37 |
|
38 | | - if (!uploadPath) { |
39 | | - throw new Error('UPLOAD_PATH argument is required') |
| 38 | + if (!datacenters) { |
| 39 | + throw new Error('DATACENTER argument is required') |
40 | 40 | } |
41 | 41 |
|
42 | 42 | if (checkMonitors) { |
43 | | - command`node ./scripts/deploy/check-monitors.ts ${uploadPath}`.withLogs().run() |
| 43 | + command`node ./scripts/deploy/check-monitors.ts ${datacenters.join(',')}`.withLogs().run() |
44 | 44 | } |
45 | 45 |
|
46 | | - command`node ./scripts/deploy/deploy.ts prod ${version} ${uploadPath}`.withLogs().run() |
47 | | - command`node ./scripts/deploy/upload-source-maps.ts ${version} ${uploadPath}`.withLogs().run() |
| 46 | + const uploadPathTypes = toDatacenterUploadPathType(datacenters).join(',') |
48 | 47 |
|
49 | | - if (checkMonitors && uploadPath !== 'root') { |
50 | | - await gateMonitors(uploadPath) |
| 48 | + command`node ./scripts/deploy/deploy.ts prod ${version} ${uploadPathTypes}`.withLogs().run() |
| 49 | + command`node ./scripts/deploy/upload-source-maps.ts ${version} ${uploadPathTypes}`.withLogs().run() |
| 50 | + |
| 51 | + if (checkMonitors) { |
| 52 | + await gateMonitors(datacenters) |
51 | 53 | } |
52 | 54 | } |
53 | 55 |
|
54 | | -async function gateMonitors(uploadPath: string): Promise<void> { |
55 | | - printLog(`Check monitors for ${uploadPath} during ${GATE_DURATION / ONE_MINUTE_IN_SECOND} minutes`) |
| 56 | +async function gateMonitors(datacenters: string[]): Promise<void> { |
| 57 | + printLog(`Check monitors for ${datacenters.join(',')} during ${GATE_DURATION / ONE_MINUTE_IN_SECOND} minutes`) |
| 58 | + |
56 | 59 | for (let i = 0; i < GATE_DURATION; i += GATE_INTERVAL) { |
57 | | - command`node ./scripts/deploy/check-monitors.ts ${uploadPath}`.run() |
| 60 | + command`node ./scripts/deploy/check-monitors.ts ${datacenters.join(',')}`.run() |
58 | 61 | process.stdout.write('.') // progress indicator |
59 | 62 | await timeout(GATE_INTERVAL * 1000) |
60 | 63 | } |
| 64 | + |
61 | 65 | printLog() // new line |
62 | 66 | } |
63 | 67 |
|
64 | | -// Major DCs are the ones that are deployed last. |
65 | | -// They have their own step jobs in `deploy-manual.yml` and `deploy-auto.yml`. |
66 | | -const MAJOR_DCS = ['root', 'us1', 'eu1'] |
| 68 | +function getDatacenters(datacenterGroup: string): string[] { |
| 69 | + if (datacenterGroup === 'minor-dcs') { |
| 70 | + return getAllMinorDcs() |
| 71 | + } |
67 | 72 |
|
68 | | -// Minor DCs are all the DCs from `siteByDatacenter` that are not in `MAJOR_DCS`. |
69 | | -function getAllMinorDcs(): string[] { |
70 | | - return Object.keys(siteByDatacenter).filter((dc) => !MAJOR_DCS.includes(dc)) |
| 73 | + if (datacenterGroup === 'private-regions') { |
| 74 | + return getAllPrivateDcs() |
| 75 | + } |
| 76 | + |
| 77 | + return datacenterGroup.split(',') |
| 78 | +} |
| 79 | + |
| 80 | +function toDatacenterUploadPathType(datacenters: string[]): string[] { |
| 81 | + return datacenters.map((datacenter) => { |
| 82 | + if (datacenter === 'gov') { |
| 83 | + return 'root' |
| 84 | + } |
| 85 | + |
| 86 | + return datacenter |
| 87 | + }) |
71 | 88 | } |
0 commit comments