mirror of
https://github.com/containers/podman-compose.git
synced 2025-03-28 08:37:22 +01:00
Implement include
from compose-spec
Signed-off-by: Mahmoud Abduljawad <mahmoud@masaar.com>
This commit is contained in:
parent
3890eacf57
commit
bf07e91163
@ -1559,7 +1559,15 @@ class PodmanCompose:
|
||||
}
|
||||
)
|
||||
compose = {}
|
||||
for filename in files:
|
||||
# Iterate over files primitively to allow appending to files in-loop
|
||||
files_iter = iter(files)
|
||||
|
||||
while True:
|
||||
try:
|
||||
filename = next(files_iter)
|
||||
except StopIteration:
|
||||
break
|
||||
|
||||
with open(filename, "r", encoding="utf-8") as f:
|
||||
content = yaml.safe_load(f)
|
||||
# log(filename, json.dumps(content, indent = 2))
|
||||
@ -1573,6 +1581,15 @@ class PodmanCompose:
|
||||
# log(filename, json.dumps(content, indent = 2))
|
||||
content = rec_subs(content, self.environ)
|
||||
rec_merge(compose, content)
|
||||
# If `include` is used, append included files to files
|
||||
if include := compose.get("include", None):
|
||||
files.append(*include)
|
||||
# As compose obj is updated and tested with every loop, not deleting `include`
|
||||
# from it, results in it being tested again and again, original values for
|
||||
# `include` be appended to `files`, and, included files be processed for ever.
|
||||
# Solution is to remove 'include' key from compose obj. This doesn't break
|
||||
# having `include` present and correctly processed in included files
|
||||
del compose["include"]
|
||||
resolved_services = self._resolve_profiles(
|
||||
compose.get("services", {}), set(args.profile)
|
||||
)
|
||||
|
7
tests/include/docker-compose.base.yaml
Normal file
7
tests/include/docker-compose.base.yaml
Normal file
@ -0,0 +1,7 @@
|
||||
version: '3.6'
|
||||
|
||||
services:
|
||||
web:
|
||||
image: busybox
|
||||
command: ["/bin/busybox", "httpd", "-f", "-h", ".", "-p", "8003"]
|
||||
|
4
tests/include/docker-compose.yaml
Normal file
4
tests/include/docker-compose.yaml
Normal file
@ -0,0 +1,4 @@
|
||||
version: '3.6'
|
||||
|
||||
include:
|
||||
- docker-compose.base.yaml
|
71
tests/test_podman_compose_include.py
Normal file
71
tests/test_podman_compose_include.py
Normal file
@ -0,0 +1,71 @@
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
|
||||
|
||||
def capture(command):
|
||||
proc = subprocess.Popen(
|
||||
command,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
)
|
||||
out, err = proc.communicate()
|
||||
return out, err, proc.returncode
|
||||
|
||||
|
||||
def test_podman_compose_include():
|
||||
"""
|
||||
Test that podman-compose can execute podman-compose -f <file> up with include
|
||||
:return:
|
||||
"""
|
||||
main_path = Path(__file__).parent.parent
|
||||
|
||||
command_up = [
|
||||
"python3",
|
||||
str(main_path.joinpath("podman_compose.py")),
|
||||
"-f",
|
||||
str(main_path.joinpath("tests", "include", "docker-compose.yaml")),
|
||||
"up",
|
||||
"-d",
|
||||
]
|
||||
|
||||
command_check_container = [
|
||||
"podman",
|
||||
"ps",
|
||||
"-a",
|
||||
"--filter",
|
||||
"label=io.podman.compose.project=include",
|
||||
"--format",
|
||||
'"{{.Image}}"',
|
||||
]
|
||||
|
||||
command_container_id = [
|
||||
"podman",
|
||||
"ps",
|
||||
"-a",
|
||||
"--filter",
|
||||
"label=io.podman.compose.project=include",
|
||||
"--format",
|
||||
'"{{.ID}}"',
|
||||
]
|
||||
|
||||
command_down = ["podman", "rm", "--force", "CONTAINER_ID"]
|
||||
|
||||
out, _, returncode = capture(command_up)
|
||||
assert 0 == returncode
|
||||
out, _, returncode = capture(command_check_container)
|
||||
assert 0 == returncode
|
||||
assert out == b'"docker.io/library/busybox:latest"\n'
|
||||
# Get container ID to remove it
|
||||
out, _, returncode = capture(command_container_id)
|
||||
assert 0 == returncode
|
||||
assert out != b""
|
||||
container_id = out.decode().strip().replace('"', "")
|
||||
command_down[3] = container_id
|
||||
out, _, returncode = capture(command_down)
|
||||
# cleanup test image(tags)
|
||||
assert 0 == returncode
|
||||
assert out != b""
|
||||
# check container did not exists anymore
|
||||
out, _, returncode = capture(command_check_container)
|
||||
assert 0 == returncode
|
||||
assert out == b""
|
Loading…
Reference in New Issue
Block a user