Skip to content
This repository was archived by the owner on Nov 27, 2023. It is now read-only.

Commit f8bf0ac

Browse files
authored
Merge pull request #1018 from gtardif/compose_moby_ctx
`compose up` and other compose commands running on “Moby” context type.
2 parents 3190456 + fea0cf8 commit f8bf0ac

29 files changed

+38
-89
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,12 @@ jobs:
6060

6161
- name: Test
6262
env:
63-
BUILD_TAGS: example,local
63+
BUILD_TAGS: example
6464
run: make -f builder.Makefile test
6565

6666
- name: Build for local E2E
6767
env:
68-
BUILD_TAGS: example,local,e2e
68+
BUILD_TAGS: example,e2e
6969
run: make -f builder.Makefile cli
7070

7171
- name: E2E Test

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ protos: ## Generate go code from .proto files
3939
cli: ## Compile the cli
4040
@docker build . --target cli \
4141
--platform local \
42-
--build-arg BUILD_TAGS=example,local,e2e \
42+
--build-arg BUILD_TAGS=example,e2e \
4343
--build-arg GIT_TAG=$(GIT_TAG) \
4444
--output ./bin
4545

@@ -63,7 +63,7 @@ cross: ## Compile the CLI for linux, darwin and windows
6363

6464
test: ## Run unit tests
6565
@docker build . \
66-
--build-arg BUILD_TAGS=example,local \
66+
--build-arg BUILD_TAGS=example \
6767
--build-arg GIT_TAG=$(GIT_TAG) \
6868
--target test
6969

@@ -72,7 +72,7 @@ cache-clear: ## Clear the builder cache
7272

7373
lint: ## run linter(s)
7474
@docker build . \
75-
--build-arg BUILD_TAGS=example,local,e2e \
75+
--build-arg BUILD_TAGS=example,e2e \
7676
--build-arg GIT_TAG=$(GIT_TAG) \
7777
--target lint
7878

api/client/client.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,15 @@ import (
3232

3333
// New returns a backend client associated with current context
3434
func New(ctx context.Context) (*Client, error) {
35+
return newWithDefaultBackend(ctx, "")
36+
}
37+
38+
// NewWithDefaultLocalBackend returns a backend client associated with current context or local backend if on default context type
39+
func NewWithDefaultLocalBackend(ctx context.Context) (*Client, error) {
40+
return newWithDefaultBackend(ctx, store.LocalContextType)
41+
}
42+
43+
func newWithDefaultBackend(ctx context.Context, defaultBackend string) (*Client, error) {
3544
currentContext := apicontext.CurrentContext(ctx)
3645
s := store.ContextStore(ctx)
3746

@@ -40,7 +49,12 @@ func New(ctx context.Context) (*Client, error) {
4049
return nil, err
4150
}
4251

43-
service, err := backend.Get(ctx, cc.Type())
52+
backendName := cc.Type()
53+
if backendName == store.DefaultContextType && defaultBackend != "" {
54+
backendName = defaultBackend
55+
}
56+
57+
service, err := backend.Get(ctx, backendName)
4458
if err != nil {
4559
return nil, err
4660
}

cli/cmd/compose/build.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func buildCommand() *cobra.Command {
4545
}
4646

4747
func runBuild(ctx context.Context, opts buildOptions, services []string) error {
48-
c, err := client.New(ctx)
48+
c, err := client.NewWithDefaultLocalBackend(ctx)
4949
if err != nil {
5050
return err
5151
}

cli/cmd/compose/compose.go

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,12 @@
1717
package compose
1818

1919
import (
20-
"context"
21-
2220
"github.com/compose-spec/compose-go/cli"
2321
"github.com/compose-spec/compose-go/types"
2422
"github.com/spf13/cobra"
2523
"github.com/spf13/pflag"
2624

27-
"github.com/docker/compose-cli/api/client"
2825
"github.com/docker/compose-cli/context/store"
29-
"github.com/docker/compose-cli/errdefs"
3026
)
3127

3228
type composeOptions struct {
@@ -76,9 +72,6 @@ func Command(contextType string) *cobra.Command {
7672
command := &cobra.Command{
7773
Short: "Docker Compose",
7874
Use: "compose",
79-
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
80-
return checkComposeSupport(cmd.Context())
81-
},
8275
}
8376

8477
command.AddCommand(
@@ -90,7 +83,7 @@ func Command(contextType string) *cobra.Command {
9083
convertCommand(),
9184
)
9285

93-
if contextType == store.LocalContextType {
86+
if contextType == store.LocalContextType || contextType == store.DefaultContextType {
9487
command.AddCommand(
9588
buildCommand(),
9689
pushCommand(),
@@ -101,15 +94,6 @@ func Command(contextType string) *cobra.Command {
10194
return command
10295
}
10396

104-
func checkComposeSupport(ctx context.Context) error {
105-
_, err := client.New(ctx)
106-
if errdefs.IsNotFoundError(err) {
107-
return errdefs.ErrNotImplemented
108-
}
109-
110-
return err
111-
}
112-
11397
//
11498
func filter(project *types.Project, services []string) error {
11599
if len(services) == 0 {

cli/cmd/compose/convert.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func convertCommand() *cobra.Command {
4646

4747
func runConvert(ctx context.Context, opts composeOptions) error {
4848
var json []byte
49-
c, err := client.New(ctx)
49+
c, err := client.NewWithDefaultLocalBackend(ctx)
5050
if err != nil {
5151
return err
5252
}

cli/cmd/compose/down.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func downCommand() *cobra.Command {
4141
}
4242

4343
func runDown(ctx context.Context, opts composeOptions) error {
44-
c, err := client.New(ctx)
44+
c, err := client.NewWithDefaultLocalBackend(ctx)
4545
if err != nil {
4646
return err
4747
}

cli/cmd/compose/list.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func listCommand() *cobra.Command {
4343
}
4444

4545
func runList(ctx context.Context, opts composeOptions) error {
46-
c, err := client.New(ctx)
46+
c, err := client.NewWithDefaultLocalBackend(ctx)
4747
if err != nil {
4848
return err
4949
}

cli/cmd/compose/logs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func logsCommand() *cobra.Command {
4141
}
4242

4343
func runLogs(ctx context.Context, opts composeOptions) error {
44-
c, err := client.New(ctx)
44+
c, err := client.NewWithDefaultLocalBackend(ctx)
4545
if err != nil {
4646
return err
4747
}

cli/cmd/compose/ps.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func psCommand() *cobra.Command {
4545
}
4646

4747
func runPs(ctx context.Context, opts composeOptions) error {
48-
c, err := client.New(ctx)
48+
c, err := client.NewWithDefaultLocalBackend(ctx)
4949
if err != nil {
5050
return err
5151
}

0 commit comments

Comments
 (0)