Skip to content
This repository has been archived by the owner on Jun 13, 2021. It is now read-only.

Add services column to docker app ls command #757

Merged
merged 5 commits into from
Nov 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions e2e/commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,8 @@ func TestDockerAppLifecycle(t *testing.T) {
cmd.Command = dockerCli.Command("app", "ls")
checkContains(t, icmd.RunCmd(cmd).Assert(t, icmd.Success).Combined(),
[]string{
`RUNNING APP\s+APP NAME\s+LAST ACTION\s+RESULT\s+CREATED\s+MODIFIED\s+REFERENCE`,
fmt.Sprintf(`%s\s+simple \(1.1.0-beta1\)\s+install\s+failure\s+.+second[s]?\sago\s+.+second[s]?\sago\s+`, appName),
`RUNNING APP\s+APP NAME\s+SERVICES\s+LAST ACTION\s+RESULT\s+CREATED\s+MODIFIED\s+REFERENCE`,
fmt.Sprintf(`%s\s+simple \(1.1.0-beta1\)\s+0/3\s+install\s+failure\s+.+second[s]?\sago\s+.+second[s]?\sago\s+`, appName),
})

// Upgrading a failed installation is not allowed
Expand All @@ -344,8 +344,8 @@ func TestDockerAppLifecycle(t *testing.T) {
cmd.Command = dockerCli.Command("app", "ls")
checkContains(t, icmd.RunCmd(cmd).Assert(t, icmd.Success).Combined(),
[]string{
`RUNNING APP\s+APP NAME\s+LAST ACTION\s+RESULT\s+CREATED\s+MODIFIED\s+REFERENCE`,
fmt.Sprintf(`%s\s+simple \(1.1.0-beta1\)\s+install\s+success\s+.+second[s]?\sago\s+.+second[s]?\sago\s+`, appName),
`RUNNING APP\s+APP NAME\s+SERVICES\s+LAST ACTION\s+RESULT\s+CREATED\s+MODIFIED\s+REFERENCE`,
fmt.Sprintf(`%s\s+simple \(1.1.0-beta1\)\s+\d/3\s+install\s+success\s+.+second[s]?\sago\s+.+second[s]?\sago\s+`, appName),
})

// Installing again the same application is forbidden
Expand Down
2 changes: 1 addition & 1 deletion e2e/pushpull_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func TestPushPullInstall(t *testing.T) {
cmd.Command = dockerCli.Command("app", "ls")
checkContains(t, icmd.RunCmd(cmd).Assert(t, icmd.Success).Combined(),
[]string{
fmt.Sprintf(`%s\s+push-pull \(1.1.0-beta1\)\s+install\s+success\s+.+second[s]?\sago\s+.+second[s]?\sago\s+%s`, t.Name(), ref+tag),
fmt.Sprintf(`%s\s+push-pull \(1.1.0-beta1\)\s+\d/1\s+install\s+success\s+.+second[s]?\sago\s+.+second[s]?\sago\s+%s`, t.Name(), ref+tag),
})

// install should fail (registry is stopped)
Expand Down
4 changes: 3 additions & 1 deletion e2e/testdata/plugin-usage.golden
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ Usage: docker app [OPTIONS] COMMAND
A tool to build, share and run a Docker App

Options:
--version Print version information
--installer-context string Context on which the installer image
is ran (default "default")
--version Print version information

Management Commands:
image Manage App images
Expand Down
2 changes: 1 addition & 1 deletion internal/cnab/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func prepareDriver(dockerCli command.Cli, bindMount BindMount, stdout io.Writer)
return d, errBuf
}

func SetupDriver(installation *store2.Installation, dockerCli command.Cli, opts cliopts.InstallerContextOptions, stdout io.Writer) (driver.Driver, *bytes.Buffer, error) {
func SetupDriver(installation *store2.Installation, dockerCli command.Cli, opts *cliopts.InstallerContextOptions, stdout io.Writer) (driver.Driver, *bytes.Buffer, error) {
dockerCli, err := opts.SetInstallerContext(dockerCli)
if err != nil {
return nil, nil, err
Expand Down
7 changes: 4 additions & 3 deletions internal/commands/image/command.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package image

import (
"github.com/docker/app/internal/cliopts"
"github.com/docker/cli/cli/command"
"github.com/spf13/cobra"
)

// Cmd is the image top level command
func Cmd(dockerCli command.Cli) *cobra.Command {
func Cmd(dockerCli command.Cli, installerContext *cliopts.InstallerContextOptions) *cobra.Command {
cmd := &cobra.Command{
Short: "Manage App images",
Use: "image",
Expand All @@ -16,8 +17,8 @@ func Cmd(dockerCli command.Cli) *cobra.Command {
listCmd(dockerCli),
rmCmd(),
tagCmd(),
inspectCmd(dockerCli),
renderCmd(dockerCli),
inspectCmd(dockerCli, installerContext),
renderCmd(dockerCli, installerContext),
)

return cmd
Expand Down
13 changes: 5 additions & 8 deletions internal/commands/image/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ import (
"io/ioutil"
"os"

"github.com/docker/app/internal/cliopts"

"github.com/deislabs/cnab-go/action"
"github.com/docker/app/internal"
"github.com/docker/app/internal/cliopts"
"github.com/docker/app/internal/cnab"
"github.com/docker/app/internal/inspect"
appstore "github.com/docker/app/internal/store"
Expand All @@ -25,7 +24,6 @@ const inspectExample = `- $ docker app image inspect myapp

type inspectOptions struct {
pretty bool
cliopts.InstallerContextOptions
}

func muteDockerCli(dockerCli command.Cli) func() {
Expand All @@ -37,24 +35,23 @@ func muteDockerCli(dockerCli command.Cli) func() {
}
}

func inspectCmd(dockerCli command.Cli) *cobra.Command {
func inspectCmd(dockerCli command.Cli, installerContext *cliopts.InstallerContextOptions) *cobra.Command {
var opts inspectOptions
cmd := &cobra.Command{
Use: "inspect [OPTIONS] APP_IMAGE",
Short: "Display detailed information about an App image",
Example: inspectExample,
Args: cli.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
return runInspect(dockerCli, args[0], opts)
return runInspect(dockerCli, args[0], opts, installerContext)
},
}
opts.InstallerContextOptions.AddFlags(cmd.Flags())
cmd.Flags().BoolVar(&opts.pretty, "pretty", false, "Print the information in a human friendly format")

return cmd
}

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

if _, hasAction := installation.Bundle.Actions[internal.ActionInspectName]; hasAction {
driverImpl, errBuf, err := cnab.SetupDriver(installation, dockerCli, opts.InstallerContextOptions, os.Stdout)
driverImpl, errBuf, err := cnab.SetupDriver(installation, dockerCli, installerContext, os.Stdout)
if err != nil {
return err
}
Expand Down
20 changes: 12 additions & 8 deletions internal/commands/image/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,11 @@ import (

type renderOptions struct {
cliopts.ParametersOptions
cliopts.InstallerContextOptions
formatDriver string
renderOutput string
}

func renderCmd(dockerCli command.Cli) *cobra.Command {
func renderCmd(dockerCli command.Cli, installerContext *cliopts.InstallerContextOptions) *cobra.Command {
var opts renderOptions
cmd := &cobra.Command{
Use: "render [OPTIONS] APP_IMAGE",
Expand All @@ -37,18 +36,17 @@ func renderCmd(dockerCli command.Cli) *cobra.Command {
Args: cli.ExactArgs(1),
Hidden: true,
RunE: func(cmd *cobra.Command, args []string) error {
return runRender(dockerCli, args[0], opts)
return runRender(dockerCli, args[0], opts, installerContext)
},
}
opts.ParametersOptions.AddFlags(cmd.Flags())
opts.InstallerContextOptions.AddFlags(cmd.Flags())
cmd.Flags().StringVarP(&opts.renderOutput, "output", "o", "-", "Output file")
cmd.Flags().StringVar(&opts.formatDriver, "formatter", "yaml", "Configure the output format (yaml|json)")

return cmd
}

func runRender(dockerCli command.Cli, appname string, opts renderOptions) error {
func runRender(dockerCli command.Cli, appname string, opts renderOptions, installerContext *cliopts.InstallerContextOptions) error {
defer muteDockerCli(dockerCli)()

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

action, installation, errBuf, err := prepareCustomAction(internal.ActionRenderName, dockerCli, appname, w, opts)
action, installation, errBuf, err := prepareCustomAction(internal.ActionRenderName, dockerCli, appname, w, opts, installerContext)
if err != nil {
return err
}
Expand All @@ -78,7 +76,13 @@ func runRender(dockerCli command.Cli, appname string, opts renderOptions) error
return nil
}

func prepareCustomAction(actionName string, dockerCli command.Cli, appname string, stdout io.Writer, opts renderOptions) (*action.RunCustom, *appstore.Installation, *bytes.Buffer, error) {
func prepareCustomAction(actionName string,
dockerCli command.Cli,
appname string,
stdout io.Writer,
opts renderOptions,
installerContext *cliopts.InstallerContextOptions) (*action.RunCustom, *appstore.Installation, *bytes.Buffer, error) {

s, err := appstore.NewApplicationStore(config.Dir())
if err != nil {
return nil, nil, nil, err
Expand All @@ -103,7 +107,7 @@ func prepareCustomAction(actionName string, dockerCli command.Cli, appname strin
return nil, nil, nil, err
}

driverImpl, errBuf, err := cnab.SetupDriver(installation, dockerCli, opts.InstallerContextOptions, stdout)
driverImpl, errBuf, err := cnab.SetupDriver(installation, dockerCli, installerContext, stdout)
if err != nil {
return nil, nil, nil, err
}
Expand Down
10 changes: 4 additions & 6 deletions internal/commands/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,26 @@ const inspectExample = `- $ docker app inspect my-running-app

type inspectOptions struct {
credentialOptions
cliopts.InstallerContextOptions
pretty bool
}

func inspectCmd(dockerCli command.Cli) *cobra.Command {
func inspectCmd(dockerCli command.Cli, installerContext *cliopts.InstallerContextOptions) *cobra.Command {
var opts inspectOptions
cmd := &cobra.Command{
Use: "inspect [OPTIONS] RUNNING_APP",
Short: "Shows status, metadata, parameters and the list of services of a running App",
Example: inspectExample,
Args: cli.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
return runInspect(dockerCli, firstOrEmpty(args), opts)
return runInspect(dockerCli, args[0], opts, installerContext)
},
}
cmd.Flags().BoolVar(&opts.pretty, "pretty", false, "Pretty print the output")
opts.credentialOptions.addFlags(cmd.Flags())
opts.InstallerContextOptions.AddFlags(cmd.Flags())
return cmd
}

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

var buf bytes.Buffer
driverImpl, errBuf, err := cnab.SetupDriver(installation, dockerCli, inspectOptions.InstallerContextOptions, &buf)
driverImpl, errBuf, err := cnab.SetupDriver(installation, dockerCli, installerContext, &buf)
if err != nil {
return err
}
Expand Down
Loading