Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.

Commit c0ca8ee

Browse files
committed
Rewrite Docker Desktop contexts before testing for required bind mounts
Signed-off-by: Simon Ferquel <[email protected]>
1 parent 9668790 commit c0ca8ee

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

internal/commands/cnab.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -195,20 +195,22 @@ func requiredClaimBindMount(c claim.Claim, targetContextName string, dockerCli c
195195
specifiedOrchestrator = rawOrchestrator.(string)
196196
}
197197

198-
return requiredBindMount(targetContextName, specifiedOrchestrator, dockerCli)
198+
return requiredBindMount(targetContextName, specifiedOrchestrator, dockerCli.ContextStore())
199199
}
200200

201-
func requiredBindMount(targetContextName string, targetOrchestrator string, dockerCli command.Cli) (bindMount, error) {
201+
func requiredBindMount(targetContextName string, targetOrchestrator string, s store.Store) (bindMount, error) {
202202
if targetOrchestrator == "kubernetes" {
203203
return bindMount{}, nil
204204
}
205205

206-
// TODO:smarter handling of default context required
207206
if targetContextName == "" {
208-
return bindMount{true, defaultSocketPath}, nil
207+
targetContextName = "default"
209208
}
210209

211-
ctxMeta, err := dockerCli.ContextStore().GetContextMetadata(targetContextName)
210+
// in case of docker desktop, we want to rewrite the context in cases where it targets the local swarm or Kubernetes
211+
s = &dockerDesktopAwareStore{Store: s}
212+
213+
ctxMeta, err := s.GetContextMetadata(targetContextName)
212214
if err != nil {
213215
return bindMount{}, err
214216
}

internal/commands/cnab_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ import (
44
"testing"
55

66
"github.com/docker/cli/cli/command"
7+
cliflags "github.com/docker/cli/cli/flags"
78
"gotest.tools/assert"
89
)
910

1011
func TestRequiresBindMount(t *testing.T) {
1112
dockerCli, err := command.NewDockerCli()
1213
assert.NilError(t, err)
14+
dockerCli.Initialize(cliflags.NewClientOptions())
1315

1416
testCases := []struct {
1517
name string
@@ -39,7 +41,7 @@ func TestRequiresBindMount(t *testing.T) {
3941

4042
for _, testCase := range testCases {
4143
t.Run(testCase.name, func(t *testing.T) {
42-
result, err := requiredBindMount(testCase.targetContextName, testCase.targetOrchestrator, dockerCli)
44+
result, err := requiredBindMount(testCase.targetContextName, testCase.targetOrchestrator, dockerCli.ContextStore())
4345
if testCase.expectedError == "" {
4446
assert.NilError(t, err)
4547
} else {

internal/commands/install.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func runInstall(dockerCli command.Cli, appname string, opts installOptions) erro
7373
return errors.New("with-registry-auth is not supported at the moment")
7474
}
7575
targetContext := getTargetContext(opts.targetContext, dockerCli.CurrentContext())
76-
bind, err := requiredBindMount(targetContext, opts.orchestrator, dockerCli)
76+
bind, err := requiredBindMount(targetContext, opts.orchestrator, dockerCli.ContextStore())
7777
if err != nil {
7878
return err
7979
}

0 commit comments

Comments
 (0)