forked from carimura/cli
-
Notifications
You must be signed in to change notification settings - Fork 1
/
push.go
69 lines (58 loc) · 1.64 KB
/
push.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package main
import (
"errors"
"fmt"
"github.com/urfave/cli"
)
func push() cli.Command {
cmd := pushcmd{}
var flags []cli.Flag
flags = append(flags, cmd.flags()...)
return cli.Command{
Name: "push",
Usage: "push function to Docker Hub",
Flags: flags,
Action: cmd.push,
}
}
type pushcmd struct {
verbose bool
registry string
}
func (cmd *pushcmd) Registry() string {
return cmd.registry
}
func (p *pushcmd) flags() []cli.Flag {
return []cli.Flag{
cli.BoolFlag{
Name: "v",
Usage: "verbose mode",
Destination: &p.verbose,
},
cli.StringFlag{
Name: "registry",
Usage: "Sets the Docker owner for images and optionally the registry. This will be prefixed to your function name for pushing to Docker registries. eg: `--registry username` will set your Docker Hub owner. `--registry registry.hub.docker.com/username` will set the registry and owner.",
Destination: &p.registry,
},
}
}
// push will take the found function and check for the presence of a
// Dockerfile, and run a three step process: parse functions file,
// push the container, and finally it will update function's route. Optionally,
// the route can be overriden inside the functions file.
func (p *pushcmd) push(c *cli.Context) error {
setRegistryEnv(p)
ff, err := loadFuncfile()
if err != nil {
if _, ok := err.(*notFoundError); ok {
return errors.New("error: image name is missing or no function file found")
}
return err
}
fmt.Println("pushing", ff.ImageName())
if err := dockerpush(ff); err != nil {
return err
}
fmt.Printf("Function %v pushed successfully to Docker Hub.\n", ff.ImageName())
return nil
}