add suffix-flag
parent
a6ba86a4c4
commit
b14bab60f0
|
|
@ -129,6 +129,7 @@ def args_setup(description):
|
|||
parser.add_argument("compose_files", nargs="+")
|
||||
parser.add_argument("--output", "-o")
|
||||
parser.add_argument("--ignore", "-i", nargs="+", default=False)
|
||||
parser.add_argument("--match-suffix", "-s", action="store_false")
|
||||
return parser
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ TAG_STORE = {}
|
|||
def api_call(url):
|
||||
result = requests.get(url)
|
||||
if not result.ok:
|
||||
log.error(result, result.url)
|
||||
log.error(f"{result}, {result.status_code}, {result.url}")
|
||||
return {}
|
||||
data = result.json()
|
||||
tags = {}
|
||||
|
|
@ -44,7 +44,11 @@ def replace(string, replacements):
|
|||
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)
|
||||
other = replace(other, replacements)
|
||||
v1 = version.parse(base)
|
||||
|
|
@ -53,23 +57,17 @@ def compare(base, other, replacements=[("-","+"),]):
|
|||
log.debug(f"{v1} < {v2}: {result}")
|
||||
return result
|
||||
|
||||
def get_new_tags(image):
|
||||
def get_new_tags(image, match_suffix=False):
|
||||
if not ":" in image:
|
||||
log.warn("using implicit latest, skip")
|
||||
return
|
||||
image_name, current_tag = image.split(":")
|
||||
if not image_name in TAG_STORE:
|
||||
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 = {}
|
||||
for tag in TAG_STORE[image_name]:
|
||||
log.debug("check("+str(tag)+")")
|
||||
if compare(current_tag, tag):
|
||||
if compare(current_tag, tag, match_suffix):
|
||||
log.debug("NEWER!!!")
|
||||
update = TAG_STORE[image_name][tag]
|
||||
new_tags[tag] = str(update)
|
||||
|
|
|
|||
|
|
@ -1,13 +1,15 @@
|
|||
import argparse
|
||||
import json
|
||||
import logging
|
||||
|
||||
import docker_compose
|
||||
import image_tags
|
||||
|
||||
log = logging
|
||||
|
||||
def find_updates(image_ref, usages):
|
||||
def find_updates(image_ref, usages, match_suffix=False):
|
||||
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:
|
||||
newer_tags = e.args
|
||||
return {
|
||||
|
|
@ -24,20 +26,21 @@ def main(args):
|
|||
image_ref = f"{image}:{tag}"
|
||||
if image_ref in updates:
|
||||
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]:
|
||||
if not "base_images" in usage:
|
||||
continue
|
||||
for base in usage["base_images"]:
|
||||
info = [{
|
||||
"is_base_image": True,
|
||||
"path": usage["path"],
|
||||
"service_name": usage["service_name"]
|
||||
}]
|
||||
if base in updates:
|
||||
continue
|
||||
updates[base]["usages"].append(info)
|
||||
else:
|
||||
info = {
|
||||
"is_base_image": True,
|
||||
"path": usage["path"],
|
||||
"service_name": usage["service_name"]
|
||||
}
|
||||
updates[base] = find_updates(base, info)
|
||||
log.info(f"find base image updates for {base}")
|
||||
updates[base] = find_updates(base, info, args.match_suffix)
|
||||
|
||||
if args.output:
|
||||
with open(args.output, "w") as out:
|
||||
|
|
|
|||
Loading…
Reference in New Issue