display the location of OCI or GIT Compose stack download

Signed-off-by: Guillaume Lours <705411+glours@users.noreply.github.com>
This commit is contained in:
Guillaume Lours 2025-03-03 10:53:01 +01:00 committed by Nicolas De loof
parent 19571c2c81
commit b6c8a2b9fc
4 changed files with 31 additions and 12 deletions

View File

@ -372,7 +372,7 @@ func (o *ProjectOptions) remoteLoaders(dockerCli command.Cli) []loader.ResourceL
if o.Offline { if o.Offline {
return nil return nil
} }
git := remote.NewGitRemoteLoader(o.Offline) git := remote.NewGitRemoteLoader(dockerCli, o.Offline)
oci := remote.NewOCIRemoteLoader(dockerCli, o.Offline) oci := remote.NewOCIRemoteLoader(dockerCli, o.Offline)
return []loader.ResourceLoader{git, oci} return []loader.ResourceLoader{git, oci}
} }

View File

@ -301,6 +301,7 @@ func runUp(
attachSet.RemoveAll(upOptions.noAttach...) attachSet.RemoveAll(upOptions.noAttach...)
attach = attachSet.Elements() attach = attachSet.Elements()
} }
displayLocationRemoteStack(dockerCli, project, buildOptions)
timeout := time.Duration(upOptions.waitTimeout) * time.Second timeout := time.Duration(upOptions.waitTimeout) * time.Second
return backend.Up(ctx, project, api.UpOptions{ return backend.Up(ctx, project, api.UpOptions{
@ -329,3 +330,18 @@ func setServiceScale(project *types.Project, name string, replicas int) error {
project.Services[name] = service project.Services[name] = service
return nil return nil
} }
func displayLocationRemoteStack(dockerCli command.Cli, project *types.Project, options buildOptions) {
if len(options.ProjectOptions.ConfigPaths) == 0 {
return
}
mainComposeFile := options.ProjectOptions.ConfigPaths[0]
if ui.Mode != ui.ModeQuiet && ui.Mode != ui.ModeJSON {
for _, loader := range options.ProjectOptions.remoteLoaders(dockerCli) {
if loader.Accept(mainComposeFile) {
_, _ = fmt.Fprintf(dockerCli.Out(), "Your compose stack %q is stored in %q\n", mainComposeFile, project.WorkingDir)
return
}
}
}
}

View File

@ -28,6 +28,7 @@ import (
"github.com/compose-spec/compose-go/v2/cli" "github.com/compose-spec/compose-go/v2/cli"
"github.com/compose-spec/compose-go/v2/loader" "github.com/compose-spec/compose-go/v2/loader"
"github.com/compose-spec/compose-go/v2/types" "github.com/compose-spec/compose-go/v2/types"
"github.com/docker/cli/cli/command"
"github.com/docker/compose/v2/pkg/api" "github.com/docker/compose/v2/pkg/api"
"github.com/moby/buildkit/util/gitutil" "github.com/moby/buildkit/util/gitutil"
) )
@ -45,14 +46,16 @@ func gitRemoteLoaderEnabled() (bool, error) {
return false, nil return false, nil
} }
func NewGitRemoteLoader(offline bool) loader.ResourceLoader { func NewGitRemoteLoader(dockerCli command.Cli, offline bool) loader.ResourceLoader {
return gitRemoteLoader{ return gitRemoteLoader{
dockerCli: dockerCli,
offline: offline, offline: offline,
known: map[string]string{}, known: map[string]string{},
} }
} }
type gitRemoteLoader struct { type gitRemoteLoader struct {
dockerCli command.Cli
offline bool offline bool
known map[string]string known map[string]string
} }

View File

@ -34,7 +34,10 @@ import (
v1 "github.com/opencontainers/image-spec/specs-go/v1" v1 "github.com/opencontainers/image-spec/specs-go/v1"
) )
const OCI_REMOTE_ENABLED = "COMPOSE_EXPERIMENTAL_OCI_REMOTE" const (
OCI_REMOTE_ENABLED = "COMPOSE_EXPERIMENTAL_OCI_REMOTE"
OciPrefix = "oci://"
)
func ociRemoteLoaderEnabled() (bool, error) { func ociRemoteLoaderEnabled() (bool, error) {
if v := os.Getenv(OCI_REMOTE_ENABLED); v != "" { if v := os.Getenv(OCI_REMOTE_ENABLED); v != "" {
@ -61,10 +64,8 @@ type ociRemoteLoader struct {
known map[string]string known map[string]string
} }
const prefix = "oci://"
func (g ociRemoteLoader) Accept(path string) bool { func (g ociRemoteLoader) Accept(path string) bool {
return strings.HasPrefix(path, prefix) return strings.HasPrefix(path, OciPrefix)
} }
func (g ociRemoteLoader) Load(ctx context.Context, path string) (string, error) { 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)
local, ok := g.known[path] local, ok := g.known[path]
if !ok { if !ok {
ref, err := reference.ParseDockerRef(path[len(prefix):]) ref, err := reference.ParseDockerRef(path[len(OciPrefix):])
if err != nil { if err != nil {
return "", err return "", err
} }
@ -121,7 +122,6 @@ func (g ociRemoteLoader) Load(ctx context.Context, path string) (string, error)
} }
g.known[path] = local g.known[path] = local
} }
return filepath.Join(local, "compose.yaml"), nil return filepath.Join(local, "compose.yaml"), nil
} }