mirror of
https://github.com/containers/podman-compose.git
synced 2025-07-07 16:06:59 +02:00
Load .env from Compose file's directory and cwd
This commit loads dotenv `.env` (exactly that name) from the following location (the later takes precedence): - The `.env` file in the Compose file's directory. - The `.env` file in the current working directory (invoking podman-compose). This preserves the behavior prior to 1.1.0 and to match with Docker Compose CLI. Fix: https://github.com/containers/podman-compose/issues/937 Signed-off-by: Genzer <732937+Genzer@users.noreply.github.com>
This commit is contained in:
committed by
Povilas Kanapickas
parent
84f7fdd7da
commit
4e9f76768c
@ -1798,8 +1798,14 @@ class PodmanCompose:
|
||||
# env-file is relative to the CWD
|
||||
dotenv_dict = {}
|
||||
if args.env_file:
|
||||
# Load .env from the Compose file's directory to preserve
|
||||
# behavior prior to 1.1.0 and to match with Docker Compose (v2).
|
||||
if ".env" == args.env_file:
|
||||
project_dotenv_file = os.path.realpath(os.path.join(dirname, ".env"))
|
||||
if os.path.exists(project_dotenv_file):
|
||||
dotenv_dict.update(dotenv_to_dict(project_dotenv_file))
|
||||
dotenv_path = os.path.realpath(args.env_file)
|
||||
dotenv_dict = dotenv_to_dict(dotenv_path)
|
||||
dotenv_dict.update(dotenv_to_dict(dotenv_path))
|
||||
|
||||
# TODO: remove next line
|
||||
os.chdir(dirname)
|
||||
|
Reference in New Issue
Block a user