-
Notifications
You must be signed in to change notification settings - Fork 173
Expand file tree
/
Copy pathdeploy_static_files.py
More file actions
36 lines (26 loc) · 1.22 KB
/
deploy_static_files.py
File metadata and controls
36 lines (26 loc) · 1.22 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
import os
import subprocess
import sys
import paramiko
if len(sys.argv) == 1:
print('Usage: python deploy_static_files.py <Worker Node IPs seperated by space>')
exit(1)
STATIC_FILE = 'https://backend-ai-k8s-agent-static.s3.ap-northeast-2.amazonaws.com/bai-static.tar.gz'
ssh = paramiko.SSHClient()
ssh.load_system_host_keys()
ssh.set_missing_host_key_policy(paramiko.RejectPolicy())
for ip in sys.argv[1:]:
ssh.connect(ip)
# Get cwd and username
stdin, stdout, stderr = ssh.exec_command('pwd')
pwd = stdout.readlines()[0].strip().replace('\n', '')
print(f'pwd: {pwd}')
stdin, stdout, stderr = ssh.exec_command('whoami')
whoami = stdout.readlines()[0].strip().replace('\n', '')
print(f'whoami: {whoami}')
# delete old static files
stdin, stdout, stderr = ssh.exec_command(f'sudo rm -rf /opt/backend.ai && rm -rf {pwd}/bai*')
print(''.join(stdout.readlines()))
# Extract to /opt/backend.ai
stdin, stdout, stderr = ssh.exec_command(f'wget https://backend-ai-k8s-agent-static.s3.ap-northeast-2.amazonaws.com/bai-static.tar.gz && tar xvf {pwd}/bai-static.tar.gz && sudo mv {pwd}/backend.ai /opt && sudo chown {whoami}:{whoami} /opt/backend.ai')
print(''.join(stdout.readlines()))