Skip to content

Commit a9176bb

Browse files
committed
wip
1 parent 851aac1 commit a9176bb

File tree

3 files changed

+22
-13
lines changed

3 files changed

+22
-13
lines changed

podman_compose.py

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,10 @@ def strverscmp_lt(a, b):
131131
return a_ls < b_ls
132132

133133

134-
def parse_short_mount(mount_str, basedir):
134+
def parse_short_mount(compose, mount_str):
135+
# TODO: handle relative path according to spec. Will require some refactoring
136+
basedir = compose.dirname
137+
mount_str = rec_subs(mount_str, compose.environ)
135138
mount_a = mount_str.split(":")
136139
mount_opt_dict = {}
137140
mount_opt = None
@@ -199,6 +202,7 @@ def fix_mount_dict(compose, mount_dict, proj_name, srv_name):
199202
- define _vol to be the corresponding top-level volume
200203
- if name is missing it would be source prefixed with project
201204
- if no source it would be generated
205+
- substitute variables
202206
"""
203207
# if already applied nothing todo
204208
if "_vol" in mount_dict:
@@ -413,7 +417,7 @@ async def assert_volume(compose, mount_dict):
413417
raise RuntimeError(f"External volume [{vol_name}] does not exists") from e
414418
labels = vol.get("labels", None) or []
415419
if not is_list(labels) and not isinstance(labels, dict):
416-
raise ValueError("labels must be list or dict")
420+
raise ValueError("labels not list or dict on volume [{vol_name}]") from e
417421
args = [
418422
"create",
419423
"--label",
@@ -540,16 +544,14 @@ def mount_desc_to_volume_args(compose, mount_desc, srv_name='DEPRECATED', cnt_na
540544
def get_mnt_dict(compose, cnt, volume):
541545
proj_name = compose.project_name
542546
srv_name = cnt["_service"]
543-
basedir = compose.dirname
544547
if isinstance(volume, str):
545-
volume = parse_short_mount(volume, basedir)
548+
volume = parse_short_mount(compose, volume)
546549
return fix_mount_dict(compose, volume, proj_name, srv_name)
547550

548551

549552
async def get_mount_args(compose, cnt, volume):
550553
volume = get_mnt_dict(compose, cnt, volume)
551554
# proj_name = compose.project_name
552-
srv_name = cnt["_service"]
553555
mount_type = volume["type"]
554556
await assert_volume(compose, volume)
555557
if compose.prefer_volume_over_mount:
@@ -1396,7 +1398,7 @@ async def output(self, podman_args, cmd="", cmd_args=None):
13961398
returncode = p.returncode
13971399
if returncode == 0:
13981400
return stdout_data
1399-
if returncode == None:
1401+
if returncode is None:
14001402
returncode = -1
14011403

14021404
raise subprocess.CalledProcessError(returncode, " ".join(cmd_ls), stderr_data)
@@ -1903,8 +1905,14 @@ def translate_paths_service(content: dict, project_directory: str):
19031905
else content['env_file']
19041906
)
19051907
content['env_file'] = [
1906-
os.path.join(project_directory or '.', ef if isinstance(ef, str) else
1907-
ef['path']) for ef in env_file
1908+
{
1909+
'path': os.path.join(
1910+
project_directory or os.path.dirname(file['path']),
1911+
ef if isinstance(ef, str) else ef['path'],
1912+
),
1913+
'required': ef.get('required', True) if isinstance(ef, dict) else True,
1914+
}
1915+
for ef in env_file
19081916
]
19091917
return content
19101918

@@ -1917,9 +1925,10 @@ def translate_paths(content, project_directory):
19171925
content['services'] = services
19181926
return content
19191927

1920-
content = translate_paths(content, file['project_directory'])
1928+
content = translate_paths(
1929+
content, file['project_directory'] or os.path.dirname(file['path'])
1930+
)
19211931
# log(filename, json.dumps(content, indent = 2))
1922-
# TODO: this seems to miss environment files from other includes
19231932
content = rec_subs(content, self.environ)
19241933
rec_merge(compose, content)
19251934
# If `include` is used, append included files to files
@@ -2706,12 +2715,11 @@ def _task_cancelled(task: Task) -> bool:
27062715

27072716
def get_volume_names(compose, cnt):
27082717
proj_name = compose.project_name
2709-
basedir = compose.dirname
27102718
srv_name = cnt["_service"]
27112719
ls = []
27122720
for volume in cnt.get("volumes", []):
27132721
if isinstance(volume, str):
2714-
volume = parse_short_mount(volume, basedir)
2722+
volume = parse_short_mount(compose, volume)
27152723
volume = fix_mount_dict(compose, volume, proj_name, srv_name)
27162724
mount_type = volume["type"]
27172725
if mount_type != "volume":

tests/integration/include/docker-compose.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ include:
55
project_directory: .
66
- path: subdir/subdir-proj.docker-compose.yaml
77
project_directory: subdir
8+
- path: subdir/default-proj.docker-compose.yaml

tests/integration/test_podman_compose_include.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def test_podman_compose_include(self):
4848

4949
self.run_subprocess_assert_returncode(command_up)
5050
out, _ = self.run_subprocess_assert_returncode(command_check_container)
51-
expected_output = b'"localhost/nopush/podman-compose-test:latest"\n' * 4
51+
expected_output = b'"localhost/nopush/podman-compose-test:latest"\n' * 5
5252
self.assertEqual(out, expected_output)
5353
# Get container ID to remove it
5454
out, _ = self.run_subprocess_assert_returncode(command_container_id)

0 commit comments

Comments
 (0)