diff --git a/podman_compose.py b/podman_compose.py index f01719d..d7f549c 100755 --- a/podman_compose.py +++ b/podman_compose.py @@ -1296,10 +1296,7 @@ def parse_build(build): if is_str(build): build_parsed["context"] = build elif is_dict(build): - if "context" in build: - build_parsed["context"] = build["context"] - if "dockerfile" in build: - build_parsed["dockerfile"] = build["dockerfile"] + build_parsed = build else: raise ValueError(f"invalid type of build value [{type(build)}]") return build_parsed @@ -1326,7 +1323,7 @@ def rec_merge_one(target, source): source_parsed = {} if key in source: source_parsed = parse_build(source[key]) - target["build"] = {**target_parsed, **source_parsed} + target["build"] = rec_merge_one(target_parsed, source_parsed) continue if key not in source: continue diff --git a/pytests/test_rec_merge_one_build.py b/pytests/test_rec_merge_one_build.py index 23efb40..3d25ec7 100644 --- a/pytests/test_rec_merge_one_build.py +++ b/pytests/test_rec_merge_one_build.py @@ -40,6 +40,21 @@ test_cases = [ {"build": {"dockerfile": "./compose-2.yaml", "context": "./dir-2"}}, {"build": {"dockerfile": "./compose-2.yaml", "context": "./dir-2"}}, ), + ( + {"build": {"dockerfile": "./compose-1.yaml"}}, + {"build": {"dockerfile": "./compose-2.yaml", "args": ["ENV1=1"]}}, + {"build": {"dockerfile": "./compose-2.yaml", "args": ["ENV1=1"]}}, + ), + ( + {"build": {"dockerfile": "./compose-2.yaml", "args": ["ENV1=1"]}}, + {"build": {"dockerfile": "./compose-1.yaml"}}, + {"build": {"dockerfile": "./compose-1.yaml", "args": ["ENV1=1"]}}, + ), + ( + {"build": {"dockerfile": "./compose-2.yaml", "args": ["ENV1=1"]}}, + {"build": {"dockerfile": "./compose-1.yaml", "args": ["ENV2=2"]}}, + {"build": {"dockerfile": "./compose-1.yaml", "args": ["ENV1=1", "ENV2=2"]}}, + ), ]