github.com/iron-io/functions@v0.0.0-20180820112432-d59d7d1c40b2/fn/commands/images/push.go (about) 1 package commands 2 3 import ( 4 "errors" 5 "fmt" 6 "github.com/iron-io/functions/fn/common" 7 "github.com/urfave/cli" 8 ) 9 10 func Push() cli.Command { 11 cmd := pushcmd{} 12 var flags []cli.Flag 13 flags = append(flags, cmd.flags()...) 14 return cli.Command{ 15 Name: "push", 16 Usage: "push function to Docker Hub", 17 Flags: flags, 18 Action: cmd.push, 19 } 20 } 21 22 type pushcmd struct { 23 verbose bool 24 } 25 26 func (p *pushcmd) flags() []cli.Flag { 27 return []cli.Flag{ 28 cli.BoolFlag{ 29 Name: "v", 30 Usage: "verbose mode", 31 Destination: &p.verbose, 32 }, 33 } 34 } 35 36 // push will take the found function and check for the presence of a 37 // Dockerfile, and run a three step process: parse functions file, 38 // push the container, and finally it will update function's route. Optionally, 39 // the route can be overriden inside the functions file. 40 func (p *pushcmd) push(c *cli.Context) error { 41 verbwriter := common.Verbwriter(p.verbose) 42 43 ff, err := common.LoadFuncfile() 44 if err != nil { 45 if _, ok := err.(*common.NotFoundError); ok { 46 return errors.New("error: image name is missing or no function file found") 47 } 48 return err 49 } 50 51 fmt.Fprintln(verbwriter, "pushing", ff.FullName()) 52 53 if err := common.Dockerpush(ff); err != nil { 54 return err 55 } 56 57 fmt.Printf("Function %v pushed successfully to Docker Hub.\n", ff.FullName()) 58 return nil 59 }