dockerutils/docker_update.py

37 lines
1.2 KiB
Python
Raw Normal View History

2022-06-20 02:06:30 +00:00
import os
import sys
2022-06-20 02:35:24 +00:00
import subprocess
2022-06-20 02:40:52 +00:00
import datetime
2022-06-20 02:06:30 +00:00
if len(sys.argv) != 3:
print("Invalid number of arguments\n")
exit(1)
2022-06-20 02:16:26 +00:00
path = os.path.abspath(sys.argv[1])
spec_file = os.path.abspath(sys.argv[2])
2022-06-20 02:06:30 +00:00
with open(spec_file,"r") as f:
lines = f.readlines()
2022-06-20 02:40:52 +00:00
print(">>>>>>>>>> docker_update.py @", datetime.datetime.now()," <<<<<<<<<<")
2022-06-20 02:35:24 +00:00
2022-06-20 02:06:30 +00:00
for line in lines:
s = line.strip()
2022-06-20 02:27:50 +00:00
if s.startswith("#"):
continue
2022-06-20 02:13:09 +00:00
fullpath = os.path.join(path, s)
2022-12-06 03:58:25 +00:00
if os.path.isdir(fullpath) and ("docker-compose.yml" in os.listdir(fullpath)):
2022-12-06 03:57:34 +00:00
fullpath = os.path.join(fullpath, "docker compose.yml")
2022-06-20 02:13:09 +00:00
print("========= Processing " + fullpath + " =========")
2022-12-06 03:57:34 +00:00
print(subprocess.check_output("docker compose -f " + fullpath + " pull", shell=True, stderr=subprocess.STDOUT).decode())
print(subprocess.check_output("docker compose -f " + fullpath + " up -d", shell=True, stderr=subprocess.STDOUT).decode())
2022-06-20 02:13:09 +00:00
else:
print("========= Skipping " + fullpath + ": invalid dir or docker-compos.yml =========")
2022-06-20 02:06:30 +00:00
print("========== CLEANING UP ==========")
2022-06-20 02:42:20 +00:00
print(subprocess.check_output("docker system prune -af", shell=True, stderr=subprocess.STDOUT).decode())
2022-06-20 02:06:30 +00:00
2022-06-20 02:35:24 +00:00
print("Docker update complete!\n")