From a9e070206ef881b463850fd2cb38f7b84e152280 Mon Sep 17 00:00:00 2001 From: Guillaume Lours <705411+glours@users.noreply.github.com> Date: Wed, 9 Nov 2022 19:51:11 +0100 Subject: [PATCH 1/2] check if a missing image won't be build via a service declared in depends_on section Signed-off-by: Guillaume Lours <705411+glours@users.noreply.github.com> --- pkg/compose/pull.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/pkg/compose/pull.go b/pkg/compose/pull.go index 88cfefbf6..d3b794c6e 100644 --- a/pkg/compose/pull.go +++ b/pkg/compose/pull.go @@ -271,7 +271,7 @@ func (s *composeService) pullRequiredImages(ctx context.Context, project *types. eg.Go(func() error { id, err := s.pullServiceImage(ctx, service, info, s.configFile(), w, quietPull) pulledImages[i] = id - if err != nil && service.Build != nil { + if err != nil && isServiceImageToBuild(service, project.Services) { // image can be built, so we can ignore pull failure return nil } @@ -291,6 +291,19 @@ func (s *composeService) pullRequiredImages(ctx context.Context, project *types. }) } +func isServiceImageToBuild(service types.ServiceConfig, services []types.ServiceConfig) bool { + if service.Build != nil { + return true + } + + for _, depService := range services { + if depService.Image == service.Image && depService.Build != nil { + return true + } + } + return false +} + func toPullProgressEvent(parent string, jm jsonmessage.JSONMessage, w progress.Writer) { if jm.ID == "" || jm.Progress == nil { return From 8c1e2af3e1ffc6f6466662725e0eb12ce0391284 Mon Sep 17 00:00:00 2001 From: Guillaume Lours <705411+glours@users.noreply.github.com> Date: Thu, 10 Nov 2022 10:56:07 +0100 Subject: [PATCH 2/2] add e2e tests to check build dependency between services Signed-off-by: Guillaume Lours <705411+glours@users.noreply.github.com> --- pkg/e2e/fixtures/dependencies/Dockerfile | 16 ++++++++++++++++ .../service-image-depends-on.yaml | 9 +++++++++ pkg/e2e/up_test.go | 19 +++++++++++++++++++ 3 files changed, 44 insertions(+) create mode 100644 pkg/e2e/fixtures/dependencies/Dockerfile create mode 100644 pkg/e2e/fixtures/dependencies/service-image-depends-on.yaml diff --git a/pkg/e2e/fixtures/dependencies/Dockerfile b/pkg/e2e/fixtures/dependencies/Dockerfile new file mode 100644 index 000000000..fe5992a8d --- /dev/null +++ b/pkg/e2e/fixtures/dependencies/Dockerfile @@ -0,0 +1,16 @@ +# Copyright 2020 Docker Compose CLI authors + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +FROM busybox:1.35.0 +RUN echo "hello" \ No newline at end of file diff --git a/pkg/e2e/fixtures/dependencies/service-image-depends-on.yaml b/pkg/e2e/fixtures/dependencies/service-image-depends-on.yaml new file mode 100644 index 000000000..313997836 --- /dev/null +++ b/pkg/e2e/fixtures/dependencies/service-image-depends-on.yaml @@ -0,0 +1,9 @@ +services: + foo: + image: built-image-dependency + build: + context: . + bar: + image: built-image-dependency + depends_on: + - foo diff --git a/pkg/e2e/up_test.go b/pkg/e2e/up_test.go index c86599c01..ecb4595b1 100644 --- a/pkg/e2e/up_test.go +++ b/pkg/e2e/up_test.go @@ -104,3 +104,22 @@ func TestUpDependenciesNotStopped(t *testing.T) { RequireServiceState(t, c, "dependency", "running") RequireServiceState(t, c, "orphan", "running") } + +func TestUpWithBuildDependencies(t *testing.T) { + c := NewParallelCLI(t) + + t.Run("up with service using image build by an another service", func(t *testing.T) { + // ensure local test run does not reuse previously build image + c.RunDockerOrExitError(t, "rmi", "built-image-dependency") + + res := c.RunDockerComposeCmd(t, "--project-directory", "fixtures/dependencies", + "-f", "fixtures/dependencies/service-image-depends-on.yaml", "up", "-d") + + t.Cleanup(func() { + c.RunDockerComposeCmd(t, "--project-directory", "fixtures/dependencies", + "-f", "fixtures/dependencies/service-image-depends-on.yaml", "down", "--rmi", "all") + }) + + res.Assert(t, icmd.Success) + }) +}