Skip to content

Commit b6c8a2b

Browse files
gloursndeloof
authored andcommitted
display the location of OCI or GIT Compose stack download
Signed-off-by: Guillaume Lours <[email protected]>
1 parent 19571c2 commit b6c8a2b

File tree

4 files changed

+31
-12
lines changed

4 files changed

+31
-12
lines changed

cmd/compose/compose.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ func (o *ProjectOptions) remoteLoaders(dockerCli command.Cli) []loader.ResourceL
372372
if o.Offline {
373373
return nil
374374
}
375-
git := remote.NewGitRemoteLoader(o.Offline)
375+
git := remote.NewGitRemoteLoader(dockerCli, o.Offline)
376376
oci := remote.NewOCIRemoteLoader(dockerCli, o.Offline)
377377
return []loader.ResourceLoader{git, oci}
378378
}

cmd/compose/up.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ func runUp(
301301
attachSet.RemoveAll(upOptions.noAttach...)
302302
attach = attachSet.Elements()
303303
}
304+
displayLocationRemoteStack(dockerCli, project, buildOptions)
304305

305306
timeout := time.Duration(upOptions.waitTimeout) * time.Second
306307
return backend.Up(ctx, project, api.UpOptions{
@@ -329,3 +330,18 @@ func setServiceScale(project *types.Project, name string, replicas int) error {
329330
project.Services[name] = service
330331
return nil
331332
}
333+
334+
func displayLocationRemoteStack(dockerCli command.Cli, project *types.Project, options buildOptions) {
335+
if len(options.ProjectOptions.ConfigPaths) == 0 {
336+
return
337+
}
338+
mainComposeFile := options.ProjectOptions.ConfigPaths[0]
339+
if ui.Mode != ui.ModeQuiet && ui.Mode != ui.ModeJSON {
340+
for _, loader := range options.ProjectOptions.remoteLoaders(dockerCli) {
341+
if loader.Accept(mainComposeFile) {
342+
_, _ = fmt.Fprintf(dockerCli.Out(), "Your compose stack %q is stored in %q\n", mainComposeFile, project.WorkingDir)
343+
return
344+
}
345+
}
346+
}
347+
}

pkg/remote/git.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"github.com/compose-spec/compose-go/v2/cli"
2929
"github.com/compose-spec/compose-go/v2/loader"
3030
"github.com/compose-spec/compose-go/v2/types"
31+
"github.com/docker/cli/cli/command"
3132
"github.com/docker/compose/v2/pkg/api"
3233
"github.com/moby/buildkit/util/gitutil"
3334
)
@@ -45,16 +46,18 @@ func gitRemoteLoaderEnabled() (bool, error) {
4546
return false, nil
4647
}
4748

48-
func NewGitRemoteLoader(offline bool) loader.ResourceLoader {
49+
func NewGitRemoteLoader(dockerCli command.Cli, offline bool) loader.ResourceLoader {
4950
return gitRemoteLoader{
50-
offline: offline,
51-
known: map[string]string{},
51+
dockerCli: dockerCli,
52+
offline: offline,
53+
known: map[string]string{},
5254
}
5355
}
5456

5557
type gitRemoteLoader struct {
56-
offline bool
57-
known map[string]string
58+
dockerCli command.Cli
59+
offline bool
60+
known map[string]string
5861
}
5962

6063
func (g gitRemoteLoader) Accept(path string) bool {

pkg/remote/oci.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ import (
3434
v1 "github.com/opencontainers/image-spec/specs-go/v1"
3535
)
3636

37-
const OCI_REMOTE_ENABLED = "COMPOSE_EXPERIMENTAL_OCI_REMOTE"
37+
const (
38+
OCI_REMOTE_ENABLED = "COMPOSE_EXPERIMENTAL_OCI_REMOTE"
39+
OciPrefix = "oci://"
40+
)
3841

3942
func ociRemoteLoaderEnabled() (bool, error) {
4043
if v := os.Getenv(OCI_REMOTE_ENABLED); v != "" {
@@ -61,10 +64,8 @@ type ociRemoteLoader struct {
6164
known map[string]string
6265
}
6366

64-
const prefix = "oci://"
65-
6667
func (g ociRemoteLoader) Accept(path string) bool {
67-
return strings.HasPrefix(path, prefix)
68+
return strings.HasPrefix(path, OciPrefix)
6869
}
6970

7071
func (g ociRemoteLoader) Load(ctx context.Context, path string) (string, error) {
@@ -82,7 +83,7 @@ func (g ociRemoteLoader) Load(ctx context.Context, path string) (string, error)
8283

8384
local, ok := g.known[path]
8485
if !ok {
85-
ref, err := reference.ParseDockerRef(path[len(prefix):])
86+
ref, err := reference.ParseDockerRef(path[len(OciPrefix):])
8687
if err != nil {
8788
return "", err
8889
}
@@ -121,7 +122,6 @@ func (g ociRemoteLoader) Load(ctx context.Context, path string) (string, error)
121122
}
122123
g.known[path] = local
123124
}
124-
125125
return filepath.Join(local, "compose.yaml"), nil
126126
}
127127

0 commit comments

Comments
 (0)