-
Notifications
You must be signed in to change notification settings - Fork 5
/
deploy
50 lines (38 loc) · 1.37 KB
/
deploy
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
#!/usr/bin/env python3
# SITN deploy helper
import os
import argparse
import subprocess
import sys
import shutil
ALLOWED_INSTANCES = ["prepub", "prod", "dev", "local", "test"]
def load_env(env_file):
with open(env_file) as f:
for line in f:
if line.startswith('#') or not line.strip():
continue
key, value = line.strip().split('=', 1)
os.environ[key] = value or ''
def call_cmd(cmd):
print(" ".join(cmd))
subprocess.check_call(cmd)
def main():
parser = argparse.ArgumentParser(description="Déploiement infolica")
parser.add_argument("env", nargs="*", help="The environment config")
args = parser.parse_args()
if len(args.env) != 1:
sys.exit("Vous devez utiliser ce script avec au moins un argument: " + '|'.join(ALLOWED_INSTANCES))
instance = args.env[0]
if instance not in ALLOWED_INSTANCES:
sys.exit(f"L'instance {instance} n'est pas autorisée.")
dotenv_file = f"env.{instance}"
load_env(dotenv_file)
shutil.copy(dotenv_file, '.env')
print('DOCKER_HOST is: {}'.format(os.environ.get('DOCKER_HOST', 'not setted')))
call_cmd(["docker-compose", "build", "back"])
call_cmd(["docker-compose", "build", "front"])
call_cmd(["docker-compose", "down"])
call_cmd(["docker-compose", "up", "-d"])
print('\a')
if __name__ == "__main__":
main()