From 3d66451a2bed7c814193db6114acdd4f09d8b17f Mon Sep 17 00:00:00 2001 From: Nicolas De Loof Date: Tue, 4 Mar 2025 15:49:59 +0100 Subject: [PATCH] reject compose file with bind mounts Signed-off-by: Nicolas De Loof --- pkg/compose/publish.go | 9 +++++++++ pkg/e2e/fixtures/publish/compose-bind-mount.yml | 5 +++++ pkg/e2e/publish_test.go | 6 ++++++ 3 files changed, 20 insertions(+) create mode 100644 pkg/e2e/fixtures/publish/compose-bind-mount.yml diff --git a/pkg/compose/publish.go b/pkg/compose/publish.go index 459a5f2f5e..8dcdcc0742 100644 --- a/pkg/compose/publish.go +++ b/pkg/compose/publish.go @@ -155,6 +155,15 @@ func (s *composeService) preChecks(project *types.Project, options api.PublishOp } return acceptPublishEnvVariables(s.dockerCli) } + + for name, config := range project.Services { + for _, volume := range config.Volumes { + if volume.Type == types.VolumeTypeBind { + return false, fmt.Errorf("cannot publish compose file: service %q relies on bind-mount. You should use volumes", name) + } + } + } + return true, nil } diff --git a/pkg/e2e/fixtures/publish/compose-bind-mount.yml b/pkg/e2e/fixtures/publish/compose-bind-mount.yml new file mode 100644 index 0000000000..ecfc700d1c --- /dev/null +++ b/pkg/e2e/fixtures/publish/compose-bind-mount.yml @@ -0,0 +1,5 @@ +services: + serviceA: + image: a + volumes: + - .:/user-data diff --git a/pkg/e2e/publish_test.go b/pkg/e2e/publish_test.go index 3a94153436..25007d7e15 100644 --- a/pkg/e2e/publish_test.go +++ b/pkg/e2e/publish_test.go @@ -108,6 +108,12 @@ FOO=bar`), res.Combined()) assert.Assert(t, strings.Contains(res.Combined(), `QUIX=`), res.Combined()) }) + t.Run("refuse to publish with bind mount", func(t *testing.T) { + res := c.RunDockerComposeCmdNoCheck(t, "-f", "./fixtures/publish/compose-bind-mount.yml", + "-p", projectName, "alpha", "publish", "test/test", "--dry-run") + res.Assert(t, icmd.Expected{ExitCode: 1, Err: `cannot publish compose file: service "serviceA" relies on bind-mount. You should use volumes`}) + }) + t.Run("refuse to publish with build section only", func(t *testing.T) { res := c.RunDockerComposeCmdNoCheck(t, "-f", "./fixtures/publish/compose-build-only.yml", "-p", projectName, "alpha", "publish", "test/test", "--with-env", "-y", "--dry-run")