forked from zauberzeug/nicegui
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.py
More file actions
executable file
·61 lines (53 loc) · 1.93 KB
/
deploy.py
File metadata and controls
executable file
·61 lines (53 loc) · 1.93 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
#!/usr/bin/env python3
import json
import subprocess
import time
def run(cmd: list[str], *, capture: bool = False) -> str:
"""Run a command and return the output."""
if capture:
return subprocess.run(cmd, check=True, capture_output=True, text=True).stdout
subprocess.run(cmd, check=True)
return ''
try:
tag = run(['git', 'describe', '--abbrev=0', '--tags', '--match', 'v*'], capture=True).strip()
version = tag.lstrip('v') or '0.0.0'
except Exception:
version = '0.0.0'
run(['fly', 'deploy', '--wait-timeout', '600', '--lease-timeout', '30s', '--build-arg', f'VERSION={version}'])
instances = {
'yyz': 2, # Toronto, Ontario (Canada)
'iad': 3, # Washington DC, Virginia (US)
'sjc': 2, # San Jose, California (US)
'lax': 2, # Los Angeles, California (US)
'mia': 2, # Miami, Florida (US)
'sea': 2, # Seattle, Washington (US)
'fra': 3, # Frankfurt, Germany
'ams': 2, # Amsterdam, Netherlands
'cdg': 2, # Paris, France
'lhr': 2, # London, England (UK)
'jnb': 1, # Johannesburg, South Africa
'bom': 1, # Mumbai, India
'nrt': 3, # Tokyo, Japan
'sin': 3, # Singapore
'syd': 1, # Sydney, Australia
'gru': 1, # Sao Paulo, Brazil
}
print('scaling regions...')
for region, count in instances.items():
run(['fly', 'scale', 'count', f'app={count}', '--region', region, '-y'])
time.sleep(2)
# NOTE: pin first machine per region to avoid cold-start latency
print('pinning machines...')
machines_json = run(['fly', 'machines', 'list', '--json'], capture=True)
machines = json.loads(machines_json)
pinned_regions = set()
for m in machines:
region = m.get('region', 'unknown')
if region in pinned_regions:
continue
machine_id = m.get('id')
if machine_id:
run(['fly', 'machine', 'update', machine_id, '--autostop=false', '-y'])
print(f'pinned {machine_id} in {region}')
pinned_regions.add(region)
time.sleep(2)