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

Commit dab1159

Browse files
Move installer-context as a global flag
Signed-off-by: Silvin Lubecki <[email protected]>
1 parent b621499 commit dab1159

File tree

10 files changed

+58
-63
lines changed

10 files changed

+58
-63
lines changed

e2e/testdata/plugin-usage.golden

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ Usage: docker app [OPTIONS] COMMAND
44
A tool to build, share and run a Docker App
55

66
Options:
7-
--version Print version information
7+
--installer-context string Context on which the installer image
8+
is ran (default "default")
9+
--version Print version information
810

911
Management Commands:
1012
image Manage App images

internal/cnab/driver.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ func prepareDriver(dockerCli command.Cli, bindMount BindMount, stdout io.Writer)
119119
return d, errBuf
120120
}
121121

122-
func SetupDriver(installation *store2.Installation, dockerCli command.Cli, opts cliopts.InstallerContextOptions, stdout io.Writer) (driver.Driver, *bytes.Buffer, error) {
122+
func SetupDriver(installation *store2.Installation, dockerCli command.Cli, opts *cliopts.InstallerContextOptions, stdout io.Writer) (driver.Driver, *bytes.Buffer, error) {
123123
dockerCli, err := opts.SetInstallerContext(dockerCli)
124124
if err != nil {
125125
return nil, nil, err

internal/commands/image/command.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
package image
22

33
import (
4+
"github.com/docker/app/internal/cliopts"
45
"github.com/docker/cli/cli/command"
56
"github.com/spf13/cobra"
67
)
78

89
// Cmd is the image top level command
9-
func Cmd(dockerCli command.Cli) *cobra.Command {
10+
func Cmd(dockerCli command.Cli, installerContext *cliopts.InstallerContextOptions) *cobra.Command {
1011
cmd := &cobra.Command{
1112
Short: "Manage App images",
1213
Use: "image",
@@ -16,8 +17,8 @@ func Cmd(dockerCli command.Cli) *cobra.Command {
1617
listCmd(dockerCli),
1718
rmCmd(),
1819
tagCmd(),
19-
inspectCmd(dockerCli),
20-
renderCmd(dockerCli),
20+
inspectCmd(dockerCli, installerContext),
21+
renderCmd(dockerCli, installerContext),
2122
)
2223

2324
return cmd

internal/commands/image/inspect.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@ import (
55
"io/ioutil"
66
"os"
77

8-
"github.com/docker/app/internal/cliopts"
9-
108
"github.com/deislabs/cnab-go/action"
119
"github.com/docker/app/internal"
10+
"github.com/docker/app/internal/cliopts"
1211
"github.com/docker/app/internal/cnab"
1312
"github.com/docker/app/internal/inspect"
1413
appstore "github.com/docker/app/internal/store"
@@ -25,7 +24,6 @@ const inspectExample = `- $ docker app image inspect myapp
2524

2625
type inspectOptions struct {
2726
pretty bool
28-
cliopts.InstallerContextOptions
2927
}
3028

3129
func muteDockerCli(dockerCli command.Cli) func() {
@@ -37,24 +35,23 @@ func muteDockerCli(dockerCli command.Cli) func() {
3735
}
3836
}
3937

40-
func inspectCmd(dockerCli command.Cli) *cobra.Command {
38+
func inspectCmd(dockerCli command.Cli, installerContext *cliopts.InstallerContextOptions) *cobra.Command {
4139
var opts inspectOptions
4240
cmd := &cobra.Command{
4341
Use: "inspect [OPTIONS] APP_IMAGE",
4442
Short: "Display detailed information about an App image",
4543
Example: inspectExample,
4644
Args: cli.ExactArgs(1),
4745
RunE: func(cmd *cobra.Command, args []string) error {
48-
return runInspect(dockerCli, args[0], opts)
46+
return runInspect(dockerCli, args[0], opts, installerContext)
4947
},
5048
}
51-
opts.InstallerContextOptions.AddFlags(cmd.Flags())
5249
cmd.Flags().BoolVar(&opts.pretty, "pretty", false, "Print the information in a human friendly format")
5350

5451
return cmd
5552
}
5653

57-
func runInspect(dockerCli command.Cli, appname string, opts inspectOptions) error {
54+
func runInspect(dockerCli command.Cli, appname string, opts inspectOptions, installerContext *cliopts.InstallerContextOptions) error {
5855
defer muteDockerCli(dockerCli)()
5956
s, err := appstore.NewApplicationStore(config.Dir())
6057
if err != nil {
@@ -81,7 +78,7 @@ func runInspect(dockerCli command.Cli, appname string, opts inspectOptions) erro
8178
}
8279

8380
if _, hasAction := installation.Bundle.Actions[internal.ActionInspectName]; hasAction {
84-
driverImpl, errBuf, err := cnab.SetupDriver(installation, dockerCli, opts.InstallerContextOptions, os.Stdout)
81+
driverImpl, errBuf, err := cnab.SetupDriver(installation, dockerCli, installerContext, os.Stdout)
8582
if err != nil {
8683
return err
8784
}

internal/commands/image/render.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,11 @@ import (
2323

2424
type renderOptions struct {
2525
cliopts.ParametersOptions
26-
cliopts.InstallerContextOptions
2726
formatDriver string
2827
renderOutput string
2928
}
3029

31-
func renderCmd(dockerCli command.Cli) *cobra.Command {
30+
func renderCmd(dockerCli command.Cli, installerContext *cliopts.InstallerContextOptions) *cobra.Command {
3231
var opts renderOptions
3332
cmd := &cobra.Command{
3433
Use: "render [OPTIONS] APP_IMAGE",
@@ -37,18 +36,17 @@ func renderCmd(dockerCli command.Cli) *cobra.Command {
3736
Args: cli.ExactArgs(1),
3837
Hidden: true,
3938
RunE: func(cmd *cobra.Command, args []string) error {
40-
return runRender(dockerCli, args[0], opts)
39+
return runRender(dockerCli, args[0], opts, installerContext)
4140
},
4241
}
4342
opts.ParametersOptions.AddFlags(cmd.Flags())
44-
opts.InstallerContextOptions.AddFlags(cmd.Flags())
4543
cmd.Flags().StringVarP(&opts.renderOutput, "output", "o", "-", "Output file")
4644
cmd.Flags().StringVar(&opts.formatDriver, "formatter", "yaml", "Configure the output format (yaml|json)")
4745

4846
return cmd
4947
}
5048

51-
func runRender(dockerCli command.Cli, appname string, opts renderOptions) error {
49+
func runRender(dockerCli command.Cli, appname string, opts renderOptions, installerContext *cliopts.InstallerContextOptions) error {
5250
defer muteDockerCli(dockerCli)()
5351

5452
var w io.Writer = os.Stdout
@@ -66,7 +64,7 @@ func runRender(dockerCli command.Cli, appname string, opts renderOptions) error
6664
return nil
6765
}
6866

69-
action, installation, errBuf, err := prepareCustomAction(internal.ActionRenderName, dockerCli, appname, w, opts)
67+
action, installation, errBuf, err := prepareCustomAction(internal.ActionRenderName, dockerCli, appname, w, opts, installerContext)
7068
if err != nil {
7169
return err
7270
}
@@ -78,7 +76,7 @@ func runRender(dockerCli command.Cli, appname string, opts renderOptions) error
7876
return nil
7977
}
8078

81-
func prepareCustomAction(actionName string, dockerCli command.Cli, appname string, stdout io.Writer, opts renderOptions) (*action.RunCustom, *appstore.Installation, *bytes.Buffer, error) {
79+
func prepareCustomAction(actionName string, dockerCli command.Cli, appname string, stdout io.Writer, opts renderOptions, installerContext *cliopts.InstallerContextOptions) (*action.RunCustom, *appstore.Installation, *bytes.Buffer, error) {
8280
s, err := appstore.NewApplicationStore(config.Dir())
8381
if err != nil {
8482
return nil, nil, nil, err
@@ -103,7 +101,7 @@ func prepareCustomAction(actionName string, dockerCli command.Cli, appname strin
103101
return nil, nil, nil, err
104102
}
105103

106-
driverImpl, errBuf, err := cnab.SetupDriver(installation, dockerCli, opts.InstallerContextOptions, stdout)
104+
driverImpl, errBuf, err := cnab.SetupDriver(installation, dockerCli, installerContext, stdout)
107105
if err != nil {
108106
return nil, nil, nil, err
109107
}

internal/commands/inspect.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,28 +22,26 @@ const inspectExample = `- $ docker app inspect my-running-app
2222

2323
type inspectOptions struct {
2424
credentialOptions
25-
cliopts.InstallerContextOptions
2625
pretty bool
2726
}
2827

29-
func inspectCmd(dockerCli command.Cli) *cobra.Command {
28+
func inspectCmd(dockerCli command.Cli, installerContext *cliopts.InstallerContextOptions) *cobra.Command {
3029
var opts inspectOptions
3130
cmd := &cobra.Command{
3231
Use: "inspect [OPTIONS] RUNNING_APP",
3332
Short: "Shows status, metadata, parameters and the list of services of a running App",
3433
Example: inspectExample,
3534
Args: cli.ExactArgs(1),
3635
RunE: func(cmd *cobra.Command, args []string) error {
37-
return runInspect(dockerCli, firstOrEmpty(args), opts)
36+
return runInspect(dockerCli, args[0], opts, installerContext)
3837
},
3938
}
4039
cmd.Flags().BoolVar(&opts.pretty, "pretty", false, "Pretty print the output")
4140
opts.credentialOptions.addFlags(cmd.Flags())
42-
opts.InstallerContextOptions.AddFlags(cmd.Flags())
4341
return cmd
4442
}
4543

46-
func runInspect(dockerCli command.Cli, appName string, inspectOptions inspectOptions) error {
44+
func runInspect(dockerCli command.Cli, appName string, inspectOptions inspectOptions, installerContext *cliopts.InstallerContextOptions) error {
4745
defer muteDockerCli(dockerCli)()
4846
_, installationStore, credentialStore, err := prepareStores(dockerCli.CurrentContext())
4947
if err != nil {
@@ -60,7 +58,7 @@ func runInspect(dockerCli command.Cli, appName string, inspectOptions inspectOpt
6058
}
6159

6260
var buf bytes.Buffer
63-
driverImpl, errBuf, err := cnab.SetupDriver(installation, dockerCli, inspectOptions.InstallerContextOptions, &buf)
61+
driverImpl, errBuf, err := cnab.SetupDriver(installation, dockerCli, installerContext, &buf)
6462
if err != nil {
6563
return err
6664
}

internal/commands/remove.go

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

7+
"github.com/docker/app/internal/cliopts"
78
"github.com/docker/app/internal/cnab"
89

910
"github.com/deislabs/cnab-go/driver"
10-
"github.com/docker/app/internal/cliopts"
1111

1212
"github.com/deislabs/cnab-go/action"
1313
"github.com/deislabs/cnab-go/credentials"
@@ -18,11 +18,10 @@ import (
1818

1919
type removeOptions struct {
2020
credentialOptions
21-
cliopts.InstallerContextOptions
2221
force bool
2322
}
2423

25-
func removeCmd(dockerCli command.Cli) *cobra.Command {
24+
func removeCmd(dockerCli command.Cli, installerContext *cliopts.InstallerContextOptions) *cobra.Command {
2625
var opts removeOptions
2726

2827
cmd := &cobra.Command{
@@ -32,17 +31,16 @@ func removeCmd(dockerCli command.Cli) *cobra.Command {
3231
Example: `$ docker app rm myrunningapp`,
3332
Args: cli.ExactArgs(1),
3433
RunE: func(cmd *cobra.Command, args []string) error {
35-
return runRemove(dockerCli, args[0], opts)
34+
return runRemove(dockerCli, args[0], opts, installerContext)
3635
},
3736
}
3837
opts.credentialOptions.addFlags(cmd.Flags())
39-
opts.InstallerContextOptions.AddFlags(cmd.Flags())
4038
cmd.Flags().BoolVar(&opts.force, "force", false, "Force the removal of a running App")
4139

4240
return cmd
4341
}
4442

45-
func runRemove(dockerCli command.Cli, installationName string, opts removeOptions) (mainErr error) {
43+
func runRemove(dockerCli command.Cli, installationName string, opts removeOptions, installerContext *cliopts.InstallerContextOptions) (mainErr error) {
4644
defer muteDockerCli(dockerCli)()
4745

4846
_, installationStore, credentialStore, err := prepareStores(dockerCli.CurrentContext())
@@ -66,7 +64,7 @@ func runRemove(dockerCli command.Cli, installationName string, opts removeOption
6664
fmt.Fprintf(os.Stderr, "deletion forced for running App %q\n", installationName)
6765
}()
6866
}
69-
driverImpl, errBuf, err := cnab.SetupDriver(installation, dockerCli, opts.InstallerContextOptions, os.Stdout)
67+
driverImpl, errBuf, err := cnab.SetupDriver(installation, dockerCli, installerContext, os.Stdout)
7068
if err != nil {
7169
return err
7270
}

internal/commands/root.go

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77

88
"github.com/deislabs/cnab-go/claim"
99
"github.com/docker/app/internal"
10+
"github.com/docker/app/internal/cliopts"
1011
"github.com/docker/app/internal/commands/build"
1112
"github.com/docker/app/internal/commands/image"
1213
"github.com/docker/app/internal/store"
@@ -17,19 +18,21 @@ import (
1718
"github.com/spf13/pflag"
1819
)
1920

20-
var (
21+
type mainOptions struct {
22+
cliopts.InstallerContextOptions
2123
showVersion bool
22-
)
24+
}
2325

2426
// NewRootCmd returns the base root command.
2527
func NewRootCmd(use string, dockerCli command.Cli) *cobra.Command {
28+
var opts mainOptions
2629
cmd := &cobra.Command{
2730
Short: "Docker App",
2831
Long: `A tool to build, share and run a Docker App`,
2932
Use: use,
3033
Annotations: map[string]string{"experimentalCLI": "true"},
3134
RunE: func(cmd *cobra.Command, args []string) error {
32-
if showVersion {
35+
if opts.showVersion {
3336
fmt.Fprintln(os.Stdout, internal.FullVersion()) //nolint:errcheck
3437
return nil
3538
}
@@ -41,25 +44,27 @@ func NewRootCmd(use string, dockerCli command.Cli) *cobra.Command {
4144
return nil
4245
},
4346
}
44-
addCommands(cmd, dockerCli)
47+
addCommands(cmd, dockerCli, &opts.InstallerContextOptions)
48+
49+
cmd.Flags().BoolVar(&opts.showVersion, "version", false, "Print version information")
50+
opts.InstallerContextOptions.AddFlags(cmd.Flags())
4551

46-
cmd.Flags().BoolVar(&showVersion, "version", false, "Print version information")
4752
return cmd
4853
}
4954

50-
func addCommands(cmd *cobra.Command, dockerCli command.Cli) {
55+
func addCommands(cmd *cobra.Command, dockerCli command.Cli, installerContext *cliopts.InstallerContextOptions) {
5156
cmd.AddCommand(
52-
runCmd(dockerCli),
53-
updateCmd(dockerCli),
54-
removeCmd(dockerCli),
55-
listCmd(dockerCli),
57+
runCmd(dockerCli, installerContext),
58+
updateCmd(dockerCli, installerContext),
59+
removeCmd(dockerCli, installerContext),
60+
listCmd(dockerCli, installerContext),
5661
initCmd(dockerCli),
5762
validateCmd(),
5863
pushCmd(dockerCli),
5964
pullCmd(dockerCli),
60-
image.Cmd(dockerCli),
65+
image.Cmd(dockerCli, installerContext),
6166
build.Cmd(dockerCli),
62-
inspectCmd(dockerCli),
67+
inspectCmd(dockerCli, installerContext),
6368
)
6469

6570
if !dockerCli.ClientInfo().HasExperimental {

0 commit comments

Comments
 (0)