Skip to content

Commit bcd000a

Browse files
ndeloofglours
authored andcommitted
refuse to publish compose file with local include
Signed-off-by: Nicolas De Loof <[email protected]>
1 parent 8092ce9 commit bcd000a

File tree

4 files changed

+21
-1
lines changed

4 files changed

+21
-1
lines changed

cmd/compose/publish.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package compose
1818

1919
import (
2020
"context"
21+
"errors"
2122

2223
"github.com/docker/cli/cli/command"
2324
"github.com/spf13/cobra"
@@ -55,11 +56,15 @@ func publishCommand(p *ProjectOptions, dockerCli command.Cli, backend api.Servic
5556
}
5657

5758
func runPublish(ctx context.Context, dockerCli command.Cli, backend api.Service, opts publishOptions, repository string) error {
58-
project, _, err := opts.ToProject(ctx, dockerCli, nil)
59+
project, metrics, err := opts.ToProject(ctx, dockerCli, nil)
5960
if err != nil {
6061
return err
6162
}
6263

64+
if metrics.CountIncludesLocal > 0 {
65+
return errors.New("cannot publish compose file with local includes")
66+
}
67+
6368
return backend.Publish(ctx, project, repository, api.PublishOptions{
6469
ResolveImageDigests: opts.resolveImageDigests,
6570
OCIVersion: api.OCIVersion(opts.ociVersion),
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
services:
2+
foo:
3+
image: bar
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
include:
2+
- ./another/compose.yml
3+
4+
services:
5+
test:
6+
image: test

pkg/e2e/publish_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,4 +116,10 @@ FOO=bar`), res.Combined())
116116
assert.Assert(t, strings.Contains(res.Combined(), "serviceA"), res.Combined())
117117
assert.Assert(t, strings.Contains(res.Combined(), "serviceB"), res.Combined())
118118
})
119+
120+
t.Run("refuse to publish with local include", func(t *testing.T) {
121+
res := c.RunDockerComposeCmdNoCheck(t, "-f", "./fixtures/publish/compose-local-include.yml",
122+
"-p", projectName, "alpha", "publish", "test/test", "--dry-run")
123+
res.Assert(t, icmd.Expected{ExitCode: 1, Err: "cannot publish compose file with local includes"})
124+
})
119125
}

0 commit comments

Comments
 (0)