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

Commit e244826

Browse files
authored
Merge pull request #769 from silvin-lubecki/warning-invoc-version
Warn user if the app bundle version differs with the current app version
2 parents e18898a + 12e6785 commit e244826

File tree

12 files changed

+109
-58
lines changed

12 files changed

+109
-58
lines changed

internal/commands/image/inspect.go

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

8+
"github.com/docker/app/internal/packager"
9+
810
"github.com/deislabs/cnab-go/action"
911
"github.com/docker/app/internal"
1012
"github.com/docker/app/internal/cliopts"
@@ -52,7 +54,6 @@ func inspectCmd(dockerCli command.Cli, installerContext *cliopts.InstallerContex
5254
}
5355

5456
func runInspect(dockerCli command.Cli, appname string, opts inspectOptions, installerContext *cliopts.InstallerContextOptions) error {
55-
defer muteDockerCli(dockerCli)()
5657
s, err := appstore.NewApplicationStore(config.Dir())
5758
if err != nil {
5859
return err
@@ -66,6 +67,9 @@ func runInspect(dockerCli command.Cli, appname string, opts inspectOptions, inst
6667
if err != nil {
6768
return err
6869
}
70+
if err := packager.CheckAppVersion(dockerCli.Err(), bndl.Bundle); err != nil {
71+
return err
72+
}
6973

7074
format := "json"
7175
if opts.pretty {
@@ -77,6 +81,7 @@ func runInspect(dockerCli command.Cli, appname string, opts inspectOptions, inst
7781
return err
7882
}
7983

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

internal/commands/image/render.go

Lines changed: 28 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
package image
22

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

9-
"github.com/deislabs/cnab-go/driver"
10-
118
"github.com/deislabs/cnab-go/action"
9+
"github.com/deislabs/cnab-go/driver"
1210
"github.com/docker/app/internal"
1311
bdl "github.com/docker/app/internal/bundle"
1412
"github.com/docker/app/internal/cliopts"
1513
"github.com/docker/app/internal/cnab"
14+
"github.com/docker/app/internal/packager"
1615
appstore "github.com/docker/app/internal/store"
1716
"github.com/docker/cli/cli"
1817
"github.com/docker/cli/cli/command"
@@ -47,8 +46,6 @@ func renderCmd(dockerCli command.Cli, installerContext *cliopts.InstallerContext
4746
}
4847

4948
func runRender(dockerCli command.Cli, appname string, opts renderOptions, installerContext *cliopts.InstallerContextOptions) error {
50-
defer muteDockerCli(dockerCli)()
51-
5249
var w io.Writer = os.Stdout
5350
if opts.renderOutput != "-" {
5451
f, err := os.Create(opts.renderOutput)
@@ -59,61 +56,51 @@ func runRender(dockerCli command.Cli, appname string, opts renderOptions, instal
5956
w = f
6057
}
6158

62-
cfgFunc := func(op *driver.Operation) error {
63-
op.Out = w
64-
return nil
65-
}
66-
67-
action, installation, errBuf, err := prepareCustomAction(internal.ActionRenderName, dockerCli, appname, w, opts, installerContext)
68-
if err != nil {
69-
return err
70-
}
71-
installation.Parameters[internal.ParameterRenderFormatName] = opts.formatDriver
72-
73-
if err := action.Run(&installation.Claim, nil, cfgFunc, cnab.WithRelocationMap(installation)); err != nil {
74-
return fmt.Errorf("render failed: %s\n%s", err, errBuf)
75-
}
76-
return nil
77-
}
78-
79-
func prepareCustomAction(actionName string,
80-
dockerCli command.Cli,
81-
appname string,
82-
stdout io.Writer,
83-
opts renderOptions,
84-
installerContext *cliopts.InstallerContextOptions) (*action.RunCustom, *appstore.Installation, *bytes.Buffer, error) {
85-
8659
s, err := appstore.NewApplicationStore(config.Dir())
8760
if err != nil {
88-
return nil, nil, nil, err
61+
return err
8962
}
9063
bundleStore, err := s.BundleStore()
9164
if err != nil {
92-
return nil, nil, nil, err
65+
return err
9366
}
94-
bundle, ref, err := cnab.GetBundle(dockerCli, bundleStore, appname)
67+
bndl, ref, err := cnab.GetBundle(dockerCli, bundleStore, appname)
9568
if err != nil {
96-
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)
70+
}
71+
if err := packager.CheckAppVersion(dockerCli.Err(), bndl.Bundle); err != nil {
72+
return err
9773
}
98-
installation, err := appstore.NewInstallation("custom-action", ref.String(), bundle)
74+
installation, err := appstore.NewInstallation("custom-action", ref.String(), bndl)
9975
if err != nil {
100-
return nil, nil, nil, err
76+
return err
10177
}
10278

10379
if err := bdl.MergeBundleParameters(installation,
10480
bdl.WithFileParameters(opts.ParametersFiles),
10581
bdl.WithCommandLineParameters(opts.Overrides),
10682
); err != nil {
107-
return nil, nil, nil, err
83+
return err
10884
}
10985

110-
driverImpl, errBuf, err := cnab.SetupDriver(installation, dockerCli, installerContext, stdout)
86+
defer muteDockerCli(dockerCli)()
87+
driverImpl, errBuf, err := cnab.SetupDriver(installation, dockerCli, installerContext, w)
11188
if err != nil {
112-
return nil, nil, nil, err
89+
return err
11390
}
114-
a := &action.RunCustom{
115-
Action: actionName,
91+
action := &action.RunCustom{
92+
Action: internal.ActionRenderName,
11693
Driver: driverImpl,
11794
}
118-
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
119106
}

internal/commands/inspect.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"github.com/docker/app/internal/cliopts"
1313
"github.com/docker/app/internal/cnab"
1414
"github.com/docker/app/internal/inspect"
15+
"github.com/docker/app/internal/packager"
1516
"github.com/docker/cli/cli"
1617
"github.com/docker/cli/cli/command"
1718
"github.com/spf13/cobra"
@@ -42,7 +43,6 @@ func inspectCmd(dockerCli command.Cli, installerContext *cliopts.InstallerContex
4243
}
4344

4445
func runInspect(dockerCli command.Cli, appName string, inspectOptions inspectOptions, installerContext *cliopts.InstallerContextOptions) error {
45-
defer muteDockerCli(dockerCli)()
4646
_, installationStore, credentialStore, err := prepareStores(dockerCli.CurrentContext())
4747
if err != nil {
4848
return err
@@ -51,12 +51,15 @@ func runInspect(dockerCli command.Cli, appName string, inspectOptions inspectOpt
5151
if err != nil {
5252
return err
5353
}
54-
54+
if err := packager.CheckAppVersion(dockerCli.Err(), installation.Bundle); err != nil {
55+
return err
56+
}
5557
creds, err := prepareCredentialSet(installation.Bundle, inspectOptions.CredentialSetOpts(dockerCli, credentialStore)...)
5658
if err != nil {
5759
return err
5860
}
5961

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

internal/commands/pull.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"os"
66

77
"github.com/docker/app/internal/cnab"
8+
"github.com/docker/app/internal/packager"
89
"github.com/docker/app/internal/store"
910
"github.com/docker/cli/cli"
1011
"github.com/docker/cli/cli/command"
@@ -46,7 +47,9 @@ func runPull(dockerCli command.Cli, name string) error {
4647
if err != nil {
4748
return errors.Wrap(err, name)
4849
}
49-
50+
if err := packager.CheckAppVersion(dockerCli.Err(), bndl.Bundle); err != nil {
51+
return err
52+
}
5053
fmt.Fprintf(os.Stdout, "Successfully pulled %q (%s) from %s\n", bndl.Name, bndl.Version, ref.String())
5154

5255
return nil

internal/commands/remove.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66

77
"github.com/docker/app/internal/cliopts"
88
"github.com/docker/app/internal/cnab"
9+
"github.com/docker/app/internal/packager"
910

1011
"github.com/deislabs/cnab-go/driver"
1112

@@ -41,8 +42,6 @@ func removeCmd(dockerCli command.Cli, installerContext *cliopts.InstallerContext
4142
}
4243

4344
func runRemove(dockerCli command.Cli, installationName string, opts removeOptions, installerContext *cliopts.InstallerContextOptions) (mainErr error) {
44-
defer muteDockerCli(dockerCli)()
45-
4645
_, installationStore, credentialStore, err := prepareStores(dockerCli.CurrentContext())
4746
if err != nil {
4847
return err
@@ -52,6 +51,10 @@ func runRemove(dockerCli command.Cli, installationName string, opts removeOption
5251
if err != nil {
5352
return err
5453
}
54+
if err := packager.CheckAppVersion(dockerCli.Err(), installation.Bundle); err != nil {
55+
return err
56+
}
57+
5558
if opts.force {
5659
defer func() {
5760
if mainErr == nil {
@@ -64,6 +67,8 @@ func runRemove(dockerCli command.Cli, installationName string, opts removeOption
6467
fmt.Fprintf(os.Stderr, "deletion forced for running App %q\n", installationName)
6568
}()
6669
}
70+
71+
defer muteDockerCli(dockerCli)()
6772
driverImpl, errBuf, err := cnab.SetupDriver(installation, dockerCli, installerContext, os.Stdout)
6873
if err != nil {
6974
return err

internal/commands/run.go

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

7+
"github.com/docker/app/internal/packager"
8+
79
"github.com/docker/app/internal/relocated"
810

911
"github.com/deislabs/cnab-go/driver"
@@ -98,6 +100,9 @@ func runDockerApp(dockerCli command.Cli, appname string, opts runOptions, instal
98100
}
99101

100102
func runBundle(dockerCli command.Cli, bndl *relocated.Bundle, opts runOptions, installerContext *cliopts.InstallerContextOptions, ref string) (err error) {
103+
if err := packager.CheckAppVersion(dockerCli.Err(), bndl.Bundle); err != nil {
104+
return err
105+
}
101106
_, installationStore, credentialStore, err := prepareStores(dockerCli.CurrentContext())
102107
if err != nil {
103108
return err

internal/commands/update.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/docker/app/internal/bundle"
1212
"github.com/docker/app/internal/cliopts"
1313
"github.com/docker/app/internal/cnab"
14+
"github.com/docker/app/internal/packager"
1415
"github.com/docker/cli/cli/command"
1516
"github.com/spf13/cobra"
1617
)
@@ -40,8 +41,6 @@ func updateCmd(dockerCli command.Cli, installerContext *cliopts.InstallerContext
4041
}
4142

4243
func runUpdate(dockerCli command.Cli, installationName string, opts updateOptions, installerContext *cliopts.InstallerContextOptions) error {
43-
defer muteDockerCli(dockerCli)()
44-
4544
bundleStore, installationStore, credentialStore, err := prepareStores(dockerCli.CurrentContext())
4645
if err != nil {
4746
return err
@@ -63,6 +62,10 @@ func runUpdate(dockerCli command.Cli, installationName string, opts updateOption
6362
}
6463
installation.Bundle = b.Bundle
6564
}
65+
if err := packager.CheckAppVersion(dockerCli.Err(), installation.Bundle); err != nil {
66+
return err
67+
}
68+
6669
if err := bundle.MergeBundleParameters(installation,
6770
bundle.WithFileParameters(opts.ParametersFiles),
6871
bundle.WithCommandLineParameters(opts.Overrides),
@@ -71,6 +74,7 @@ func runUpdate(dockerCli command.Cli, installationName string, opts updateOption
7174
return err
7275
}
7376

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

internal/packager/cnab.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ func ToCNAB(app *types.App, invocationImageName string) (*bundle.Bundle, error)
172172
SchemaVersion: CNABVersion1_0_0,
173173
Custom: map[string]interface{}{
174174
internal.CustomDockerAppName: DockerAppCustom{
175-
Version: DockerAppCustomVersionCurrent,
175+
Version: DockerAppPayloadVersionCurrent,
176176
Payload: payload,
177177
},
178178
},

internal/packager/cnab_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import (
66
"regexp"
77
"testing"
88

9+
"github.com/docker/app/internal"
10+
911
"github.com/docker/app/types"
1012
"gotest.tools/assert"
1113
"gotest.tools/golden"
@@ -20,7 +22,7 @@ func TestToCNAB(t *testing.T) {
2022
assert.NilError(t, err)
2123
s := golden.Get(t, "bundle-json.golden")
2224
expectedLiteral := regexp.QuoteMeta(string(s))
23-
expected := fmt.Sprintf(expectedLiteral, DockerAppCustomVersionCurrent, `\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d+Z`)
25+
expected := fmt.Sprintf(expectedLiteral, DockerAppPayloadVersionCurrent, internal.Version, `\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d+Z`)
2426
matches, err := regexp.Match(expected, actualJSON)
2527
assert.NilError(t, err)
2628
assert.Assert(t, matches)

0 commit comments

Comments
 (0)