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

Commit 12e6785

Browse files
Fix warning message not shown properly as the docker cli was muted
Signed-off-by: Silvin Lubecki <[email protected]>
1 parent 65b5f8c commit 12e6785

File tree

5 files changed

+29
-48
lines changed

5 files changed

+29
-48
lines changed

internal/commands/image/inspect.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ func inspectCmd(dockerCli command.Cli, installerContext *cliopts.InstallerContex
5454
}
5555

5656
func runInspect(dockerCli command.Cli, appname string, opts inspectOptions, installerContext *cliopts.InstallerContextOptions) error {
57-
defer muteDockerCli(dockerCli)()
5857
s, err := appstore.NewApplicationStore(config.Dir())
5958
if err != nil {
6059
return err
@@ -82,6 +81,7 @@ func runInspect(dockerCli command.Cli, appname string, opts inspectOptions, inst
8281
return err
8382
}
8483

84+
defer muteDockerCli(dockerCli)()
8585
if _, hasAction := installation.Bundle.Actions[internal.ActionInspectName]; hasAction {
8686
driverImpl, errBuf, err := cnab.SetupDriver(installation, dockerCli, installerContext, os.Stdout)
8787
if err != nil {

internal/commands/image/render.go

Lines changed: 24 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
11
package image
22

33
import (
4-
"bytes"
54
"fmt"
65
"io"
76
"os"
87

9-
"github.com/docker/app/internal/packager"
10-
11-
"github.com/deislabs/cnab-go/driver"
12-
138
"github.com/deislabs/cnab-go/action"
9+
"github.com/deislabs/cnab-go/driver"
1410
"github.com/docker/app/internal"
1511
bdl "github.com/docker/app/internal/bundle"
1612
"github.com/docker/app/internal/cliopts"
1713
"github.com/docker/app/internal/cnab"
14+
"github.com/docker/app/internal/packager"
1815
appstore "github.com/docker/app/internal/store"
1916
"github.com/docker/cli/cli"
2017
"github.com/docker/cli/cli/command"
@@ -49,8 +46,6 @@ func renderCmd(dockerCli command.Cli, installerContext *cliopts.InstallerContext
4946
}
5047

5148
func runRender(dockerCli command.Cli, appname string, opts renderOptions, installerContext *cliopts.InstallerContextOptions) error {
52-
defer muteDockerCli(dockerCli)()
53-
5449
var w io.Writer = os.Stdout
5550
if opts.renderOutput != "-" {
5651
f, err := os.Create(opts.renderOutput)
@@ -61,64 +56,51 @@ func runRender(dockerCli command.Cli, appname string, opts renderOptions, instal
6156
w = f
6257
}
6358

64-
cfgFunc := func(op *driver.Operation) error {
65-
op.Out = w
66-
return nil
67-
}
68-
69-
action, installation, errBuf, err := prepareCustomAction(internal.ActionRenderName, dockerCli, appname, w, opts, installerContext)
70-
if err != nil {
71-
return err
72-
}
73-
installation.Parameters[internal.ParameterRenderFormatName] = opts.formatDriver
74-
75-
if err := action.Run(&installation.Claim, nil, cfgFunc, cnab.WithRelocationMap(installation)); err != nil {
76-
return fmt.Errorf("render failed: %s\n%s", err, errBuf)
77-
}
78-
return nil
79-
}
80-
81-
func prepareCustomAction(actionName string,
82-
dockerCli command.Cli,
83-
appname string,
84-
stdout io.Writer,
85-
opts renderOptions,
86-
installerContext *cliopts.InstallerContextOptions) (*action.RunCustom, *appstore.Installation, *bytes.Buffer, error) {
87-
8859
s, err := appstore.NewApplicationStore(config.Dir())
8960
if err != nil {
90-
return nil, nil, nil, err
61+
return err
9162
}
9263
bundleStore, err := s.BundleStore()
9364
if err != nil {
94-
return nil, nil, nil, err
65+
return err
9566
}
9667
bndl, ref, err := cnab.GetBundle(dockerCli, bundleStore, appname)
9768
if err != nil {
98-
return nil, nil, nil, errors.Wrapf(err, "could not render %q: no such App image", appname)
69+
return errors.Wrapf(err, "could not render %q: no such App image", appname)
9970
}
10071
if err := packager.CheckAppVersion(dockerCli.Err(), bndl.Bundle); err != nil {
101-
return nil, nil, nil, err
72+
return err
10273
}
10374
installation, err := appstore.NewInstallation("custom-action", ref.String(), bndl)
10475
if err != nil {
105-
return nil, nil, nil, err
76+
return err
10677
}
10778

10879
if err := bdl.MergeBundleParameters(installation,
10980
bdl.WithFileParameters(opts.ParametersFiles),
11081
bdl.WithCommandLineParameters(opts.Overrides),
11182
); err != nil {
112-
return nil, nil, nil, err
83+
return err
11384
}
11485

115-
driverImpl, errBuf, err := cnab.SetupDriver(installation, dockerCli, installerContext, stdout)
86+
defer muteDockerCli(dockerCli)()
87+
driverImpl, errBuf, err := cnab.SetupDriver(installation, dockerCli, installerContext, w)
11688
if err != nil {
117-
return nil, nil, nil, err
89+
return err
11890
}
119-
a := &action.RunCustom{
120-
Action: actionName,
91+
action := &action.RunCustom{
92+
Action: internal.ActionRenderName,
12193
Driver: driverImpl,
12294
}
123-
return a, installation, errBuf, nil
95+
installation.Parameters[internal.ParameterRenderFormatName] = opts.formatDriver
96+
97+
cfgFunc := func(op *driver.Operation) error {
98+
op.Out = w
99+
return nil
100+
}
101+
102+
if err := action.Run(&installation.Claim, nil, cfgFunc, cnab.WithRelocationMap(installation)); err != nil {
103+
return fmt.Errorf("render failed: %s\n%s", err, errBuf)
104+
}
105+
return nil
124106
}

internal/commands/inspect.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ func inspectCmd(dockerCli command.Cli, installerContext *cliopts.InstallerContex
4343
}
4444

4545
func runInspect(dockerCli command.Cli, appName string, inspectOptions inspectOptions, installerContext *cliopts.InstallerContextOptions) error {
46-
defer muteDockerCli(dockerCli)()
4746
_, installationStore, credentialStore, err := prepareStores(dockerCli.CurrentContext())
4847
if err != nil {
4948
return err
@@ -60,6 +59,7 @@ func runInspect(dockerCli command.Cli, appName string, inspectOptions inspectOpt
6059
return err
6160
}
6261

62+
defer muteDockerCli(dockerCli)()
6363
var buf bytes.Buffer
6464
driverImpl, errBuf, err := cnab.SetupDriver(installation, dockerCli, installerContext, &buf)
6565
if err != nil {

internal/commands/remove.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ func removeCmd(dockerCli command.Cli, installerContext *cliopts.InstallerContext
4242
}
4343

4444
func runRemove(dockerCli command.Cli, installationName string, opts removeOptions, installerContext *cliopts.InstallerContextOptions) (mainErr error) {
45-
defer muteDockerCli(dockerCli)()
46-
4745
_, installationStore, credentialStore, err := prepareStores(dockerCli.CurrentContext())
4846
if err != nil {
4947
return err
@@ -69,6 +67,8 @@ func runRemove(dockerCli command.Cli, installationName string, opts removeOption
6967
fmt.Fprintf(os.Stderr, "deletion forced for running App %q\n", installationName)
7068
}()
7169
}
70+
71+
defer muteDockerCli(dockerCli)()
7272
driverImpl, errBuf, err := cnab.SetupDriver(installation, dockerCli, installerContext, os.Stdout)
7373
if err != nil {
7474
return err

internal/commands/update.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ func updateCmd(dockerCli command.Cli, installerContext *cliopts.InstallerContext
4141
}
4242

4343
func runUpdate(dockerCli command.Cli, installationName string, opts updateOptions, installerContext *cliopts.InstallerContextOptions) error {
44-
defer muteDockerCli(dockerCli)()
45-
4644
bundleStore, installationStore, credentialStore, err := prepareStores(dockerCli.CurrentContext())
4745
if err != nil {
4846
return err
@@ -76,6 +74,7 @@ func runUpdate(dockerCli command.Cli, installationName string, opts updateOption
7674
return err
7775
}
7876

77+
defer muteDockerCli(dockerCli)()
7978
driverImpl, errBuf, err := cnab.SetupDriver(installation, dockerCli, installerContext, os.Stdout)
8079
if err != nil {
8180
return err

0 commit comments

Comments
 (0)