From 73e79a6f7304fb5c25305f89d978088503d7cd9a Mon Sep 17 00:00:00 2001 From: RadioLogic Date: Thu, 10 Aug 2023 21:48:35 -0400 Subject: [PATCH] Fixed git URL access in build context (#127) Signed-off-by: RadioLogic --- podman_compose.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/podman_compose.py b/podman_compose.py index 2001145..423e2a2 100755 --- a/podman_compose.py +++ b/podman_compose.py @@ -1301,7 +1301,8 @@ def normalize_service_final(service: dict, project_dir: str) -> dict: if "build" in service: build = service["build"] context = build if is_str(build) else build.get("context", ".") - context = os.path.normpath(os.path.join(project_dir, context)) + if not re.match(r"://", context) and not re.match(r"[^:]+:.+", context): + context = os.path.normpath(os.path.join(project_dir, context)) dockerfile = ( "Dockerfile" if is_str(build) @@ -2103,10 +2104,8 @@ def build_one(compose, args, cnt): if not hasattr(build_desc, "items"): build_desc = {"context": build_desc} ctx = build_desc.get("context", ".") - dockerfile = build_desc.get("dockerfile", None) - if dockerfile: - dockerfile = os.path.join(ctx, dockerfile) - else: + dockerfile = build_desc.get("dockerfile", "") + if not dockerfile: dockerfile_alts = [ "Containerfile", "ContainerFile", @@ -2115,13 +2114,15 @@ def build_one(compose, args, cnt): "DockerFile", "dockerfile", ] - for dockerfile in dockerfile_alts: - dockerfile = os.path.join(ctx, dockerfile) - if os.path.exists(dockerfile): + for dockerfile_alt in dockerfile_alts: + if os.path.exists(dockerfile_alt): + dockerfile = dockerfile_alt break - if not os.path.exists(dockerfile): - raise OSError("Dockerfile not found in " + ctx) - build_args = ["-f", dockerfile, "-t", cnt["image"]] + if os.path.exists(os.path.join(ctx, dockerfile)): + dockerfile = os.path.normpath(os.path.join(ctx, dockerfile)) + build_args = ["-t", cnt["image"]] + if os.path.exists(dockerfile) or re.match(r"://", ctx) or re.match(r"[^:]+:.+", ctx): + build_args.extend(["-f", dockerfile]) for secret in build_desc.get("secrets", []): build_args.extend(get_secret_args(compose, cnt, secret)) for tag in build_desc.get("tags", []):