-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanage.py
45 lines (41 loc) · 1.44 KB
/
manage.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
import click
import os
@click.command()
@click.argument('environment', required=True, type=click.Choice(['dev', 'prod']))
@click.argument('action', required=True, type=click.Choice(['logs', 'up', 'down', 'ssh', 'sloc', 'test', 'generate']))
def manage(environment, action):
# Handle other commands (sloc, ssh)
if action == 'ssh':
os.system('ssh root@<not implemented>')
return
elif action == 'test':
os.system('docker-compose build backend')
os.system('docker-compose run backend pytest')
return
elif action == 'sloc':
os.system("find . -name '*.py' | xargs wc -l")
os.system("find . -name '*.vue' | xargs wc -l")
return
# Main commands (logs, up, down)
if environment == 'prod':
host = "DOCKER_HOST='ssh://root@<not implemented>'"
else:
host = ""
if environment == 'prod':
compose_file = 'docker-compose.prod.yml'
else:
compose_file = 'docker-compose.dev.yml'
extra_args = ""
if action == 'up':
extra_args = "--build "
if environment == 'prod':
extra_args += "--detach"
else:
extra_args += "--abort-on-container-exit"
if action == 'generate':
action = 'run mnemonic python3 generate.py'
command = f"{host} docker-compose -f docker-compose.yml -f {compose_file} {action} {extra_args}"
print(command)
os.system(command)
if __name__ == '__main__':
manage()