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

Commit eca2252

Browse files
author
Ian Campbell
committed
push: autodetect when asked to push a bundle
... instead of requiring a separate option, this follows the pattern of `install` et al. Signed-off-by: Ian Campbell <[email protected]>
1 parent 11955fe commit eca2252

File tree

2 files changed

+24
-32
lines changed

2 files changed

+24
-32
lines changed

internal/commands/push.go

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

1212
"github.com/containerd/containerd/platforms"
1313
"github.com/deislabs/cnab-go/bundle"
14-
"github.com/docker/app/internal/packager"
1514
"github.com/docker/app/types/metadata"
1615
"github.com/docker/cli/cli"
1716
"github.com/docker/cli/cli/command"
@@ -29,7 +28,6 @@ import (
2928
type pushOptions struct {
3029
registry registryOptions
3130
tag string
32-
bundle string
3331
platforms []string
3432
}
3533

@@ -46,7 +44,6 @@ func pushCmd(dockerCli command.Cli) *cobra.Command {
4644
}
4745
flags := cmd.Flags()
4846
flags.StringVarP(&opts.tag, "tag", "t", "", "Target registry reference (default: <name>:<version> from metadata)")
49-
flags.StringVar(&opts.bundle, "bundle", "", "Push a specific bundle")
5047
flags.StringSliceVar(&opts.platforms, "platform", nil, "For multi-arch service images, only push the specified platforms")
5148
opts.registry.addFlags(flags)
5249
return cmd
@@ -55,37 +52,20 @@ func pushCmd(dockerCli command.Cli) *cobra.Command {
5552
func runPush(dockerCli command.Cli, name string, opts pushOptions) error {
5653
defer muteDockerCli(dockerCli)()
5754

58-
var (
59-
bndl *bundle.Bundle
60-
meta metadata.AppMetadata
61-
)
62-
if opts.bundle == "" {
63-
app, err := packager.Extract(name)
64-
if err != nil {
65-
return err
66-
}
67-
defer app.Cleanup()
68-
if bndl, err = makeBundleFromApp(dockerCli, app, nil); err != nil {
69-
return err
70-
}
71-
meta = app.Metadata()
72-
} else {
73-
if name != "" {
74-
fmt.Fprintf(os.Stderr, "WARNING: ignoring dockerapp at %q, pushing app directly from %q\n", name, opts.bundle)
75-
}
76-
r, err := os.Open(opts.bundle)
77-
if err != nil {
78-
return err
79-
}
80-
if b, err := bundle.ParseReader(r); err == nil {
81-
bndl = &b // TODO: PR to change return type of ParseReader
82-
} else {
83-
return err
84-
}
85-
meta = metadata.FromBundle(bndl)
55+
bundleStore, err := prepareBundleStore()
56+
if err != nil {
57+
return err
58+
}
59+
60+
bndl, _, err := resolveBundle(dockerCli, bundleStore, name, false, nil)
61+
if err != nil {
62+
return err
63+
}
64+
if err := bndl.Validate(); err != nil {
65+
return err
8666
}
8767

88-
retag, err := shouldRetagInvocationImage(meta, bndl, opts.tag)
68+
retag, err := shouldRetagInvocationImage(metadata.FromBundle(bndl), bndl, opts.tag)
8969
if err != nil {
9070
return err
9171
}

internal/commands/root.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,18 @@ func prepareStores(targetContext string) (store.BundleStore, store.InstallationS
7878
return bundleStore, installationStore, credentialStore, nil
7979
}
8080

81+
func prepareBundleStore() (store.BundleStore, error) {
82+
appstore, err := store.NewApplicationStore(config.Dir())
83+
if err != nil {
84+
return nil, err
85+
}
86+
bundleStore, err := appstore.BundleStore()
87+
if err != nil {
88+
return nil, err
89+
}
90+
return bundleStore, nil
91+
}
92+
8193
type parametersOptions struct {
8294
parametersFiles []string
8395
overrides []string

0 commit comments

Comments
 (0)