Skip to content

Commit

Permalink
refuse to publish compose file with local include
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolas De Loof <[email protected]>
  • Loading branch information
ndeloof authored and glours committed Mar 4, 2025
1 parent 8092ce9 commit bcd000a
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
7 changes: 6 additions & 1 deletion cmd/compose/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package compose

import (
"context"
"errors"

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

func runPublish(ctx context.Context, dockerCli command.Cli, backend api.Service, opts publishOptions, repository string) error {
project, _, err := opts.ToProject(ctx, dockerCli, nil)
project, metrics, err := opts.ToProject(ctx, dockerCli, nil)
if err != nil {
return err
}

if metrics.CountIncludesLocal > 0 {
return errors.New("cannot publish compose file with local includes")
}

return backend.Publish(ctx, project, repository, api.PublishOptions{
ResolveImageDigests: opts.resolveImageDigests,
OCIVersion: api.OCIVersion(opts.ociVersion),
Expand Down
3 changes: 3 additions & 0 deletions pkg/e2e/fixtures/publish/another/compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
services:
foo:
image: bar
6 changes: 6 additions & 0 deletions pkg/e2e/fixtures/publish/compose-local-include.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
include:
- ./another/compose.yml

services:
test:
image: test
6 changes: 6 additions & 0 deletions pkg/e2e/publish_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,10 @@ FOO=bar`), res.Combined())
assert.Assert(t, strings.Contains(res.Combined(), "serviceA"), res.Combined())
assert.Assert(t, strings.Contains(res.Combined(), "serviceB"), res.Combined())
})

t.Run("refuse to publish with local include", func(t *testing.T) {
res := c.RunDockerComposeCmdNoCheck(t, "-f", "./fixtures/publish/compose-local-include.yml",
"-p", projectName, "alpha", "publish", "test/test", "--dry-run")
res.Assert(t, icmd.Expected{ExitCode: 1, Err: "cannot publish compose file with local includes"})
})
}

0 comments on commit bcd000a

Please sign in to comment.