forked from iron-io/functions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
push.go
60 lines (50 loc) · 1.27 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
package main
import (
"fmt"
"os"
functions "github.com/iron-io/functions_go"
"github.com/urfave/cli"
)
func push() cli.Command {
cmd := pushcmd{
publishcmd: &publishcmd{
commoncmd: &commoncmd{},
RoutesApi: functions.NewRoutesApi(),
},
}
var flags []cli.Flag
flags = append(flags, cmd.commoncmd.flags()...)
return cli.Command{
Name: "push",
Usage: "push function to Docker Hub",
Flags: flags,
Action: cmd.scan,
}
}
type pushcmd struct {
*publishcmd
}
func (p *pushcmd) scan(c *cli.Context) error {
p.commoncmd.scan(p.walker)
return nil
}
func (p *pushcmd) walker(path string, info os.FileInfo, err error) error {
walker(path, info, err, p.push)
return nil
}
// 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(path string) error {
fmt.Fprintln(p.verbwriter, "pushing", path)
funcfile, err := parsefuncfile(path)
if err != nil {
return err
}
if err := p.dockerpush(funcfile); err != nil {
return err
}
fmt.Printf("Function %v pushed successfully to Docker Hub.\n", funcfile.FullName())
return nil
}