Browse Source

Merge pull request #9504 from docker/nicksieger/9427

fix: bring up services with deps with --no-deps
Guillaume Lours 3 years ago
parent
commit
335decceda
3 changed files with 20 additions and 1 deletions
  1. 5 1
      pkg/compose/create.go
  2. 8 0
      pkg/e2e/fixtures/links/compose.yaml
  3. 7 0
      pkg/e2e/start_stop_test.go

+ 5 - 1
pkg/compose/create.go

@@ -183,7 +183,11 @@ func prepareServicesDependsOn(p *types.Project) error {
 		if service.DependsOn == nil {
 			service.DependsOn = make(types.DependsOnConfig)
 		}
-		deps, err := p.GetServices(dependencies...)
+
+		// Verify dependencies exist in the project, whether disabled or not
+		projAllServices := types.Project{}
+		projAllServices.Services = p.AllServices()
+		deps, err := projAllServices.GetServices(dependencies...)
 		if err != nil {
 			return err
 		}

+ 8 - 0
pkg/e2e/fixtures/links/compose.yaml

@@ -0,0 +1,8 @@
+services:
+  foo:
+    image: nginx:alpine
+    links:
+      - bar
+
+  bar:
+    image: nginx:alpine

+ 7 - 0
pkg/e2e/start_stop_test.go

@@ -131,6 +131,13 @@ func TestStartStopWithDependencies(t *testing.T) {
 		assert.Assert(t, strings.Contains(res.Combined(), "e2e-start-stop-with-dependencies-foo-1"), res.Combined())
 	})
 
+	t.Run("Up no-deps links", func(t *testing.T) {
+		_ = c.RunDockerComposeCmd("--project-name", projectName, "down")
+		res := c.RunDockerComposeCmd("-f", "./fixtures/links/compose.yaml", "--project-name", projectName, "up", "--no-deps", "-d", "foo")
+		assert.Assert(t, strings.Contains(res.Combined(), "Container e2e-start-stop-with-dependencies-foo-1  Started"), res.Combined())
+		assert.Assert(t, !strings.Contains(res.Combined(), "Container e2e-start-stop-with-dependencies-bar-1  Started"), res.Combined())
+	})
+
 	t.Run("down", func(t *testing.T) {
 		_ = c.RunDockerComposeCmd("--project-name", projectName, "down")
 	})