Skip to content

Commit 65b455f

Browse files
r10rRuben Jenster
authored and
Ruben Jenster
committed
Fix project name evaluation order
The COMPOSE_PROJECT_NAME environment variable must override the top-level name: attribute in the Compose file. The precedence order is defined in the docker compose documentation https://docs.docker.com/compose/how-tos/project-name/#set-a-project-name Signed-off-by: Ruben Jenster <[email protected]>
1 parent 1aa750b commit 65b455f

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Fixed project name evaluation order to match the order defined in the [compose spec](https://docs.docker.com/compose/how-tos/project-name/#set-a-project-name).

podman_compose.py

+13-8
Original file line numberDiff line numberDiff line change
@@ -1981,15 +1981,20 @@ def _parse_compose_file(self):
19811981
content = normalize(content)
19821982
# log(filename, json.dumps(content, indent = 2))
19831983

1984+
# See also https://docs.docker.com/compose/how-tos/project-name/#set-a-project-name
1985+
# **project_name** is initialized to the argument of the `-p` command line flag.
19841986
if not project_name:
1985-
project_name = content.get("name")
1986-
if project_name is None:
1987-
# More strict then actually needed for simplicity:
1988-
# podman requires [a-zA-Z0-9][a-zA-Z0-9_.-]*
1989-
project_name = self.environ.get("COMPOSE_PROJECT_NAME", dir_basename.lower())
1990-
project_name = norm_re.sub("", project_name)
1991-
if not project_name:
1992-
raise RuntimeError(f"Project name [{dir_basename}] normalized to empty")
1987+
project_name = self.environ.get("COMPOSE_PROJECT_NAME")
1988+
if not project_name:
1989+
project_name = content.get("name")
1990+
if not project_name:
1991+
project_name = dir_basename.lower()
1992+
# More strict then actually needed for simplicity:
1993+
# podman requires [a-zA-Z0-9][a-zA-Z0-9_.-]*
1994+
project_name_normalized = norm_re.sub("", project_name)
1995+
if not project_name_normalized:
1996+
raise RuntimeError(f"Project name [{project_name}] normalized to empty")
1997+
project_name = project_name_normalized
19931998

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

0 commit comments

Comments
 (0)