From 3813f7c6b1168af7282be65d5757239d161f92ad Mon Sep 17 00:00:00 2001 From: Robert Kaussow Date: Wed, 8 Jun 2022 15:32:30 +0200 Subject: [PATCH] feat: add option DOCKER_AUTOTAG_SUFFIX_STRICT (#139) --- README.md | 5 +++++ dockerautotag/cli.py | 10 +++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 05cf1a7..aa823be 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,8 @@ Simple tool to create a list of docker tags from a given version string. DOCKER_AUTOTAG_OUTPUT_FILE= # adds a given suffix to every determined tag DOCKER_AUTOTAG_SUFFIX= +# returns only tags with the applied suffix +DOCKER_AUTOTAG_SUFFIX_STRICT=False # version string to use; returns 'latest' if nothing is specified DOCKER_AUTOTAG_VERSION= # comma-seprated list of static tags to add to the result set @@ -59,6 +61,9 @@ DOCKER_AUTOTAG_IGNORE_PRERELEASE=True DOCKER_AUTOTAG_VERSION=1.0.0-beta docker-a DOCKER_AUTOTAG_SUFFIX=amd64 DOCKER_AUTOTAG_VERSION=1.0.0 docker-autotag # 1.0.0,1.0,1,1.0.0-amd64,1.0-amd64,1-amd64 +DOCKER_AUTOTAG_SUFFIX=amd64 DOCKER_AUTOTAG_SUFFIX_STRICT=True DOCKER_AUTOTAG_VERSION=1.0.0 docker-autotag +# 1.0.0-amd64,1.0-amd64,1-amd64 + DOCKER_AUTOTAG_EXTRA_TAGS=extra1,extra2 DOCKER_AUTOTAG_VERSION=1.0.0 docker-autotag # 1.0.0,1.0,1,extra1,extra2 ``` diff --git a/dockerautotag/cli.py b/dockerautotag/cli.py index 1b59d45..36d39c7 100644 --- a/dockerautotag/cli.py +++ b/dockerautotag/cli.py @@ -42,6 +42,7 @@ class Autotag: config["file"] = normalize_path(output_raw) config["suffix"] = os.environ.get("DOCKER_AUTOTAG_SUFFIX", None) + config["suffix_strict"] = to_bool(os.environ.get("DOCKER_AUTOTAG_SUFFIX_STRICT", False)) config["version"] = os.environ.get("DOCKER_AUTOTAG_VERSION", None) config["extra"] = os.environ.get("DOCKER_AUTOTAG_EXTRA_TAGS", None) config["force_latest"] = to_bool(os.environ.get("DOCKER_AUTOTAG_FORCE_LATEST", False)) @@ -58,11 +59,14 @@ class Autotag: return tags + e @staticmethod - def _tag_suffix(tags, suffix): + def _tag_suffix(tags, suffix, suffix_strict): if not suffix: return tags - res = copy.deepcopy(tags) + res = [] + if not suffix_strict: + res = copy.deepcopy(tags) + for t in tags: if t == "latest": res.append(suffix) @@ -116,7 +120,7 @@ class Autotag: config = self.config v = self._default_tags(config["version"], config["ignore_pre"], config["force_latest"]) - v = self._tag_suffix(v, config["suffix"]) + v = self._tag_suffix(v, config["suffix"], config["suffix_strict"]) v = self._tag_extra(v, config["extra"]) if config["file"]: