fnctl: add push command (#248)

Fixes #229
This commit is contained in:
C Cirello
2016-11-09 23:30:17 +01:00
committed by GitHub
parent 71dabe21ae
commit aec766679d
3 changed files with 70 additions and 1 deletions

View File

@@ -157,7 +157,7 @@ during functions execution.
the image. These calls are executed before `fnctl` calls `docker build` and the image. These calls are executed before `fnctl` calls `docker build` and
`docker push`. `docker push`.
## Build and Bump ## Build, Bump, Push
When dealing with a lot of functions you might find yourself making lots of 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 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, their version according to [semver](http://semver.org/) rules. In their absence,
it will skip. it will skip.
`fnctl push` will scan all IronFunctions and push their images to Docker Hub,
and update their routes accordingly.
## Application level configuration ## Application level configuration
When creating an application, you can configure it to tweak its behavior and its When creating an application, you can configure it to tweak its behavior and its

View File

@@ -24,6 +24,7 @@ func main() {
call(), call(),
lambda(), lambda(),
publish(), publish(),
push(),
routes(), routes(),
run(), run(),
} }

65
fnctl/push.go Normal file
View File

@@ -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
}