Skip to content

Commit

Permalink
reject compose file with bind mounts
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolas De Loof <[email protected]>
  • Loading branch information
ndeloof committed Mar 4, 2025
1 parent 8092ce9 commit 7f499dc
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pkg/compose/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,15 @@ func (s *composeService) preChecks(project *types.Project, options api.PublishOp
}
return acceptPublishEnvVariables(s.dockerCli)
}

for _, config := range project.Services {
for _, volume := range config.Volumes {
if volume.Type == types.VolumeTypeBind {
return false, errors.New("cannot publish a compose file relying on bind-mount. You should use volumes")
}
}
}

return true, nil
}

Expand Down
5 changes: 5 additions & 0 deletions pkg/e2e/fixtures/publish/compose-bind-mount.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
services:
serviceA:
image: a
volumes:
- .:/user-data
6 changes: 6 additions & 0 deletions pkg/e2e/publish_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 a compose file relying 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")
Expand Down

0 comments on commit 7f499dc

Please sign in to comment.