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

Commit c1a8217

Browse files
committed
Fix rebase issues
Signed-off-by: Nicolas De Loof <[email protected]>
1 parent 82878c7 commit c1a8217

File tree

10 files changed

+110
-111
lines changed

10 files changed

+110
-111
lines changed

e2e/images_test.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,22 +72,21 @@ my.registry:5000/c-myapp latest [a-f0-9]{12} push-pull
7272
func TestImageListQuiet(t *testing.T) {
7373
runWithDindSwarmAndRegistry(t, func(info dindSwarmAndRegistryInfo) {
7474
cmd := info.configuredCmd
75-
insertBundles(t, cmd, info)
75+
insertBundles(t, cmd)
7676
verifyImageIDListOutput(t, cmd, 3, 2)
7777
})
7878
}
7979

8080
func TestImageListDigests(t *testing.T) {
8181
runWithDindSwarmAndRegistry(t, func(info dindSwarmAndRegistryInfo) {
8282
cmd := info.configuredCmd
83-
insertBundles(t, cmd, info)
84-
expected := `REPOSITORY TAG DIGEST APP IMAGE ID APP NAME
85-
%s latest <none> [a-f0-9]{12} push-pull
86-
a-simple-app latest <none> [a-f0-9]{12} simple
87-
b-simple-app latest <none> [a-f0-9]{12} simple
83+
insertBundles(t, cmd)
84+
expected := `REPOSITORY TAG DIGEST APP IMAGE ID APP NAME
85+
a-simple-app latest <none> [a-f0-9]{12} simple
86+
b-simple-app latest <none> [a-f0-9]{12} simple
87+
my.registry:5000/c-myapp latest <none> [a-f0-9]{12} push-pull
8888
`
89-
expectedOutput := fmt.Sprintf(expected, info.registryAddress+"/c-myapp")
90-
expectImageListDigestsOutput(t, cmd, expectedOutput)
89+
expectImageListDigestsOutput(t, cmd, expected)
9190
})
9291
}
9392

internal/cliopts/installerContext.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package cliopts
2+
3+
import (
4+
"fmt"
5+
"os"
6+
7+
"github.com/docker/cli/cli/command"
8+
"github.com/docker/cli/cli/config"
9+
"github.com/docker/cli/cli/flags"
10+
"github.com/pkg/errors"
11+
"github.com/sirupsen/logrus"
12+
"github.com/spf13/pflag"
13+
)
14+
15+
type InstallerContextOptions struct {
16+
installerContext string
17+
}
18+
19+
func (o *InstallerContextOptions) AddFlags(flags *pflag.FlagSet) {
20+
defaultContext, ok := os.LookupEnv("DOCKER_INSTALLER_CONTEXT")
21+
if !ok {
22+
defaultContext = "default"
23+
}
24+
flags.StringVar(&o.installerContext, "installer-context", defaultContext, "Context on which the installer image is ran")
25+
}
26+
27+
func (o *InstallerContextOptions) SetInstallerContext(dockerCli command.Cli) (command.Cli, error) {
28+
if o.installerContext != dockerCli.CurrentContext() {
29+
if _, err := dockerCli.ContextStore().GetMetadata(o.installerContext); err != nil {
30+
return nil, errors.Wrapf(err, "Unknown docker context %s", o.installerContext)
31+
}
32+
fmt.Fprintf(dockerCli.Out(), "Using context %q to run installer image", o.installerContext)
33+
cli, err := command.NewDockerCli()
34+
if err != nil {
35+
return nil, err
36+
}
37+
opts := flags.ClientOptions{
38+
Common: &flags.CommonOptions{
39+
Context: o.installerContext,
40+
LogLevel: logrus.GetLevel().String(),
41+
},
42+
ConfigDir: config.Dir(),
43+
}
44+
if err = cli.Apply(
45+
command.WithInputStream(dockerCli.In()),
46+
command.WithOutputStream(dockerCli.Out()),
47+
command.WithErrorStream(dockerCli.Err())); err != nil {
48+
return nil, err
49+
}
50+
if err = cli.Initialize(&opts); err != nil {
51+
return nil, err
52+
}
53+
return cli, nil
54+
}
55+
return dockerCli, nil
56+
}

internal/cnab/driver.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import (
66
"os"
77
"strings"
88

9+
"github.com/docker/app/internal/cliopts"
10+
store2 "github.com/docker/app/internal/store"
11+
912
"github.com/deislabs/cnab-go/claim"
1013
"github.com/deislabs/cnab-go/driver"
1114
dockerDriver "github.com/deislabs/cnab-go/driver/docker"
@@ -80,8 +83,8 @@ func isDockerHostLocal(host string) bool {
8083
return host == "" || strings.HasPrefix(host, "unix://") || strings.HasPrefix(host, "npipe://")
8184
}
8285

83-
// PrepareDriver prepares a driver per the user's request.
84-
func PrepareDriver(dockerCli command.Cli, bindMount BindMount, stdout io.Writer) (driver.Driver, *bytes.Buffer) {
86+
// prepareDriver prepares a driver per the user's request.
87+
func prepareDriver(dockerCli command.Cli, bindMount BindMount, stdout io.Writer) (driver.Driver, *bytes.Buffer) {
8588
d := &dockerDriver.Driver{}
8689
errBuf := bytes.NewBuffer(nil)
8790
d.SetDockerCli(dockerCli)
@@ -113,3 +116,16 @@ func PrepareDriver(dockerCli command.Cli, bindMount BindMount, stdout io.Writer)
113116

114117
return d, errBuf
115118
}
119+
120+
func SetupDriver(installation *store2.Installation, dockerCli command.Cli, opts cliopts.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 := RequiredClaimBindMount(installation.Claim, dockerCli)
126+
if err != nil {
127+
return nil, nil, err
128+
}
129+
driverImpl, errBuf := prepareDriver(dockerCli, bind, stdout)
130+
return driverImpl, errBuf, nil
131+
}

internal/commands/credentials.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -133,14 +133,5 @@ func prepareCredentialSet(b *bundle.Bundle, opts ...credentialSetOpt) (map[strin
133133
return nil, err
134134
}
135135
}
136-
137-
_, requiresDockerContext := b.Credentials[internal.CredentialDockerContextName]
138-
_, hasDockerContext := creds[internal.CredentialDockerContextName]
139-
140-
// FIXME not sure what this mean if we don't have --target-context
141-
if requiresDockerContext && !hasDockerContext {
142-
return nil, errors.New("no target context specified. Use --target-context= or DOCKER_TARGET_CONTEXT= to define it")
143-
}
144-
145136
return creds, nil
146137
}

internal/commands/image/inspect.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ package image
33
import (
44
"fmt"
55
"io/ioutil"
6+
"os"
7+
8+
"github.com/docker/app/internal/cliopts"
69

710
"github.com/deislabs/cnab-go/action"
811
"github.com/docker/app/internal"
@@ -16,6 +19,7 @@ import (
1619

1720
type inspectOptions struct {
1821
pretty bool
22+
cliopts.InstallerContextOptions
1923
}
2024

2125
func muteDockerCli(dockerCli command.Cli) func() {
@@ -41,6 +45,7 @@ $ docker app image inspect 34be4a0c5f50`,
4145
return runInspect(dockerCli, args[0], opts)
4246
},
4347
}
48+
opts.InstallerContextOptions.AddFlags(cmd.Flags())
4449
cmd.Flags().BoolVar(&opts.pretty, "pretty", false, "Print the information in a human friendly format")
4550

4651
return cmd
@@ -66,8 +71,10 @@ func runInspect(dockerCli command.Cli, appname string, opts inspectOptions) erro
6671
return err
6772
}
6873
installation.Bundle = bndl
69-
70-
driverImpl, errBuf := cnab.PrepareDriver(dockerCli, cnab.BindMount{}, nil)
74+
driverImpl, errBuf, err := cnab.SetupDriver(installation, dockerCli, opts.InstallerContextOptions, os.Stdout)
75+
if err != nil {
76+
return err
77+
}
7178
a := &action.RunCustom{
7279
Action: internal.ActionInspectName,
7380
Driver: driverImpl,

internal/commands/image/render.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@ import (
66
"io"
77
"os"
88

9-
"github.com/docker/app/internal/cliopts"
10-
119
"github.com/deislabs/cnab-go/action"
1210
"github.com/docker/app/internal"
1311
bdl "github.com/docker/app/internal/bundle"
12+
"github.com/docker/app/internal/cliopts"
1413
"github.com/docker/app/internal/cnab"
1514
appstore "github.com/docker/app/internal/store"
1615
"github.com/docker/cli/cli"
@@ -22,7 +21,7 @@ import (
2221

2322
type renderOptions struct {
2423
cliopts.ParametersOptions
25-
installerContextOptions
24+
cliopts.InstallerContextOptions
2625
formatDriver string
2726
renderOutput string
2827
}
@@ -40,7 +39,7 @@ func renderCmd(dockerCli command.Cli) *cobra.Command {
4039
},
4140
}
4241
opts.ParametersOptions.AddFlags(cmd.Flags())
43-
opts.installerContextOptions.addFlags(cmd.Flags())
42+
opts.InstallerContextOptions.AddFlags(cmd.Flags())
4443
cmd.Flags().StringVarP(&opts.renderOutput, "output", "o", "-", "Output file")
4544
cmd.Flags().StringVar(&opts.formatDriver, "formatter", "yaml", "Configure the output format (yaml|json)")
4645

@@ -98,7 +97,7 @@ func prepareCustomAction(actionName string, dockerCli command.Cli, appname strin
9897
return nil, nil, nil, err
9998
}
10099

101-
driverImpl, errBuf, err := setupDriver(installation, dockerCli, opts.installerContextOptions, stdout)
100+
driverImpl, errBuf, err := cnab.SetupDriver(installation, dockerCli, opts.InstallerContextOptions, stdout)
102101
if err != nil {
103102
return nil, nil, nil, err
104103
}

internal/commands/remove.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ import (
44
"fmt"
55
"os"
66

7+
"github.com/docker/app/internal/cnab"
8+
9+
"github.com/docker/app/internal/cliopts"
10+
711
"github.com/deislabs/cnab-go/action"
812
"github.com/deislabs/cnab-go/credentials"
913
"github.com/docker/cli/cli"
@@ -13,7 +17,7 @@ import (
1317

1418
type removeOptions struct {
1519
credentialOptions
16-
installerContextOptions
20+
cliopts.InstallerContextOptions
1721
force bool
1822
}
1923

@@ -31,7 +35,7 @@ func removeCmd(dockerCli command.Cli) *cobra.Command {
3135
},
3236
}
3337
opts.credentialOptions.addFlags(cmd.Flags())
34-
opts.installerContextOptions.addFlags(cmd.Flags())
38+
opts.InstallerContextOptions.AddFlags(cmd.Flags())
3539
cmd.Flags().BoolVar(&opts.force, "force", false, "Force the removal of a running App")
3640

3741
return cmd
@@ -61,7 +65,7 @@ func runRemove(dockerCli command.Cli, installationName string, opts removeOption
6165
fmt.Fprintf(os.Stderr, "deletion forced for running App %q\n", installationName)
6266
}()
6367
}
64-
driverImpl, errBuf, err := setupDriver(installation, dockerCli, opts.installerContextOptions, os.Stdout)
68+
driverImpl, errBuf, err := cnab.SetupDriver(installation, dockerCli, opts.InstallerContextOptions, os.Stdout)
6569
if err != nil {
6670
return err
6771
}

internal/commands/root.go

Lines changed: 1 addition & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,18 @@
11
package commands
22

33
import (
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-
186113
type 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

Comments
 (0)