Alt Dockerfile names fix

Signed-off-by: Michaël Nass - PlugN <michael.nass@free.fr>
This commit is contained in:
Michaël Nass - PlugN 2024-06-26 15:24:58 +02:00
parent 0bcf0799b6
commit fa3e0a7772
3 changed files with 6 additions and 14 deletions

1
newsfragments/978.bugfix Normal file
View File

@ -0,0 +1 @@
Fixed support for de-facto alternative `Dockerfile` names (e.g. `Containerfile`)

View File

@ -1527,12 +1527,8 @@ def normalize_service_final(service: dict, project_dir: str) -> dict:
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", ".")
context = os.path.normpath(os.path.join(project_dir, context)) context = os.path.normpath(os.path.join(project_dir, context))
dockerfile = (
"Dockerfile" if is_str(build) else service["build"].get("dockerfile", "Dockerfile")
)
if not is_dict(service["build"]): if not is_dict(service["build"]):
service["build"] = {} service["build"] = {}
service["build"]["dockerfile"] = dockerfile
service["build"]["context"] = context service["build"]["context"] = context
return service return service

View File

@ -22,7 +22,7 @@ class TestNormalizeFinalBuild(unittest.TestCase):
( (
{"build": "."}, {"build": "."},
{ {
"build": {"context": cwd, "dockerfile": "Dockerfile"}, "build": {"context": cwd},
}, },
), ),
( (
@ -30,7 +30,6 @@ class TestNormalizeFinalBuild(unittest.TestCase):
{ {
"build": { "build": {
"context": os.path.normpath(os.path.join(cwd, "../relative")), "context": os.path.normpath(os.path.join(cwd, "../relative")),
"dockerfile": "Dockerfile",
}, },
}, },
), ),
@ -39,7 +38,6 @@ class TestNormalizeFinalBuild(unittest.TestCase):
{ {
"build": { "build": {
"context": os.path.normpath(os.path.join(cwd, "./relative")), "context": os.path.normpath(os.path.join(cwd, "./relative")),
"dockerfile": "Dockerfile",
}, },
}, },
), ),
@ -48,7 +46,6 @@ class TestNormalizeFinalBuild(unittest.TestCase):
{ {
"build": { "build": {
"context": "/workspace/absolute", "context": "/workspace/absolute",
"dockerfile": "Dockerfile",
}, },
}, },
), ),
@ -74,7 +71,6 @@ class TestNormalizeFinalBuild(unittest.TestCase):
{ {
"build": { "build": {
"context": cwd, "context": cwd,
"dockerfile": "Dockerfile",
}, },
}, },
), ),
@ -135,12 +131,12 @@ class TestNormalizeFinalBuild(unittest.TestCase):
( (
{}, {},
{"build": "."}, {"build": "."},
{"build": {"context": cwd, "dockerfile": "Dockerfile"}}, {"build": {"context": cwd}},
), ),
( (
{"build": "."}, {"build": "."},
{}, {},
{"build": {"context": cwd, "dockerfile": "Dockerfile"}}, {"build": {"context": cwd}},
), ),
( (
{"build": "/workspace/absolute"}, {"build": "/workspace/absolute"},
@ -148,19 +144,18 @@ class TestNormalizeFinalBuild(unittest.TestCase):
{ {
"build": { "build": {
"context": os.path.normpath(os.path.join(cwd, "./relative")), "context": os.path.normpath(os.path.join(cwd, "./relative")),
"dockerfile": "Dockerfile",
} }
}, },
), ),
( (
{"build": "./relative"}, {"build": "./relative"},
{"build": "/workspace/absolute"}, {"build": "/workspace/absolute"},
{"build": {"context": "/workspace/absolute", "dockerfile": "Dockerfile"}}, {"build": {"context": "/workspace/absolute"}},
), ),
( (
{"build": "./relative"}, {"build": "./relative"},
{"build": "/workspace/absolute"}, {"build": "/workspace/absolute"},
{"build": {"context": "/workspace/absolute", "dockerfile": "Dockerfile"}}, {"build": {"context": "/workspace/absolute"}},
), ),
( (
{"build": {"dockerfile": "test-dockerfile"}}, {"build": {"dockerfile": "test-dockerfile"}},