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

Fix COMPOSE_PROJECT_NAME variable parsing order regression #805

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
33 changes: 16 additions & 17 deletions podman_compose.py
Original file line number Diff line number Diff line change
Expand Up @@ -1611,6 +1611,22 @@ def _parse_compose_file(self):
sys.exit(1)
content = normalize(content)
# log(filename, json.dumps(content, indent = 2))

if not project_name:
project_name = rec_subs(content.get("name", None), self.environ)
if project_name is None:
# More strict then actually needed for simplicity: podman requires [a-zA-Z0-9][a-zA-Z0-9_.-]*
project_name = (
os.environ.get("COMPOSE_PROJECT_NAME", None) or dir_basename.lower()
)
project_name = norm_re.sub("", project_name)
if not project_name:
raise RuntimeError(
f"Project name [{dir_basename}] normalized to empty"
)
self.project_name = project_name
self.environ.update({"COMPOSE_PROJECT_NAME": self.project_name})

content = rec_subs(content, self.environ)
rec_merge(compose, content)
# If `include` is used, append included files to files
Expand Down Expand Up @@ -1638,23 +1654,6 @@ def _parse_compose_file(self):
log(" ** merged:\n", json.dumps(compose, indent=2))
# ver = compose.get('version', None)

if not project_name:
project_name = compose.get("name", None)
if project_name is None:
# More strict then actually needed for simplicity: podman requires [a-zA-Z0-9][a-zA-Z0-9_.-]*
project_name = (
self.environ.get("COMPOSE_PROJECT_NAME", None)
or dir_basename.lower()
)
project_name = norm_re.sub("", project_name)
if not project_name:
raise RuntimeError(
f"Project name [{dir_basename}] normalized to empty"
)

self.project_name = project_name
self.environ.update({"COMPOSE_PROJECT_NAME": self.project_name})

services = compose.get("services", None)
if services is None:
services = {}
Expand Down