Fix dockerfile definition if directory name ends with ".git"

After changes in 92f0a8583a, the
dockerfile parameter is igored if the (local) work directory's name ends
in `.git`.
This commit fixes the regression and adds more tests.

Signed-off-by: Monika Kairaityte <monika@kibit.lt>
This commit is contained in:
Monika Kairaityte
2025-06-16 12:05:33 +03:00
parent 1113c833da
commit dd471c8918
5 changed files with 161 additions and 24 deletions

View File

@@ -1799,7 +1799,7 @@ def normalize_service_final(service: dict[str, Any], project_dir: str) -> dict[s
build = service["build"]
context = build if isinstance(build, str) else build.get("context", ".")
if not is_path_git_url(context):
if not is_context_git_url(context):
context = os.path.normpath(os.path.join(project_dir, context))
if not isinstance(service["build"], dict):
service["build"] = {}
@@ -2788,9 +2788,18 @@ async def compose_push(compose: PodmanCompose, args: argparse.Namespace) -> None
await compose.podman.run([], "push", [cnt["image"]])
def is_path_git_url(path: str) -> bool:
def is_context_git_url(path: str) -> bool:
r = urllib.parse.urlparse(path)
return r.scheme == 'git' or r.path.endswith('.git')
if r.scheme in ('git', 'http', 'https', 'ssh', 'file', 'rsync'):
return True
# URL contains a ":" character, a hint of a valid URL
if r.scheme != "" and r.netloc == "" and r.path != "":
return True
if r.scheme == "": # tweak path URL to get username from url parser
r = urllib.parse.urlparse("ssh://" + path)
if r.username is not None and r.username != "":
return True
return False
def adjust_build_ssh_key_paths(compose: PodmanCompose, agent_or_key: str) -> str:
@@ -2834,8 +2843,8 @@ def container_to_build_args(
cleanup_callbacks.append(cleanup_temp_dockfile)
build_args = []
if not is_path_git_url(ctx):
# if givent context was not recognized as git url, try joining paths to get a file locally
if not is_context_git_url(ctx):
custom_dockerfile_given = False
if dockerfile:
dockerfile = os.path.join(ctx, dockerfile)