Browse Source

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

Fix --project-directory handling to apply to .env files as well
Joffrey F 7 năm trước cách đây
mục cha
commit
901ee4e77b

+ 5 - 2
compose/cli/main.py

@@ -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.

+ 30 - 0
tests/acceptance/cli_test.py

@@ -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'])

+ 4 - 0
tests/fixtures/default-env-file/alt/.env

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

+ 3 - 1
tests/fixtures/default-env-file/docker-compose.yml

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