11import { parseArgs } from 'node:util'
22import { printLog , runMain , timeout } from '../lib/executionUtils.ts'
33import { command } from '../lib/command.ts'
4- import { siteByDatacenter } from '../lib/datacenter.ts'
4+ import { getAllMinorDcs , getAllPrivateDcs } from '../lib/datacenter.ts'
55
66/**
77 * Orchestrate the deployments of the artifacts for specific DCs
@@ -12,15 +12,6 @@ const ONE_MINUTE_IN_SECOND = 60
1212const GATE_DURATION = 30 * ONE_MINUTE_IN_SECOND
1313const GATE_INTERVAL = ONE_MINUTE_IN_SECOND
1414
15- // Major DCs are the ones that are deployed last.
16- // They have their own step jobs in `deploy-manual.yml` and `deploy-auto.yml`.
17- const MAJOR_DCS = [ 'root' , 'us1' , 'eu1' ]
18-
19- // Minor DCs are all the DCs from `siteByDatacenter` that are not in `MAJOR_DCS`.
20- function getAllMinorDcs ( ) : string [ ] {
21- return Object . keys ( siteByDatacenter ) . filter ( ( dc ) => ! MAJOR_DCS . includes ( dc ) )
22- }
23-
2415if ( ! process . env . NODE_TEST_CONTEXT ) {
2516 runMain ( ( ) => main ( ...process . argv . slice ( 2 ) ) )
2617}
@@ -42,30 +33,56 @@ export async function main(...args: string[]): Promise<void> {
4233 } )
4334
4435 const version = positionals [ 0 ]
45- const uploadPath = positionals [ 1 ] === 'minor-dcs' ? getAllMinorDcs ( ) . join ( ',' ) : positionals [ 1 ]
36+ const datacenters = getDatacenters ( positionals [ 1 ] )
4637
47- if ( ! uploadPath ) {
48- throw new Error ( 'UPLOAD_PATH argument is required' )
38+ if ( ! datacenters ) {
39+ throw new Error ( 'DATACENTER argument is required' )
4940 }
5041
5142 if ( checkMonitors ) {
52- command `node ./scripts/deploy/check-monitors.ts ${ uploadPath } ` . withLogs ( ) . run ( )
43+ command `node ./scripts/deploy/check-monitors.ts ${ datacenters . join ( ',' ) } ` . withLogs ( ) . run ( )
5344 }
5445
55- command `node ./scripts/deploy/deploy.ts prod ${ version } ${ uploadPath } ` . withLogs ( ) . run ( )
56- command `node ./scripts/deploy/upload-source-maps.ts ${ version } ${ uploadPath } ` . withLogs ( ) . run ( )
46+ const uploadPathTypes = toDatacenterUploadPathType ( datacenters ) . join ( ',' )
5747
58- if ( checkMonitors && uploadPath !== 'root' ) {
59- 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 )
6053 }
6154}
6255
63- async function gateMonitors ( uploadPath : string ) : Promise < void > {
64- 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+
6559 for ( let i = 0 ; i < GATE_DURATION ; i += GATE_INTERVAL ) {
66- command `node ./scripts/deploy/check-monitors.ts ${ uploadPath } ` . run ( )
60+ command `node ./scripts/deploy/check-monitors.ts ${ datacenters . join ( ',' ) } ` . run ( )
6761 process . stdout . write ( '.' ) // progress indicator
6862 await timeout ( GATE_INTERVAL * 1000 )
6963 }
64+
7065 printLog ( ) // new line
7166}
67+
68+ function getDatacenters ( datacenterGroup : string ) : string [ ] {
69+ if ( datacenterGroup === 'minor-dcs' ) {
70+ return getAllMinorDcs ( )
71+ }
72+
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+ } )
88+ }
0 commit comments