From bcd000ab404f81c6ec70198fba2b8d3deddd6762 Mon Sep 17 00:00:00 2001 From: Nicolas De Loof Date: Tue, 4 Mar 2025 14:20:46 +0100 Subject: [PATCH] refuse to publish compose file with local include Signed-off-by: Nicolas De Loof --- cmd/compose/publish.go | 7 ++++++- pkg/e2e/fixtures/publish/another/compose.yml | 3 +++ pkg/e2e/fixtures/publish/compose-local-include.yml | 6 ++++++ pkg/e2e/publish_test.go | 6 ++++++ 4 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 pkg/e2e/fixtures/publish/another/compose.yml create mode 100644 pkg/e2e/fixtures/publish/compose-local-include.yml diff --git a/cmd/compose/publish.go b/cmd/compose/publish.go index 22d5aa0941..961420eba1 100644 --- a/cmd/compose/publish.go +++ b/cmd/compose/publish.go @@ -18,6 +18,7 @@ package compose import ( "context" + "errors" "github.com/docker/cli/cli/command" "github.com/spf13/cobra" @@ -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), diff --git a/pkg/e2e/fixtures/publish/another/compose.yml b/pkg/e2e/fixtures/publish/another/compose.yml new file mode 100644 index 0000000000..c8022b4687 --- /dev/null +++ b/pkg/e2e/fixtures/publish/another/compose.yml @@ -0,0 +1,3 @@ +services: + foo: + image: bar \ No newline at end of file diff --git a/pkg/e2e/fixtures/publish/compose-local-include.yml b/pkg/e2e/fixtures/publish/compose-local-include.yml new file mode 100644 index 0000000000..ad228af455 --- /dev/null +++ b/pkg/e2e/fixtures/publish/compose-local-include.yml @@ -0,0 +1,6 @@ +include: + - ./another/compose.yml + +services: + test: + image: test \ No newline at end of file diff --git a/pkg/e2e/publish_test.go b/pkg/e2e/publish_test.go index 3a94153436..e270637549 100644 --- a/pkg/e2e/publish_test.go +++ b/pkg/e2e/publish_test.go @@ -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"}) + }) }