Merge pull request #6134 from docker/4841-fix-project-dir

Fix --project-directory handling to apply to .env files as well
This commit is contained in:
Joffrey F 2018-08-13 16:03:47 -07:00 committed by GitHub
commit 901ee4e77b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 42 additions and 3 deletions

View File

@ -238,11 +238,14 @@ class TopLevelCommand(object):
version Show the Docker-Compose version information
"""
def __init__(self, project, project_dir='.', options=None):
def __init__(self, project, options=None):
self.project = project
self.project_dir = '.'
self.toplevel_options = options or {}
@property
def project_dir(self):
return self.toplevel_options.get('--project-directory') or '.'
def build(self, options):
"""
Build or rebuild services.

View File

@ -303,6 +303,36 @@ class CLITestCase(DockerClientTestCase):
}
}
def test_config_with_dot_env(self):
self.base_dir = 'tests/fixtures/default-env-file'
result = self.dispatch(['config'])
json_result = yaml.load(result.stdout)
assert json_result == {
'services': {
'web': {
'command': 'true',
'image': 'alpine:latest',
'ports': ['5643/tcp', '9999/tcp']
}
},
'version': '2.4'
}
def test_config_with_dot_env_and_override_dir(self):
self.base_dir = 'tests/fixtures/default-env-file'
result = self.dispatch(['--project-directory', 'alt/', 'config'])
json_result = yaml.load(result.stdout)
assert json_result == {
'services': {
'web': {
'command': 'echo uwu',
'image': 'alpine:3.4',
'ports': ['3341/tcp', '4449/tcp']
}
},
'version': '2.4'
}
def test_config_external_volume_v2(self):
self.base_dir = 'tests/fixtures/volumes'
result = self.dispatch(['-f', 'external-volumes-v2.yml', 'config'])

View File

@ -0,0 +1,4 @@
IMAGE=alpine:3.4
COMMAND=echo uwu
PORT1=3341
PORT2=4449

View File

@ -1,4 +1,6 @@
web:
version: '2.4'
services:
web:
image: ${IMAGE}
command: ${COMMAND}
ports: