Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/compose/compose.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ func (o *ProjectOptions) remoteLoaders(dockerCli command.Cli) []loader.ResourceL
if o.Offline {
return nil
}
git := remote.NewGitRemoteLoader(o.Offline)
git := remote.NewGitRemoteLoader(dockerCli, o.Offline)
oci := remote.NewOCIRemoteLoader(dockerCli, o.Offline)
return []loader.ResourceLoader{git, oci}
}
Expand Down
16 changes: 16 additions & 0 deletions cmd/compose/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ func runUp(
attachSet.RemoveAll(upOptions.noAttach...)
attach = attachSet.Elements()
}
displayLocationRemoteStack(dockerCli, project, buildOptions)

timeout := time.Duration(upOptions.waitTimeout) * time.Second
return backend.Up(ctx, project, api.UpOptions{
Expand Down Expand Up @@ -329,3 +330,18 @@ func setServiceScale(project *types.Project, name string, replicas int) error {
project.Services[name] = service
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
}
}
}
}
13 changes: 8 additions & 5 deletions pkg/remote/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/compose-spec/compose-go/v2/cli"
"github.com/compose-spec/compose-go/v2/loader"
"github.com/compose-spec/compose-go/v2/types"
"github.com/docker/cli/cli/command"
"github.com/docker/compose/v2/pkg/api"
"github.com/moby/buildkit/util/gitutil"
)
Expand All @@ -45,16 +46,18 @@ func gitRemoteLoaderEnabled() (bool, error) {
return false, nil
}

func NewGitRemoteLoader(offline bool) loader.ResourceLoader {
func NewGitRemoteLoader(dockerCli command.Cli, offline bool) loader.ResourceLoader {
return gitRemoteLoader{
offline: offline,
known: map[string]string{},
dockerCli: dockerCli,
offline: offline,
known: map[string]string{},
}
}

type gitRemoteLoader struct {
offline bool
known map[string]string
dockerCli command.Cli
offline bool
known map[string]string
}

func (g gitRemoteLoader) Accept(path string) bool {
Expand Down
12 changes: 6 additions & 6 deletions pkg/remote/oci.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ import (
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) {
if v := os.Getenv(OCI_REMOTE_ENABLED); v != "" {
Expand All @@ -61,10 +64,8 @@ type ociRemoteLoader struct {
known map[string]string
}

const prefix = "oci://"

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) {
Expand All @@ -82,7 +83,7 @@ func (g ociRemoteLoader) Load(ctx context.Context, path string) (string, error)

local, ok := g.known[path]
if !ok {
ref, err := reference.ParseDockerRef(path[len(prefix):])
ref, err := reference.ParseDockerRef(path[len(OciPrefix):])
if err != nil {
return "", err
}
Expand Down Expand Up @@ -121,7 +122,6 @@ func (g ociRemoteLoader) Load(ctx context.Context, path string) (string, error)
}
g.known[path] = local
}

return filepath.Join(local, "compose.yaml"), nil
}

Expand Down