github.com/jcarley/cli@v0.0.0-20180201210820-966d90434c30/commands/images/contract.go (about) 1 package images 2 3 import ( 4 "github.com/Sirupsen/logrus" 5 "github.com/daticahealth/cli/commands/environments" 6 "github.com/daticahealth/cli/commands/images/tags" 7 "github.com/daticahealth/cli/commands/images/targets" 8 "github.com/daticahealth/cli/config" 9 "github.com/daticahealth/cli/lib/auth" 10 "github.com/daticahealth/cli/lib/images" 11 "github.com/daticahealth/cli/lib/prompts" 12 "github.com/daticahealth/cli/models" 13 "github.com/jault3/mow.cli" 14 ) 15 16 // Cmd is the contract between the user and the CLI. This specifies the command 17 // name, arguments, and required/optional arguments and flags for the command. 18 var Cmd = models.Command{ 19 Name: "images", 20 ShortHelp: "Operations for working with images", 21 LongHelp: "<code>images</code> allows interactions with container images and tags. " + 22 "This command cannot be run directly, but has subcommands.", 23 CmdFunc: func(settings *models.Settings) func(cmd *cli.Cmd) { 24 return func(cmd *cli.Cmd) { 25 cmd.CommandLong(listCmd.Name, listCmd.ShortHelp, listCmd.LongHelp, listCmd.CmdFunc(settings)) 26 cmd.CommandLong(pushCmd.Name, pushCmd.ShortHelp, pushCmd.LongHelp, pushCmd.CmdFunc(settings)) 27 cmd.CommandLong(pullCmd.Name, pullCmd.ShortHelp, pullCmd.LongHelp, pullCmd.CmdFunc(settings)) 28 cmd.CommandLong(targets.Cmd.Name, targets.Cmd.ShortHelp, targets.Cmd.LongHelp, targets.Cmd.CmdFunc(settings)) 29 cmd.CommandLong(tags.Cmd.Name, tags.Cmd.ShortHelp, tags.Cmd.LongHelp, tags.Cmd.CmdFunc(settings)) 30 } 31 }, 32 } 33 34 var listCmd = models.Command{ 35 Name: "list", 36 ShortHelp: "List images available for an environment", 37 LongHelp: "<code>images list</code> lists available images for an environment. " + 38 "These images must be pushed to the registry for the environment and deployed in order to show. Here is a sample command:\n\n" + 39 "<pre>\ndatica -E \"<your_env_name>\" images list\n</pre>", 40 CmdFunc: func(settings *models.Settings) func(cmd *cli.Cmd) { 41 return func(cmd *cli.Cmd) { 42 cmd.Action = func() { 43 if _, err := auth.New(settings, prompts.New()).Signin(); err != nil { 44 logrus.Fatal(err.Error()) 45 } 46 if err := config.CheckRequiredAssociation(settings); err != nil { 47 logrus.Fatal(err.Error()) 48 } 49 err := cmdImageList(settings.EnvironmentID, environments.New(settings), images.New(settings)) 50 if err != nil { 51 logrus.Fatalln(err.Error()) 52 } 53 } 54 } 55 }, 56 } 57 58 var pushCmd = models.Command{ 59 Name: "push", 60 ShortHelp: "Push an image for your environment", 61 LongHelp: "<code>images push</code> pushes a new image to the registry for your environment. " + 62 "The image will be retagged with the Datica registry and your namespace appended to the front if not provided. " + 63 "If no tag is specified, the image will be tagged \"latest\"\n" + 64 "Note: Pushed images will not be returned by the `images list` command until they have been deployed. Here is a sample command:\n\n" + 65 "<pre>\ndatica -E \"<your_env_name>\" images push <image>:<tag>\n</pre>", 66 CmdFunc: func(settings *models.Settings) func(cmd *cli.Cmd) { 67 return func(cmd *cli.Cmd) { 68 image := cmd.StringArg("TAGGED_IMAGE", "", "The name of the image to push. (e.g. 'my-image:tag')") 69 cmd.Action = func() { 70 user, err := auth.New(settings, prompts.New()).Signin() 71 if err != nil { 72 logrus.Fatal(err.Error()) 73 } 74 if err = config.CheckRequiredAssociation(settings); err != nil { 75 logrus.Fatal(err.Error()) 76 } 77 err = cmdImagePush(settings.EnvironmentID, *image, user, environments.New(settings), images.New(settings), prompts.New()) 78 if err != nil { 79 logrus.Fatalln(err.Error()) 80 } 81 } 82 } 83 }, 84 } 85 86 var pullCmd = models.Command{ 87 Name: "pull", 88 ShortHelp: "Pull an image from your environment namespace", 89 LongHelp: "<code>images pull</code> pulls an image from the registry for your environment and verifies its content against a signed target. " + 90 "The image will be pulled with the Datica registry and your environment namespace appended to the front if not provided. Here is a sample command:\n\n" + 91 "<pre>\ndatica -E \"<your_env_name>\" images pull <image>:<tag>\n</pre>", 92 CmdFunc: func(settings *models.Settings) func(cmd *cli.Cmd) { 93 return func(cmd *cli.Cmd) { 94 image := cmd.StringArg("TAGGED_IMAGE", "", "The name of the image to pull. (e.g. 'my-image:tag')") 95 cmd.Action = func() { 96 user, err := auth.New(settings, prompts.New()).Signin() 97 if err != nil { 98 logrus.Fatal(err.Error()) 99 } 100 if err = config.CheckRequiredAssociation(settings); err != nil { 101 logrus.Fatal(err.Error()) 102 } 103 err = cmdImagePull(settings.EnvironmentID, *image, user, environments.New(settings), images.New(settings)) 104 if err != nil { 105 logrus.Fatalln(err.Error()) 106 } 107 } 108 } 109 }, 110 }