forked from qgriffith-zz/OpenEats
-
Notifications
You must be signed in to change notification settings - Fork 22
/
quick-start.py
executable file
·74 lines (62 loc) · 2.26 KB
/
quick-start.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
70
71
72
73
74
#!/usr/bin/env python
# encoding: utf-8
from time import sleep
from os import getcwd
from subprocess import call, Popen, PIPE
def download_images(version=None):
version = version if version is not None else 'latest'
print("==================")
print("Downloading Images")
print("==================")
call(['docker', 'pull', 'openeats/api:' + version])
call(['docker', 'pull', 'openeats/node:' + version])
call(['docker', 'pull', 'openeats/nginx:' + version])
def start_containers():
print("==================")
print("Starting OpenEats")
print("==================")
p = Popen(
['docker', 'ps', '-q', '-f', 'name=openeats_db_1'],
stdin=PIPE,
stdout=PIPE,
stderr=PIPE
)
output, err = p.communicate(b"input data that is passed to subprocess' stdin")
if output and not err:
print("Taking a database backup (saving as openeats.sql)...")
call(
'docker exec openeats_db_1 sh -c ' +
'\'exec mysqldump openeats -uroot -p"$MYSQL_ROOT_PASSWORD"\'' +
' > openeats.sql',
shell=True
)
else:
print("Creating the DB. This may take a minute...")
call(['docker-compose', '-f', 'docker-prod.yml', 'up', '-d', 'db'])
sleep(45)
p = Popen(
['docker', 'ps', '-q', '-f', 'name=openeats_api_1'],
stdin=PIPE,
stdout=PIPE,
stderr=PIPE
)
output, err = p.communicate(b"input data that is passed to subprocess' stdin")
if output and not err:
print("Taking a image backup save to 'site-media'...")
call(
'docker cp openeats_api_1:/code/site-media/ ' + getcwd(),
shell=True
)
call(['docker-compose', '-f', 'docker-prod.yml', 'stop', 'nginx'])
call(['docker-compose', '-f', 'docker-prod.yml', 'stop', 'api'])
call(['docker-compose', '-f', 'docker-prod.yml', 'stop', 'node'])
call(['docker-compose', '-f', 'docker-prod.yml', 'up', '-d'])
print("App started. Please wait ~30 seconds for the containers to come online.")
if __name__ == '__main__':
from sys import argv
print("OpenEats quick setup script")
try:
download_images(argv[1])
except IndexError:
download_images(None)
start_containers()