mirror of
https://gitlab.sectorq.eu/jaydee/registry-utils.git
synced 2025-12-14 18:44:53 +01:00
lala
This commit is contained in:
68
registry_utils.py
Normal file
68
registry_utils.py
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
import os
|
||||||
|
import subprocess
|
||||||
|
import json
|
||||||
|
import re
|
||||||
|
import getopt
|
||||||
|
import sys
|
||||||
|
from datetime import datetime, timedelta
|
||||||
|
from textwrap import indent
|
||||||
|
import yaml
|
||||||
|
|
||||||
|
try:
|
||||||
|
opts, args = getopt.getopt(sys.argv[1:], "gr", ["command=", "help", "output="])
|
||||||
|
except getopt.GetoptError as err:
|
||||||
|
#usage()
|
||||||
|
sys.exit(2)
|
||||||
|
output = None
|
||||||
|
# QJ : getopts
|
||||||
|
_MODE = "manual"
|
||||||
|
_FIRST = _TEST = _RESTORE = _BACKUP = _SYNC = _START = _STOP = False
|
||||||
|
_EXECUTE = True
|
||||||
|
_DATE = "pick"
|
||||||
|
|
||||||
|
for o, a in opts:
|
||||||
|
if o == "-g":
|
||||||
|
_ACTION = "generate_config"
|
||||||
|
elif o in ("-r", "--registry"):
|
||||||
|
_ACTION = "write_to_registry"
|
||||||
|
else:
|
||||||
|
print("Parameter unknown")
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
|
||||||
|
def get_docker_images():
|
||||||
|
# Use openssl command to get certificate subject and expiration date
|
||||||
|
cmnd = "docker image ls"
|
||||||
|
status, output = subprocess.getstatusoutput(cmnd)
|
||||||
|
#output, _ = process.communicate()
|
||||||
|
#print(output)
|
||||||
|
data = output.splitlines()
|
||||||
|
return data
|
||||||
|
|
||||||
|
|
||||||
|
def generate_config(data):
|
||||||
|
local_registry = "localhost:5000/library/"
|
||||||
|
interval = "60m"
|
||||||
|
yaml_config = {"sync":[]}
|
||||||
|
for line in data:
|
||||||
|
if "localhost:5000" in line:
|
||||||
|
continue
|
||||||
|
d = line.split()
|
||||||
|
print(f"{d[0]} : {d[1]}")
|
||||||
|
image = d[0].split("/")
|
||||||
|
if "<none>" == d[1]:
|
||||||
|
yaml_config["sync"].append({"source":f"{d[0]}","target": f"{local_registry}{d[0]}","type":"image","interval":interval,"backup": "\"backup-{{.Ref.Tag}}\""})
|
||||||
|
else:
|
||||||
|
yaml_config["sync"].append({"source":f"{d[0]}:{d[1]}","target": f"{local_registry}{d[0]}:{d[1]}","type":"image","interval":interval,"backup": "\"backup-{{.Ref.Tag}}\""})
|
||||||
|
config = yaml.dump(yaml_config,sort_keys=False)
|
||||||
|
print(config)
|
||||||
|
return config
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if _ACTION == "generate_config":
|
||||||
|
generate_config(get_docker_images())
|
||||||
|
|
||||||
|
elif _ACTION == "write_to_registry":
|
||||||
|
get_docker_images()
|
||||||
Reference in New Issue
Block a user