From cfc746081b1405b6a555c44ed7e03175119b537b Mon Sep 17 00:00:00 2001 From: Vitor Anjos Date: Sat, 27 Jun 2020 15:07:32 -0300 Subject: [PATCH 1/2] Ignore build context path validation when it is not necessary Signed-off-by: Vitor Anjos --- compose/config/config.py | 15 ++++++++++++++- tests/acceptance/cli_test.py | 14 ++++++++++++++ tests/fixtures/no-build/docker-compose.yml | 8 ++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 tests/fixtures/no-build/docker-compose.yml diff --git a/compose/config/config.py b/compose/config/config.py index 61fad199f60..eb7bfaeaccc 100644 --- a/compose/config/config.py +++ b/compose/config/config.py @@ -718,9 +718,22 @@ def validate_extended_service_dict(service_dict, filename, service): def validate_service(service_config, service_names, config_file): + def build_image(): + args = sys.argv[1:] + if 'pull' in args: + return False + + if '--no-build' in args: + return False + + return True + service_dict, service_name = service_config.config, service_config.name validate_service_constraints(service_dict, service_name, config_file) - validate_paths(service_dict) + + if build_image(): + # We only care about valid paths when actually building images + validate_paths(service_dict) validate_cpu(service_config) validate_ulimits(service_config) diff --git a/tests/acceptance/cli_test.py b/tests/acceptance/cli_test.py index c84d3f8cb99..4ef92dbe83c 100644 --- a/tests/acceptance/cli_test.py +++ b/tests/acceptance/cli_test.py @@ -747,6 +747,20 @@ def test_build_no_cache(self): assert BUILD_CACHE_TEXT not in result.stdout assert BUILD_PULL_TEXT not in result.stdout + def test_up_ignore_missing_build_directory(self): + self.base_dir = 'tests/fixtures/no-build' + result = self.dispatch(['up', '--no-build']) + + assert 'alpine exited with code 0' in result.stdout + self.base_dir = None + + def test_pull_ignore_missing_build_directory(self): + self.base_dir = 'tests/fixtures/no-build' + result = self.dispatch(['pull']) + + assert 'Pulling my-alpine' in result.stderr + self.base_dir = None + def test_build_pull(self): # Make sure we have the latest busybox already pull_busybox(self.client) diff --git a/tests/fixtures/no-build/docker-compose.yml b/tests/fixtures/no-build/docker-compose.yml new file mode 100644 index 00000000000..5de4d9b60e2 --- /dev/null +++ b/tests/fixtures/no-build/docker-compose.yml @@ -0,0 +1,8 @@ +version: "3" +services: + my-alpine: + image: alpine:3.12 + container_name: alpine + entrypoint: 'echo It works!' + build: + context: /this/path/doesnt/exists # and we don't really care. We just want to run containers already pulled. From d57a3b24b23fb2af8f24dadf16032422b3de42aa Mon Sep 17 00:00:00 2001 From: Vitor Anjos Date: Fri, 7 Aug 2020 09:33:45 -0300 Subject: [PATCH 2/2] Fix typo Signed-off-by: Vitor Anjos --- tests/fixtures/no-build/docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/fixtures/no-build/docker-compose.yml b/tests/fixtures/no-build/docker-compose.yml index 5de4d9b60e2..f320d17c394 100644 --- a/tests/fixtures/no-build/docker-compose.yml +++ b/tests/fixtures/no-build/docker-compose.yml @@ -5,4 +5,4 @@ services: container_name: alpine entrypoint: 'echo It works!' build: - context: /this/path/doesnt/exists # and we don't really care. We just want to run containers already pulled. + context: /this/path/doesnt/exist # and we don't really care. We just want to run containers already pulled.