From 06164596d76aff6ed5b89902f7afd6fb1ef94be1 Mon Sep 17 00:00:00 2001 From: Magnus Walbeck Date: Sun, 21 Mar 2021 12:39:11 +0100 Subject: [PATCH] Check if app_name is empty when version_type is docker_env or docker_from. Add message when no options are provided. --- .gitignore | 1 + determine_docker_tags/__init__.py | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/.gitignore b/.gitignore index 0c69be5..be0728a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ +__pycache__ .pytest_cache dist diff --git a/determine_docker_tags/__init__.py b/determine_docker_tags/__init__.py index 6a1f2f9..1237beb 100644 --- a/determine_docker_tags/__init__.py +++ b/determine_docker_tags/__init__.py @@ -41,6 +41,13 @@ def write_tags_to_file(tags): file.write(tags) +def is_app_name_empty(app_name): + if not app_name or app_name.isspace(): + raise ValueError( + "APP_NAME is required when VERSION_TYPE is docker_env or docker_from" + ) + + def main(): version_type = os.getenv("VERSION_TYPE", "") # docker_env, docker_from or date app_name = os.getenv("APP_NAME", "") @@ -61,6 +68,8 @@ def main(): include_extra_info = "no" if version_type == "docker_env": + is_app_name_empty(app_name) + with open(dockerfile_path) as dockerfile: for line in dockerfile: if re.search(rf"ENV {app_name}_VERSION .*", line): @@ -75,6 +84,8 @@ def main(): ) elif version_type == "docker_from": + is_app_name_empty(app_name) + with open(dockerfile_path) as dockerfile: for line in dockerfile: if re.search(rf"FROM {app_name}:.*", line): @@ -97,6 +108,7 @@ def main(): custom_tags = "" else: + print("Please specify a VERSION_TYPE or set CUSTOM_TAGS.") exit(-1) if custom_tags: -- 2.45.2