@@ -8,22 +8,22 @@ import (
88 "io"
99 "io/ioutil"
1010 "os"
11- "path/filepath"
1211 "strings"
1312
1413 "github.com/deislabs/duffle/pkg/action"
1514 "github.com/deislabs/duffle/pkg/bundle"
1615 "github.com/deislabs/duffle/pkg/claim"
1716 "github.com/deislabs/duffle/pkg/credentials"
1817 "github.com/deislabs/duffle/pkg/driver"
19- "github.com/deislabs/duffle/pkg/duffle/home"
2018 "github.com/deislabs/duffle/pkg/loader"
2119 "github.com/docker/app/internal"
2220 "github.com/docker/app/internal/packager"
23- bundlestore "github.com/docker/app/internal/store"
21+ appstore "github.com/docker/app/internal/store"
2422 "github.com/docker/cli/cli/command"
23+ "github.com/docker/cli/cli/config"
2524 "github.com/docker/cli/cli/context/docker"
2625 "github.com/docker/cli/cli/context/store"
26+ contextstore "github.com/docker/cli/cli/context/store"
2727 "github.com/docker/distribution/reference"
2828 "github.com/docker/docker/api/types"
2929 "github.com/docker/docker/api/types/container"
@@ -41,13 +41,10 @@ const defaultSocketPath string = "/var/run/docker.sock"
4141
4242type credentialSetOpt func (b * bundle.Bundle , creds credentials.Set ) error
4343
44- func addNamedCredentialSets (namedCredentialsets []string ) credentialSetOpt {
44+ func addNamedCredentialSets (credStore appstore. CredentialStore , namedCredentialsets []string ) credentialSetOpt {
4545 return func (_ * bundle.Bundle , creds credentials.Set ) error {
4646 for _ , file := range namedCredentialsets {
47- if _ , err := os .Stat (file ); err != nil {
48- file = filepath .Join (duffleHome ().Credentials (), file + ".yaml" )
49- }
50- c , err := credentials .Load (file )
47+ c , err := credStore .Read (file )
5148 if err != nil {
5249 return err
5350 }
@@ -63,12 +60,12 @@ func addNamedCredentialSets(namedCredentialsets []string) credentialSetOpt {
6360 }
6461}
6562
66- func addDockerCredentials (contextName string , contextStore store.Store ) credentialSetOpt {
63+ func addDockerCredentials (contextName string , store contextstore .Store ) credentialSetOpt {
6764 // docker desktop contexts require some rewriting for being used within a container
68- contextStore = dockerDesktopAwareStore {Store : contextStore }
65+ store = dockerDesktopAwareStore {Store : store }
6966 return func (_ * bundle.Bundle , creds credentials.Set ) error {
7067 if contextName != "" {
71- data , err := ioutil .ReadAll (store .Export (contextName , contextStore ))
68+ data , err := ioutil .ReadAll (contextstore .Export (contextName , store ))
7269 if err != nil {
7370 return err
7471 }
@@ -141,10 +138,6 @@ func getTargetContext(optstargetContext, currentContext string) string {
141138 return targetContext
142139}
143140
144- func duffleHome () home.Home {
145- return home .Home (home .DefaultHome ())
146- }
147-
148141// prepareDriver prepares a driver per the user's request.
149142func prepareDriver (dockerCli command.Cli , bindMount bindMount , stdout io.Writer ) (driver.Driver , * bytes.Buffer , error ) {
150143 driverImpl , err := driver .Lookup ("docker" )
@@ -217,11 +210,11 @@ func extractAndLoadAppBasedBundle(dockerCli command.Cli, name string) (*bundle.B
217210 return makeBundleFromApp (dockerCli , app )
218211}
219212
220- func resolveBundle (dockerCli command.Cli , name string , pullRef bool , insecureRegistries []string ) (* bundle.Bundle , error ) {
213+ func resolveBundle (dockerCli command.Cli , bundleStore appstore. BundleStore , name string , pullRef bool , insecureRegistries []string ) (* bundle.Bundle , error ) {
221214 // resolution logic:
222215 // - if there is a docker-app package in working directory, or an http:// / https:// prefix, use packager.Extract result
223216 // - the name has a .json or .cnab extension and refers to an existing file or web resource: load the bundle
224- // - name matches a bundle name:version stored in duffle bundle store: use it
217+ // - name matches a bundle name:version stored in the bundle store: use it
225218 // - pull the bundle from the registry and add it to the bundle store
226219 name , kind := getAppNameKind (name )
227220 switch kind {
@@ -246,7 +239,7 @@ func resolveBundle(dockerCli command.Cli, name string, pullRef bool, insecureReg
246239 if err != nil {
247240 return nil , errors .Wrap (err , name )
248241 }
249- return bundlestore .LookupOrPullBundle (dockerCli , reference .TagNameOnly (ref ), pullRef , insecureRegistries )
242+ return bundleStore .LookupOrPullBundle (reference .TagNameOnly (ref ), pullRef , dockerCli . ConfigFile () , insecureRegistries )
250243 }
251244 return nil , fmt .Errorf ("could not resolve bundle %q" , name )
252245}
@@ -306,6 +299,14 @@ func isDockerHostLocal(host string) bool {
306299
307300func prepareCustomAction (actionName string , dockerCli command.Cli , appname string , stdout io.Writer ,
308301 registryOpts registryOptions , pullOpts pullOptions , paramsOpts parametersOptions ) (* action.RunCustom , * claim.Claim , * bytes.Buffer , error ) {
302+ s , err := appstore .NewApplicationStore (config .Dir ())
303+ if err != nil {
304+ return nil , nil , nil , err
305+ }
306+ bundleStore , err := s .BundleStore ()
307+ if err != nil {
308+ return nil , nil , nil , err
309+ }
309310
310311 c , err := claim .New ("custom-action" )
311312 if err != nil {
@@ -315,7 +316,7 @@ func prepareCustomAction(actionName string, dockerCli command.Cli, appname strin
315316 if err != nil {
316317 return nil , nil , nil , err
317318 }
318- bundle , err := resolveBundle (dockerCli , appname , pullOpts .pull , registryOpts .insecureRegistries )
319+ bundle , err := resolveBundle (dockerCli , bundleStore , appname , pullOpts .pull , registryOpts .insecureRegistries )
319320 if err != nil {
320321 return nil , nil , nil , err
321322 }
0 commit comments