add suffix-flag

master
Clemens Klug 2018-08-06 13:45:48 +02:00
parent a6ba86a4c4
commit b14bab60f0
3 changed files with 22 additions and 20 deletions

View File

@ -129,6 +129,7 @@ def args_setup(description):
parser.add_argument("compose_files", nargs="+") parser.add_argument("compose_files", nargs="+")
parser.add_argument("--output", "-o") parser.add_argument("--output", "-o")
parser.add_argument("--ignore", "-i", nargs="+", default=False) parser.add_argument("--ignore", "-i", nargs="+", default=False)
parser.add_argument("--match-suffix", "-s", action="store_false")
return parser return parser
if __name__ == "__main__": if __name__ == "__main__":

View File

@ -17,7 +17,7 @@ TAG_STORE = {}
def api_call(url): def api_call(url):
result = requests.get(url) result = requests.get(url)
if not result.ok: if not result.ok:
log.error(result, result.url) log.error(f"{result}, {result.status_code}, {result.url}")
return {} return {}
data = result.json() data = result.json()
tags = {} tags = {}
@ -44,7 +44,11 @@ def replace(string, replacements):
return string return string
def compare(base, other, replacements=[("-","+"),]): def compare(base, other, match_suffix=False, replacements=[("-","+"),]):
if match_suffix:
suffix = base.split("-")[-1]
if not other.endswith(suffix):
return False
base = replace(base, replacements) base = replace(base, replacements)
other = replace(other, replacements) other = replace(other, replacements)
v1 = version.parse(base) v1 = version.parse(base)
@ -53,23 +57,17 @@ def compare(base, other, replacements=[("-","+"),]):
log.debug(f"{v1} < {v2}: {result}") log.debug(f"{v1} < {v2}: {result}")
return result return result
def get_new_tags(image): def get_new_tags(image, match_suffix=False):
if not ":" in image: if not ":" in image:
log.warn("using implicit latest, skip") log.warn("using implicit latest, skip")
return return
image_name, current_tag = image.split(":") image_name, current_tag = image.split(":")
if not image_name in TAG_STORE: if not image_name in TAG_STORE:
TAG_STORE[image_name] = get_tags(image_name) TAG_STORE[image_name] = get_tags(image_name)
#if current_tag in TAG_STORE[image_name]:
# first_update = TAG_STORE[image_name][current_tag]
#else:
# print("!!! FALLBACK!")
# first_update = list(TAG_STORE[image_name].values())[0]
#print(first_update)
new_tags = {} new_tags = {}
for tag in TAG_STORE[image_name]: for tag in TAG_STORE[image_name]:
log.debug("check("+str(tag)+")") log.debug("check("+str(tag)+")")
if compare(current_tag, tag): if compare(current_tag, tag, match_suffix):
log.debug("NEWER!!!") log.debug("NEWER!!!")
update = TAG_STORE[image_name][tag] update = TAG_STORE[image_name][tag]
new_tags[tag] = str(update) new_tags[tag] = str(update)

View File

@ -1,13 +1,15 @@
import argparse import argparse
import json import json
import logging
import docker_compose import docker_compose
import image_tags import image_tags
log = logging
def find_updates(image_ref, usages): def find_updates(image_ref, usages, match_suffix=False):
try: try:
newer_tags = image_tags.get_new_tags(image_ref) newer_tags = image_tags.get_new_tags(image_ref, match_suffix)
except ValueError as e: except ValueError as e:
newer_tags = e.args newer_tags = e.args
return { return {
@ -24,20 +26,21 @@ def main(args):
image_ref = f"{image}:{tag}" image_ref = f"{image}:{tag}"
if image_ref in updates: if image_ref in updates:
continue continue
updates[image_ref] = find_updates(image_ref, images[image][tag]) updates[image_ref] = find_updates(image_ref, images[image][tag], args.match_suffix)
for usage in images[image][tag]: for usage in images[image][tag]:
if not "base_images" in usage: if not "base_images" in usage:
continue continue
for base in usage["base_images"]: for base in usage["base_images"]:
info = [{
"is_base_image": True,
"path": usage["path"],
"service_name": usage["service_name"]
}]
if base in updates: if base in updates:
continue updates[base]["usages"].append(info)
else: else:
info = { log.info(f"find base image updates for {base}")
"is_base_image": True, updates[base] = find_updates(base, info, args.match_suffix)
"path": usage["path"],
"service_name": usage["service_name"]
}
updates[base] = find_updates(base, info)
if args.output: if args.output:
with open(args.output, "w") as out: with open(args.output, "w") as out: