mirror of
https://github.com/containers/podman-compose.git
synced 2025-04-09 17:41:03 +02:00
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 <r.jenster@drachenfels.de>
This commit is contained in:
parent
1aa750bacf
commit
65b455f081
1
newsfragments/1165-project-name-evaluation-order.bugfix
Normal file
1
newsfragments/1165-project-name-evaluation-order.bugfix
Normal file
@ -0,0 +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).
|
@ -1981,15 +1981,20 @@ class PodmanCompose:
|
|||||||
content = normalize(content)
|
content = normalize(content)
|
||||||
# log(filename, json.dumps(content, indent = 2))
|
# log(filename, json.dumps(content, indent = 2))
|
||||||
|
|
||||||
|
# See also https://docs.docker.com/compose/how-tos/project-name/#set-a-project-name
|
||||||
|
# **project_name** is initialized to the argument of the `-p` command line flag.
|
||||||
|
if not project_name:
|
||||||
|
project_name = self.environ.get("COMPOSE_PROJECT_NAME")
|
||||||
if not project_name:
|
if not project_name:
|
||||||
project_name = content.get("name")
|
project_name = content.get("name")
|
||||||
if project_name is None:
|
if not project_name:
|
||||||
|
project_name = dir_basename.lower()
|
||||||
# More strict then actually needed for simplicity:
|
# More strict then actually needed for simplicity:
|
||||||
# podman requires [a-zA-Z0-9][a-zA-Z0-9_.-]*
|
# podman requires [a-zA-Z0-9][a-zA-Z0-9_.-]*
|
||||||
project_name = self.environ.get("COMPOSE_PROJECT_NAME", dir_basename.lower())
|
project_name_normalized = norm_re.sub("", project_name)
|
||||||
project_name = norm_re.sub("", project_name)
|
if not project_name_normalized:
|
||||||
if not project_name:
|
raise RuntimeError(f"Project name [{project_name}] normalized to empty")
|
||||||
raise RuntimeError(f"Project name [{dir_basename}] normalized to empty")
|
project_name = project_name_normalized
|
||||||
|
|
||||||
self.project_name = project_name
|
self.project_name = project_name
|
||||||
self.environ.update({"COMPOSE_PROJECT_NAME": self.project_name})
|
self.environ.update({"COMPOSE_PROJECT_NAME": self.project_name})
|
||||||
|
Loading…
Reference in New Issue
Block a user