From cef99ba62a7589c5b80239a33f50763c643876b3 Mon Sep 17 00:00:00 2001 From: Clemens Klug Date: Mon, 6 Aug 2018 12:51:17 +0200 Subject: [PATCH] search updates for base images --- docker_compose.py | 2 +- show_updateable.py | 31 +++++++++++++++++++++++-------- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/docker_compose.py b/docker_compose.py index 64f8f8e..44d1a46 100644 --- a/docker_compose.py +++ b/docker_compose.py @@ -41,7 +41,7 @@ def parse_dockerfile(build): return [f] keyword = "FROM" with open(path, "r") as src: - sources = [source_to_image(line) for line in src if line.strip().startswith(keyword)] + sources = [source_to_image(line) for line in src if line.strip().startswith(keyword)] # TODO lower/upper return sources def image_info(image): diff --git a/show_updateable.py b/show_updateable.py index 5c6becb..81f8326 100644 --- a/show_updateable.py +++ b/show_updateable.py @@ -5,6 +5,16 @@ import docker_compose import image_tags +def find_updates(image_ref): + try: + newer_tags = image_tags.get_new_tags(image_ref) + except ValueError as e: + newer_tags = e.args + return { + "updates": newer_tags, + "usages": images[image][tag], + } + def main(args): @@ -13,14 +23,19 @@ def main(args): for image in images: for tag in images[image]: image_ref = f"{image}:{tag}" - try: - newer_tags = image_tags.get_new_tags(image_ref) - except ValueError as e: - newer_tags = e.args - updates[image_ref] = { - "updates": newer_tags, - "usages": images[image][tag] - } + if image_ref in updates: + continue + updates[image_ref] = find_updates(image_ref) + for usage in images[image][tag: + if "base_image" in usage: + continue + for base in usage["base_image"]: + if base in updates: + continue + else: + updates[base] = find_updates(base) + + if args.output: with open(args.output, "w") as out: json.dump(updates, out, indent=1, sort_keys=True)