Fixed git URL access in build context (#127)

Signed-off-by: RadioLogic <ncottrellweb@gmail.com>
This commit is contained in:
RadioLogic
2023-08-10 21:48:35 -04:00
parent bce40c2db3
commit 73e79a6f73

View File

@@ -1301,6 +1301,7 @@ def normalize_service_final(service: dict, project_dir: str) -> dict:
if "build" in service: if "build" in service:
build = service["build"] build = service["build"]
context = build if is_str(build) else build.get("context", ".") context = build if is_str(build) else build.get("context", ".")
if not re.match(r"://", context) and not re.match(r"[^:]+:.+", context):
context = os.path.normpath(os.path.join(project_dir, context)) context = os.path.normpath(os.path.join(project_dir, context))
dockerfile = ( dockerfile = (
"Dockerfile" "Dockerfile"
@@ -2103,10 +2104,8 @@ def build_one(compose, args, cnt):
if not hasattr(build_desc, "items"): if not hasattr(build_desc, "items"):
build_desc = {"context": build_desc} build_desc = {"context": build_desc}
ctx = build_desc.get("context", ".") ctx = build_desc.get("context", ".")
dockerfile = build_desc.get("dockerfile", None) dockerfile = build_desc.get("dockerfile", "")
if dockerfile: if not dockerfile:
dockerfile = os.path.join(ctx, dockerfile)
else:
dockerfile_alts = [ dockerfile_alts = [
"Containerfile", "Containerfile",
"ContainerFile", "ContainerFile",
@@ -2115,13 +2114,15 @@ def build_one(compose, args, cnt):
"DockerFile", "DockerFile",
"dockerfile", "dockerfile",
] ]
for dockerfile in dockerfile_alts: for dockerfile_alt in dockerfile_alts:
dockerfile = os.path.join(ctx, dockerfile) if os.path.exists(dockerfile_alt):
if os.path.exists(dockerfile): dockerfile = dockerfile_alt
break break
if not os.path.exists(dockerfile): if os.path.exists(os.path.join(ctx, dockerfile)):
raise OSError("Dockerfile not found in " + ctx) dockerfile = os.path.normpath(os.path.join(ctx, dockerfile))
build_args = ["-f", dockerfile, "-t", cnt["image"]] 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", []): for secret in build_desc.get("secrets", []):
build_args.extend(get_secret_args(compose, cnt, secret)) build_args.extend(get_secret_args(compose, cnt, secret))
for tag in build_desc.get("tags", []): for tag in build_desc.get("tags", []):