github.com/docker/app@v0.9.1-beta3.0.20210611140623-a48f773ab002/internal/commands/pull.go (about) 1 package commands 2 3 import ( 4 "fmt" 5 "os" 6 7 "github.com/docker/app/internal/cnab" 8 "github.com/docker/app/internal/packager" 9 "github.com/docker/app/internal/store" 10 "github.com/docker/cli/cli" 11 "github.com/docker/cli/cli/command" 12 "github.com/docker/cli/cli/config" 13 "github.com/docker/distribution/reference" 14 "github.com/pkg/errors" 15 "github.com/spf13/cobra" 16 ) 17 18 func pullCmd(dockerCli command.Cli) *cobra.Command { 19 cmd := &cobra.Command{ 20 Use: "pull APP_IMAGE", 21 Short: "Pull an App image from a registry", 22 Example: `$ docker app pull myrepo/myapp:0.1.0`, 23 Args: cli.ExactArgs(1), 24 RunE: func(cmd *cobra.Command, args []string) error { 25 return runPull(dockerCli, args[0]) 26 }, 27 } 28 return cmd 29 } 30 31 func runPull(dockerCli command.Cli, name string) error { 32 appstore, err := store.NewApplicationStore(config.Dir()) 33 if err != nil { 34 return err 35 } 36 imageStore, err := appstore.ImageStore() 37 if err != nil { 38 return err 39 } 40 ref, err := reference.ParseNormalizedNamed(name) 41 if err != nil { 42 return errors.Wrap(err, name) 43 } 44 tagRef := reference.TagNameOnly(ref) 45 46 bndl, err := cnab.PullBundle(dockerCli, imageStore, tagRef) 47 if err != nil { 48 return errors.Wrap(err, name) 49 } 50 if err := packager.CheckAppVersion(dockerCli.Err(), bndl.Bundle); err != nil { 51 return err 52 } 53 fmt.Fprintf(os.Stdout, "Successfully pulled %q (%s) from %s\n", bndl.Name, bndl.Version, ref.String()) 54 55 return nil 56 }