dockerutils/docker_update.py

37 lines
1.2 KiB
Python

import os
import sys
import subprocess
import datetime
if len(sys.argv) != 3:
print("Invalid number of arguments\n")
exit(1)
path = os.path.abspath(sys.argv[1])
spec_file = os.path.abspath(sys.argv[2])
with open(spec_file,"r") as f:
lines = f.readlines()
print(">>>>>>>>>> docker_update.py @", datetime.datetime.now()," <<<<<<<<<<")
for line in lines:
s = line.strip()
if s.startswith("#"):
continue
fullpath = os.path.join(path, s)
if os.path.isdir(fullpath) and ("docker-compose.yml" in os.listdir(fullpath)):
fullpath = os.path.join(fullpath, "docker compose.yml")
print("========= Processing " + fullpath + " =========")
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())
else:
print("========= Skipping " + fullpath + ": invalid dir or docker-compos.yml =========")
print("========== CLEANING UP ==========")
print(subprocess.check_output("docker system prune -af", shell=True, stderr=subprocess.STDOUT).decode())
print("Docker update complete!\n")