summaryrefslogtreecommitdiff
path: root/compose/config
diff options
context:
space:
mode:
authorAnca Iordache <anca.iordache@docker.com>2021-03-12 11:47:26 +0100
committerNicolas De loof <nicolas.deloof@gmail.com>2021-03-16 18:04:51 +0100
commit4a26d95de466560811806790bba93cbf739883af (patch)
tree31791912e83d1d19325f578bd659c0620f78aa69 /compose/config
parent5b7851f55b4ae9533f42eed282ffad7c442778f5 (diff)
Make `--env-file` paths relative to current working directory
Look up compose files in project dir as fallback to no compose file in current working directory Update config and env-file tests - get_default_config does not raise error anymore, returns None if no compose file is found Signed-off-by: Anca Iordache <anca.iordache@docker.com>
Diffstat (limited to 'compose/config')
-rw-r--r--compose/config/config.py14
-rw-r--r--compose/config/environment.py7
2 files changed, 15 insertions, 6 deletions
diff --git a/compose/config/config.py b/compose/config/config.py
index 39c815a9..cd708bae 100644
--- a/compose/config/config.py
+++ b/compose/config/config.py
@@ -304,7 +304,16 @@ def find(base_dir, filenames, environment, override_dir=None):
if filenames:
filenames = [os.path.join(base_dir, f) for f in filenames]
else:
+ # search for compose files in the base dir and its parents
filenames = get_default_config_files(base_dir)
+ if not filenames and not override_dir:
+ # none found in base_dir and no override_dir defined
+ raise ComposeFileNotFound(SUPPORTED_FILENAMES)
+ if not filenames:
+ # search for compose files in the project directory and its parents
+ filenames = get_default_config_files(override_dir)
+ if not filenames:
+ raise ComposeFileNotFound(SUPPORTED_FILENAMES)
log.debug("Using configuration files: {}".format(",".join(filenames)))
return ConfigDetails(
@@ -335,7 +344,7 @@ def get_default_config_files(base_dir):
(candidates, path) = find_candidates_in_parent_dirs(SUPPORTED_FILENAMES, base_dir)
if not candidates:
- raise ComposeFileNotFound(SUPPORTED_FILENAMES)
+ return None
winner = candidates[0]
@@ -556,8 +565,7 @@ def process_config_section(config_file, config, section, environment, interpolat
config_file.version,
config,
section,
- environment
- )
+ environment)
else:
return config
diff --git a/compose/config/environment.py b/compose/config/environment.py
index 8769df9f..5045a730 100644
--- a/compose/config/environment.py
+++ b/compose/config/environment.py
@@ -54,9 +54,10 @@ class Environment(dict):
if base_dir is None:
return result
if env_file:
- env_file_path = os.path.join(base_dir, env_file)
- else:
- env_file_path = os.path.join(base_dir, '.env')
+ env_file_path = os.path.join(os.getcwd(), env_file)
+ return cls(env_vars_from_file(env_file_path))
+
+ env_file_path = os.path.join(base_dir, '.env')
try:
return cls(env_vars_from_file(env_file_path))
except EnvFileNotFound: