From aec766679d2dd7f3e7ad05fc1c1d96c7a04da479 Mon Sep 17 00:00:00 2001 From: C Cirello Date: Wed, 9 Nov 2016 23:30:17 +0100 Subject: [PATCH] fnctl: add `push` command (#248) Fixes #229 --- fnctl/README.md | 5 +++- fnctl/main.go | 1 + fnctl/push.go | 65 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 fnctl/push.go diff --git a/fnctl/README.md b/fnctl/README.md index f1f6b003b..14deef99c 100644 --- a/fnctl/README.md +++ b/fnctl/README.md @@ -157,7 +157,7 @@ during functions execution. the image. These calls are executed before `fnctl` calls `docker build` and `docker push`. -## Build and Bump +## Build, Bump, Push When dealing with a lot of functions you might find yourself making lots of individual calls. `fnctl` offers two command to help you with that: `build` and @@ -184,6 +184,9 @@ path result their version according to [semver](http://semver.org/) rules. In their absence, it will skip. +`fnctl push` will scan all IronFunctions and push their images to Docker Hub, +and update their routes accordingly. + ## Application level configuration When creating an application, you can configure it to tweak its behavior and its diff --git a/fnctl/main.go b/fnctl/main.go index 18612106b..2267894ea 100644 --- a/fnctl/main.go +++ b/fnctl/main.go @@ -24,6 +24,7 @@ func main() { call(), lambda(), publish(), + push(), routes(), run(), } diff --git a/fnctl/push.go b/fnctl/push.go new file mode 100644 index 000000000..59191b432 --- /dev/null +++ b/fnctl/push.go @@ -0,0 +1,65 @@ +package main + +import ( + "fmt" + "io" + "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()...) + flags = append(flags, confFlags(&cmd.Configuration)...) + return cli.Command{ + Name: "push", + Usage: "scan local directory for functions and push them.", + 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, w io.Writer) error { + walker(path, info, err, w, 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.Image); err != nil { + return err + } + + if err := p.route(path, funcfile); err != nil { + return err + } + + return nil +}