github.com/emc-advanced-dev/unik@v0.0.0-20190717152701-a58d3e8e33b7/cmd/push.go (about) 1 package cmd 2 3 import ( 4 "fmt" 5 "github.com/sirupsen/logrus" 6 "github.com/emc-advanced-dev/pkg/errors" 7 "github.com/solo-io/unik/pkg/client" 8 "github.com/solo-io/unik/pkg/config" 9 "github.com/spf13/cobra" 10 "gopkg.in/yaml.v2" 11 "io/ioutil" 12 ) 13 14 // pushCmd represents the push command 15 var pushCmd = &cobra.Command{ 16 Use: "push", 17 Short: "Push an image to a Unik Image Repository", 18 Long: ` 19 Example usage: 20 unik push --image myImage 21 22 Requires that you first authenticate to a unik image repository with 'unik login' 23 `, 24 Run: func(cmd *cobra.Command, args []string) { 25 if err := readClientConfig(); err != nil { 26 logrus.Fatal(err) 27 } 28 c, err := getHubConfig() 29 if err != nil { 30 logrus.Fatal(err) 31 } 32 if imageName == "" { 33 logrus.Fatal("--image must be set") 34 } 35 if host == "" { 36 host = clientConfig.Host 37 } 38 if err := client.UnikClient(host).Images().Push(c, imageName); err != nil { 39 logrus.Fatal(err) 40 } 41 fmt.Println(imageName + " pushed") 42 }, 43 } 44 45 func getHubConfig() (config.HubConfig, error) { 46 var c config.HubConfig 47 data, err := ioutil.ReadFile(hubConfigFile) 48 if err != nil { 49 return c, errors.New("reading "+hubConfigFile, err) 50 } 51 if err := yaml.Unmarshal(data, &c); err != nil { 52 return c, errors.New("failed to convert config from yaml", err) 53 } 54 return c, nil 55 } 56 57 func init() { 58 RootCmd.AddCommand(pushCmd) 59 pushCmd.Flags().StringVar(&imageName, "image", "", "<string,required> image to push") 60 }