-
Notifications
You must be signed in to change notification settings - Fork 4
/
deploy
68 lines (53 loc) · 1.98 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env python3
import argparse
import subprocess
import os
from datetime import datetime
import re
import sys
from pathlib import Path
from dotenv import load_dotenv
CONTEXTS = ["internet", "intranet", "dev"]
ALLOWED_INSTANCES = ["prepub", "prod", "dev", "local"]
def check_settings_file(dest_instance):
# Do not deploy to the internet with DEBUG set to True
settings_file = Path("./sitn/settings.py")
with open(settings_file, 'r') as f:
settings = f.read()
is_debug = bool(re.search(r"^\s*DEBUG\s*=\s*True\s*$", settings, re.MULTILINE))
if is_debug:
if dest_instance not in ["local", "dev"]:
sys.exit("Cannot deploy if DEBUG=True in settings.py")
def main():
parser = argparse.ArgumentParser(description="Déploiement sitn applications")
parser.add_argument("env", nargs="*", help="The environment config")
args = parser.parse_args()
if len(args.env) != 2:
sys.exit(
"Vous devez utiliser ce script avec deux arguments. internet|intranet et prepub|prod|local|dev"
)
context = args.env[0]
instance = args.env[1]
if context not in CONTEXTS:
sys.exit("Le premier argument est faux.")
if instance not in ALLOWED_INSTANCES:
sys.exit("Le deuxième argument est faux.")
check_settings_file(instance)
env_file = f".env.{context}.{instance}"
os.environ['ENV_FILE'] = env_file
load_dotenv(Path(env_file), override=True)
print(f"{datetime.now().strftime('%Y-%m-%d %H:%M:%S')} - DOCKER_HOST is: {os.environ['DOCKER_HOST']}")
cmd = ["docker-compose", "build"]
print(" ".join(cmd))
subprocess.check_call(cmd)
cmd = ["docker-compose", "down", "-v"]
print(" ".join(cmd))
subprocess.check_call(cmd)
cmd = ["docker-compose", "up", "-d"]
print(" ".join(cmd))
subprocess.check_call(cmd)
os.environ["DOCKER_HOST"] = ""
print("\a")
print(f"{datetime.now().strftime('%Y-%m-%d %H:%M:%S')} - END")
if __name__ == "__main__":
main()