Skip to content

Commit d1ba2f4

Browse files
authored
Merge pull request containers#1124 from notdian/file_not_found_error
remove incorrect os.chdir, handle relative extends/includes
2 parents 51d180d + e03d675 commit d1ba2f4

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

newsfragments/1125.bugfix

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Fix handling of relative includes and extends

podman_compose.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -1925,9 +1925,6 @@ def _parse_compose_file(self):
19251925
dotenv_path = os.path.realpath(args.env_file)
19261926
dotenv_dict.update(dotenv_to_dict(dotenv_path))
19271927

1928-
# TODO: remove next line
1929-
os.chdir(dirname)
1930-
19311928
os.environ.update({
19321929
key: value for key, value in dotenv_dict.items() if key.startswith("PODMAN_")
19331930
})
@@ -1969,11 +1966,18 @@ def _parse_compose_file(self):
19691966
content = normalize(content)
19701967
# log(filename, json.dumps(content, indent = 2))
19711968
content = rec_subs(content, self.environ)
1969+
if isinstance(services := content.get('services'), dict):
1970+
for service in services.values():
1971+
if 'extends' in service and (service_file := service['extends'].get('file')):
1972+
service['extends']['file'] = os.path.join(
1973+
os.path.dirname(filename), service_file
1974+
)
1975+
19721976
rec_merge(compose, content)
19731977
# If `include` is used, append included files to files
19741978
include = compose.get("include")
19751979
if include:
1976-
files.extend(include)
1980+
files.extend([os.path.join(os.path.dirname(filename), i) for i in include])
19771981
# As compose obj is updated and tested with every loop, not deleting `include`
19781982
# from it, results in it being tested again and again, original values for
19791983
# `include` be appended to `files`, and, included files be processed for ever.

0 commit comments

Comments
 (0)