forked from QxLabIreland/listening-test
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pack_transfer.py
executable file
·69 lines (58 loc) · 2.78 KB
/
pack_transfer.py
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
import os
import shutil
import tarfile
import subprocess
subprocess.run('npm run build --prefix listening-test-react', shell=True)
try:
print('Start cleaning build folder and archive file...')
base_dir = 'listeningTest'
if os.path.exists(base_dir):
shutil.rmtree(base_dir)
# Archive file
base_dir_tgz = base_dir + '.tgz'
if os.path.exists(base_dir_tgz):
os.remove(base_dir_tgz)
# # Move tornado server files
# server_dir = os.path.join(base_dir, 'server')
# for v in ['/handlers', '/tools', '/server.py', '/mongodbconnection.py', '/url.py']:
# source = 'listening-test-server' + v
# if os.path.isfile(source):
# shutil.copyfile(source, server_dir + v)
# else:
# shutil.copytree(source, server_dir + v, ignore=shutil.ignore_patterns('*.pyc', '__pycache__'))
print('Move server files...')
server_dir = os.path.join(base_dir, 'server')
shutil.copytree('listening-test-server', server_dir, ignore=shutil.ignore_patterns(
'*.pyc', '__pycache__', '.idea', 'static2', 'venv', '.gitignore'))
print('Move react files...')
html_dir = os.path.join(base_dir, 'html')
shutil.copytree("listening-test-react/build", html_dir)
print('Move configuration files...')
# shutil.copyfile("golisten.supervisor.conf", os.path.join(base_dir, "golisten.supervisor.conf"))
# shutil.copyfile("golisten.nginx.conf", os.path.join(base_dir, "golisten.nginx.conf"))
# Docker config files
shutil.copyfile("Dockerfile.backend", os.path.join(
base_dir, 'server', "Dockerfile"))
shutil.copyfile("Dockerfile.frontend", os.path.join(
base_dir, 'html', "Dockerfile"))
shutil.copyfile("golisten.nginx80.conf", os.path.join(
base_dir, 'html', "golisten.nginx80.conf"))
shutil.copyfile("docker-compose.yml",
os.path.join(base_dir, "docker-compose.yml"))
# print('Create tar file...')
# with tarfile.open(base_dir_tgz, "w:gz") as tar:
# tar.add(base_dir, arcname=os.path.basename(base_dir))
# You may need to delete this
# print('Transfer the files to server...')
# print(os.getcwd())
# subprocess.run(
# f'scp -i .ssh/golisten_ssh_key.pem -r {base_dir}/* [email protected]:/home/golistenadmin/golisten/', shell=True)
# print('Start ssh and run script...')
# # subprocess.run('ssh -i ForStudy.pem [email protected] "pip install tornado pymongo"')
# # subprocess.run('ssh -i ForStudy.pem [email protected] "sudo supervisorctl reload"')
# subprocess.run(
# 'ssh -i .ssh/golisten_ssh_key.pem -t [email protected] "sudo supervisorctl restart golisten"', shell=True)
# input('You can close the window now')
except Exception as ex:
print(ex)
input('Error occurred')