Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove incorrect os.chdir, handle relative extends/includes #1124

Merged
merged 1 commit into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions newsfragments/1125.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Fix handling of relative includes and extends
12 changes: 8 additions & 4 deletions podman_compose.py
Original file line number Diff line number Diff line change
Expand Up @@ -1925,9 +1925,6 @@ def _parse_compose_file(self):
dotenv_path = os.path.realpath(args.env_file)
dotenv_dict.update(dotenv_to_dict(dotenv_path))

# TODO: remove next line
os.chdir(dirname)

os.environ.update({
key: value for key, value in dotenv_dict.items() if key.startswith("PODMAN_")
})
Expand Down Expand Up @@ -1969,11 +1966,18 @@ def _parse_compose_file(self):
content = normalize(content)
# log(filename, json.dumps(content, indent = 2))
content = rec_subs(content, self.environ)
if isinstance(services := content.get('services'), dict):
for service in services.values():
if 'extends' in service and (service_file := service['extends'].get('file')):
service['extends']['file'] = os.path.join(
os.path.dirname(filename), service_file
)

rec_merge(compose, content)
# If `include` is used, append included files to files
include = compose.get("include")
if include:
files.extend(include)
files.extend([os.path.join(os.path.dirname(filename), i) for i in 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.
Expand Down