-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocker-update.py
78 lines (61 loc) · 2 KB
/
docker-update.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
75
76
77
78
import docker
import subprocess
from simple_term_menu import TerminalMenu
client = docker.from_env()
containers = client.containers.list()
for container in containers:
dep_container = str(container.labels['com.docker.compose.depends_on'])
if dep_container != "":
dep_container = dep_container[:dep_container.index(":")]
containers.remove(client.containers.get(dep_container))
def update_all():
for container in containers:
update_container(container)
def update_selective():
for container in containers:
print("Update container " + str(container.name) + " ?")
options = ["Yes", "No", "Exit"]
menu = TerminalMenu(options)
index = menu.show()
if options[index] == "Yes":
update_container(container)
elif options[index] == "No":
continue
elif options[index] == "Exit":
break
def update_container(container):
dep_container = str(container.labels['com.docker.compose.depends_on'])
if dep_container != "":
dep_container = dep_container[:dep_container.index(":")]
subprocess.run(["/usr/bin/docker", "stop", dep_container])
subprocess.run(["/usr/bin/docker", "stop", str(container.name)])
subprocess.run([
"/usr/local/bin/docker-compose",
"-f",
container.labels['com.docker.compose.project.config_files'],
"up",
"-d",
"--build",
"--pull=always",
"--force-recreate"])
print("Update all containers?")
options = ["Yes", "No", "Exit"]
menu = TerminalMenu(options)
index = menu.show()
if options[index] == "Yes":
update_all()
elif options[index] == "No":
update_selective()
elif options[index] == "Exit":
quit()
print("...")
print("...")
print("...")
print("Prune everything?")
options = ["Yes", "Exit"]
menu = TerminalMenu(options)
index = menu.show()
if options[index] == "Yes":
subprocess.run(["/usr/bin/docker", "system", "prune", "-f", "-a"])
elif options[index] == "Exit":
quit()