This repository has been archived by the owner on Aug 3, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcreateBackendDocker.py
63 lines (50 loc) · 1.67 KB
/
createBackendDocker.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
#!/usr/bin/python3
import os
import sys
disableQuestions = False
def main():
global disableQuestions
if len(sys.argv) > 1:
disableQuestions = sys.argv[1]
containerName = "blob_backend"
# Ask for custom tag.
tag = askInput("Specifiy Tag [latest]: ", "latest")
# Print create cmd to validate
dockerCMD = f"docker run --restart always -d -p 5001:80 --ip 10.10.10.2 --name {containerName} --network blob blobcd/blob:{tag}"
print(dockerCMD)
# Validate cmd and create new container, pull latest image:tag
if askYesOrNo("Befehl korrekt? [j, N]: "):
# Remove old container if any.
oldContainerExists = os.system(f"docker ps | grep {containerName}")
if oldContainerExists is 0:
removeOld = askYesOrNo("Remove old container? [j, N]: ")
if removeOld is True:
os.system(f"docker rm -f {containerName}")
os.system(f"docker pull blobcd/blob:{tag}")
os.system(dockerCMD)
def askYesOrNo(text):
global disableQuestions
if disableQuestions is False:
yes = {'yes','y', 'ye', 'j'}
no = {'no','n', ''}
choice = input(text).lower()
if choice in yes:
return True
elif choice in no:
return False
else:
print("Please respond with 'yes' or 'no'")
else:
return True
def askInput(question, default="latest"):
global disableQuestions
if disableQuestions is False:
answer = input(question)
if answer is "":
return default
else:
return answer
else:
return "b_latest"
if __name__ == "__main__":
main()