11package commands
22
33import (
4- "bytes"
54 "fmt"
6- "io"
75 "io/ioutil"
86 "os"
97
108 "github.com/deislabs/cnab-go/claim"
11- "github.com/deislabs/cnab-go/driver"
129 "github.com/docker/app/internal"
13- "github.com/docker/app/internal/cnab"
1410 "github.com/docker/app/internal/commands/build"
1511 "github.com/docker/app/internal/commands/image"
1612 "github.com/docker/app/internal/store"
1713 appstore "github.com/docker/app/internal/store"
1814 "github.com/docker/cli/cli/command"
1915 "github.com/docker/cli/cli/config"
20- "github.com/docker/cli/cli/flags"
21- "github.com/pkg/errors"
22- "github.com/sirupsen/logrus"
2316 "github.com/spf13/cobra"
2417 "github.com/spf13/pflag"
2518)
@@ -117,72 +110,6 @@ func prepareBundleStore() (store.BundleStore, error) {
117110 return bundleStore , nil
118111}
119112
120- func setupDriver (installation * appstore.Installation , dockerCli command.Cli , opts installerContextOptions , stdout io.Writer ) (driver.Driver , * bytes.Buffer , error ) {
121- dockerCli , err := opts .setInstallerContext (dockerCli )
122- if err != nil {
123- return nil , nil , err
124- }
125- bind , err := cnab .RequiredClaimBindMount (installation .Claim , dockerCli )
126- if err != nil {
127- return nil , nil , err
128- }
129- driverImpl , errBuf := cnab .PrepareDriver (dockerCli , bind , stdout )
130- return driverImpl , errBuf , nil
131- }
132-
133- type parametersOptions struct {
134- parametersFiles []string
135- overrides []string
136- }
137-
138- func (o * parametersOptions ) addFlags (flags * pflag.FlagSet ) {
139- flags .StringArrayVar (& o .parametersFiles , "parameters-file" , []string {}, "Override parameters file" )
140- flags .StringArrayVarP (& o .overrides , "set" , "s" , []string {}, "Override parameter value" )
141- }
142-
143- type installerContextOptions struct {
144- installerContext string
145- }
146-
147- func (o * installerContextOptions ) addFlags (flags * pflag.FlagSet ) {
148- defaultContext , ok := os .LookupEnv ("DOCKER_INSTALLER_CONTEXT" )
149- if ! ok {
150- defaultContext = "default"
151- }
152- flags .StringVar (& o .installerContext , "installer-context" , defaultContext , "Context on which the installer image is ran" )
153- }
154-
155- func (o * installerContextOptions ) setInstallerContext (dockerCli command.Cli ) (command.Cli , error ) {
156- if o .installerContext != dockerCli .CurrentContext () {
157- if _ , err := dockerCli .ContextStore ().GetMetadata (o .installerContext ); err != nil {
158- return nil , errors .Wrapf (err , "Unknown docker context %s" , o .installerContext )
159- }
160- fmt .Fprintf (dockerCli .Out (), "Using context %q to run installer image" , o .installerContext )
161- cli , err := command .NewDockerCli ()
162- if err != nil {
163- return nil , err
164- }
165- opts := flags.ClientOptions {
166- Common : & flags.CommonOptions {
167- Context : o .installerContext ,
168- LogLevel : logrus .GetLevel ().String (),
169- },
170- ConfigDir : config .Dir (),
171- }
172- if err = cli .Apply (
173- command .WithInputStream (dockerCli .In ()),
174- command .WithOutputStream (dockerCli .Out ()),
175- command .WithErrorStream (dockerCli .Err ())); err != nil {
176- return nil , err
177- }
178- if err = cli .Initialize (& opts ); err != nil {
179- return nil , err
180- }
181- return cli , nil
182- }
183- return dockerCli , nil
184- }
185-
186113type credentialOptions struct {
187114 credentialsets []string
188115 credentials []string
@@ -204,7 +131,7 @@ func (o *credentialOptions) CredentialSetOpts(dockerCli command.Cli, credentialS
204131 }
205132}
206133
207- func isInstallationFailed (installation * appstore.Installation ) bool {
134+ func IsInstallationFailed (installation * appstore.Installation ) bool {
208135 return installation .Result .Action == claim .ActionInstall &&
209136 installation .Result .Status == claim .StatusFailure
210137}
0 commit comments