update titan, other deps and minor changes

This commit is contained in:
Pedro Nasser
2016-08-24 16:11:21 -03:00
parent 08267e6475
commit 6a2e9b29be
6 changed files with 98 additions and 72 deletions

View File

@@ -7,7 +7,6 @@ import (
"golang.org/x/net/context" "golang.org/x/net/context"
"github.com/iron-io/functions/api/models"
"github.com/iron-io/titan/common" "github.com/iron-io/titan/common"
"github.com/iron-io/titan/runner/agent" "github.com/iron-io/titan/runner/agent"
"github.com/iron-io/titan/runner/drivers" "github.com/iron-io/titan/runner/drivers"
@@ -17,15 +16,13 @@ import (
) )
type Config struct { type Config struct {
ID string ID string
Ctx context.Context Image string
Route *models.Route Timeout time.Duration
Payload string AppName string
Timeout time.Duration Env map[string]string
RequestURL string Stdout io.Writer
AppName string Stderr io.Writer
Stdout io.Writer
Stderr io.Writer
} }
type Runner struct { type Runner struct {
@@ -56,6 +53,12 @@ func (r *Runner) Run(ctx context.Context, cfg *Config) (drivers.RunResult, error
auth: &agent.ConfigAuth{}, auth: &agent.ConfigAuth{},
} }
closer, err := r.driver.Prepare(ctx, ctask)
if err != nil {
return nil, err
}
defer closer.Close()
result, err := r.driver.Run(ctx, ctask) result, err := r.driver.Run(ctx, ctask)
if err != nil { if err != nil {
return nil, err return nil, err
@@ -64,20 +67,19 @@ func (r *Runner) Run(ctx context.Context, cfg *Config) (drivers.RunResult, error
return result, nil return result, nil
} }
func (r Runner) EnsureUsableImage(cfg *Config) error { func (r Runner) EnsureUsableImage(ctx context.Context, cfg *Config) error {
ctask := &containerTask{ ctask := &containerTask{
cfg: cfg, cfg: cfg,
auth: &agent.ConfigAuth{}, auth: &agent.ConfigAuth{},
} }
err := r.driver.EnsureUsableImage(cfg.Ctx, ctask) err := r.driver.EnsureUsableImage(ctx, ctask)
if err != nil { if err != nil {
return err return err
} }
return nil return nil
} }
func selectDriver(driver string, env *common.Environment, conf *driverscommon.Config) (drivers.Driver, error) { func selectDriver(driver string, env *common.Environment, conf *driverscommon.Config) (drivers.Driver, error) {
switch driver { switch driver {
case "docker": case "docker":

View File

@@ -30,12 +30,14 @@ func TestRunnerHello(t *testing.T) {
} { } {
var stdout, stderr bytes.Buffer var stdout, stderr bytes.Buffer
cfg := &Config{ cfg := &Config{
ID: fmt.Sprintf("task-hello-%d-%d", i, time.Now().Unix()), ID: fmt.Sprintf("hello-%d-%d", i, time.Now().Unix()),
Route: test.route, Image: test.route.Image,
Timeout: 5 * time.Second, Timeout: 5 * time.Second,
Payload: test.payload, Env: map[string]string{
Stdout: &stdout, "PAYLOAD": test.payload,
Stderr: &stderr, },
Stdout: &stdout,
Stderr: &stderr,
} }
result, err := runner.Run(ctx, cfg) result, err := runner.Run(ctx, cfg)
@@ -77,12 +79,14 @@ func TestRunnerError(t *testing.T) {
} { } {
var stdout, stderr bytes.Buffer var stdout, stderr bytes.Buffer
cfg := &Config{ cfg := &Config{
ID: fmt.Sprintf("task-err-%d-%d", i, time.Now().Unix()), ID: fmt.Sprintf("err-%d-%d", i, time.Now().Unix()),
Route: test.route, Image: test.route.Image,
Timeout: 5 * time.Second, Timeout: 5 * time.Second,
Payload: test.payload, Env: map[string]string{
Stdout: &stdout, "PAYLOAD": test.payload,
Stderr: &stderr, },
Stdout: &stdout,
Stderr: &stderr,
} }
result, err := runner.Run(ctx, cfg) result, err := runner.Run(ctx, cfg)

View File

@@ -4,8 +4,8 @@ import (
"io" "io"
dockercli "github.com/fsouza/go-dockerclient" dockercli "github.com/fsouza/go-dockerclient"
"github.com/iron-io/titan/runner/tasker"
"github.com/iron-io/titan/runner/drivers" "github.com/iron-io/titan/runner/drivers"
"github.com/iron-io/titan/runner/tasker"
) )
type containerTask struct { type containerTask struct {
@@ -16,11 +16,7 @@ type containerTask struct {
func (t *containerTask) Command() string { return "" } func (t *containerTask) Command() string { return "" }
func (t *containerTask) EnvVars() map[string]string { func (t *containerTask) EnvVars() map[string]string {
env := map[string]string{ return t.cfg.Env
"PAYLOAD": t.cfg.Payload,
"REQUEST_URL": t.cfg.RequestURL,
}
return env
} }
func (t *containerTask) Labels() map[string]string { func (t *containerTask) Labels() map[string]string {
@@ -31,14 +27,14 @@ func (t *containerTask) Labels() map[string]string {
func (t *containerTask) Id() string { return t.cfg.ID } func (t *containerTask) Id() string { return t.cfg.ID }
func (t *containerTask) Group() string { return "" } func (t *containerTask) Group() string { return "" }
func (t *containerTask) Image() string { return t.cfg.Route.Image } func (t *containerTask) Image() string { return t.cfg.Image }
func (t *containerTask) Timeout() uint { return uint(t.cfg.Timeout.Seconds()) } func (t *containerTask) Timeout() uint { return uint(t.cfg.Timeout.Seconds()) }
func (t *containerTask) Logger() (stdout, stderr io.Writer) { return t.cfg.Stdout, t.cfg.Stderr } func (t *containerTask) Logger() (stdout, stderr io.Writer) { return t.cfg.Stdout, t.cfg.Stderr }
func (t *containerTask) Volumes() [][2]string { return [][2]string{} } func (t *containerTask) Volumes() [][2]string { return [][2]string{} }
func (t *containerTask) WorkDir() string { return "" } func (t *containerTask) WorkDir() string { return "" }
func (t *containerTask) Close() {} func (t *containerTask) Close() {}
func (t *containerTask) WriteStat(drivers.Stat) {} func (t *containerTask) WriteStat(drivers.Stat) {}
func (t *containerTask) DockerAuth() []dockercli.AuthConfiguration { func (t *containerTask) DockerAuth() []dockercli.AuthConfiguration {
return t.auth.Auth(t.Image()) return t.auth.Auth(t.Image())

View File

@@ -38,11 +38,9 @@ func handleRouteCreate(c *gin.Context) {
return return
} }
err = Api.Runner.EnsureUsableImage(&runner.Config{ err = Api.Runner.EnsureUsableImage(ctx, &runner.Config{
Ctx: ctx, Image: wroute.Route.Image,
Route: wroute.Route, })
})
if err != nil { if err != nil {
c.JSON(http.StatusInternalServerError, simpleError(models.ErrUsableImage)) c.JSON(http.StatusInternalServerError, simpleError(models.ErrUsableImage))
return return

View File

@@ -111,14 +111,16 @@ func handleRunner(c *gin.Context) {
if el.Path == route { if el.Path == route {
var stdout, stderr bytes.Buffer var stdout, stderr bytes.Buffer
cfg := &runner.Config{ cfg := &runner.Config{
Route: el, Image: el.Image,
Payload: string(payload), Timeout: 30 * time.Second,
Timeout: 30 * time.Second, ID: reqID,
ID: reqID, AppName: appName,
RequestURL: c.Request.URL.String(), Stdout: &stdout,
AppName: appName, Stderr: &stderr,
Stdout: &stdout, Env: map[string]string{
Stderr: &stderr, "PAYLOAD": string(payload),
"REQUEST_URL": c.Request.URL.String(),
},
} }
if result, err := Api.Runner.Run(c, cfg); err != nil { if result, err := Api.Runner.Run(c, cfg); err != nil {

78
glide.lock generated
View File

@@ -1,5 +1,5 @@
hash: 5ccf89905e13b7dc987cd203c1d7c1fddd32dcd776fe2e5f60d9f6f7b9908425 hash: 5ccf89905e13b7dc987cd203c1d7c1fddd32dcd776fe2e5f60d9f6f7b9908425
updated: 2016-08-16T14:52:37.933227014+12:00 updated: 2016-08-24T14:50:27.724858484-03:00
imports: imports:
- name: github.com/amir/raidman - name: github.com/amir/raidman
version: c74861fe6a7bb8ede0a010ce4485bdbb4fc4c985 version: c74861fe6a7bb8ede0a010ce4485bdbb4fc4c985
@@ -8,13 +8,15 @@ imports:
- name: github.com/asaskevich/govalidator - name: github.com/asaskevich/govalidator
version: 593d64559f7600f29581a3ee42177f5dbded27a9 version: 593d64559f7600f29581a3ee42177f5dbded27a9
- name: github.com/boltdb/bolt - name: github.com/boltdb/bolt
version: 94c8db596809690a3f7046fa83c7b0dda13a3222 version: 583e8937c61f1af6513608ccc75c97b6abdf4ff9
- name: github.com/BurntSushi/toml
version: 99064174e013895bbd9b025c31100bd1d9b590ca
- name: github.com/cactus/go-statsd-client - name: github.com/cactus/go-statsd-client
version: 91c326c3f7bd20f0226d3d1c289dd9f8ce28d33d version: 1c27c506c7a0584d017ca479f91b88d6a6538332
subpackages: subpackages:
- statsd - statsd
- name: github.com/dgrijalva/jwt-go
version: 63734eae1ef55eaac06fdc0f312615f2e321e273
subpackages:
- request
- name: github.com/docker/distribution - name: github.com/docker/distribution
version: 9ca7921603852314b18a6ecc19f91806935f34bd version: 9ca7921603852314b18a6ecc19f91806935f34bd
subpackages: subpackages:
@@ -28,24 +30,30 @@ imports:
- pkg/fileutils - pkg/fileutils
- pkg/homedir - pkg/homedir
- pkg/stdcopy - pkg/stdcopy
- pkg/parsers - pkg/idtools
- pkg/ulimit - pkg/ioutils
- volume
- pkg/pools - pkg/pools
- pkg/promise - pkg/promise
- pkg/system - pkg/system
- pkg/ioutils - pkg/longpath
- pkg/random
- pkg/units - pkg/units
- pkg/tarsum - pkg/tarsum
- pkg/random - name: github.com/docker/engine-api
version: 2f8c367944a28130f3c2fb9f0aad7f1d5db952a9
subpackages:
- types/swarm
- types/filters
- types/mount
- types/versions
- name: github.com/docker/go-units - name: github.com/docker/go-units
version: eb879ae3e2b84e2a142af415b679ddeda47ec71c version: eb879ae3e2b84e2a142af415b679ddeda47ec71c
- name: github.com/docker/libtrust - name: github.com/docker/libtrust
version: 9cbd2a1374f46905c68a4eb3694a130610adc62a version: 9cbd2a1374f46905c68a4eb3694a130610adc62a
- name: github.com/fsnotify/fsnotify - name: github.com/fsnotify/fsnotify
version: a8a77c9133d2d6fd8334f3260d06f60e8d80a5fb version: f12c6236fe7b5cf6bcf30e5935d08cb079d78334
- name: github.com/fsouza/go-dockerclient - name: github.com/fsouza/go-dockerclient
version: 62035adb3375dad32558aa3b1bd2279e4504e000 version: 0436d420da98515cfe6370c9c5cdde868415637b
- name: github.com/garyburd/redigo - name: github.com/garyburd/redigo
version: 4ed1111375cbeb698249ffe48dd463e9b0a63a7a version: 4ed1111375cbeb698249ffe48dd463e9b0a63a7a
subpackages: subpackages:
@@ -57,7 +65,7 @@ imports:
- binding - binding
- render - render
- name: github.com/go-openapi/analysis - name: github.com/go-openapi/analysis
version: abc9a6171f5bf03ada39aead1aa7fd7bbd44d50f version: b44dc874b601d9e4e2f6e19140e794ba24bead3b
- name: github.com/go-openapi/errors - name: github.com/go-openapi/errors
version: d24ebc2075bad502fac3a8ae27aa6dd58e1952dc version: d24ebc2075bad502fac3a8ae27aa6dd58e1952dc
- name: github.com/go-openapi/jsonpointer - name: github.com/go-openapi/jsonpointer
@@ -71,11 +79,11 @@ imports:
subpackages: subpackages:
- client - client
- name: github.com/go-openapi/spec - name: github.com/go-openapi/spec
version: e9fab754f5629065e6b7a6100301226545d4477e version: 6aced65f8501fe1217321abf0749d354824ba2ff
- name: github.com/go-openapi/strfmt - name: github.com/go-openapi/strfmt
version: dfda818c47a4ae5a1dde75ac776f34b2c95de993 version: d65c7fdb29eca313476e529628176fe17e58c488
- name: github.com/go-openapi/swag - name: github.com/go-openapi/swag
version: 1d0bd113de87027671077d3c71eb3ac5d7dbba72 version: 0e04f5e499b19bf51031c01a00f098f25067d8dc
- name: github.com/go-openapi/validate - name: github.com/go-openapi/validate
version: deaf2c9013bc1a7f4c774662259a506ba874d80f version: deaf2c9013bc1a7f4c774662259a506ba874d80f
- name: github.com/golang/protobuf - name: github.com/golang/protobuf
@@ -85,7 +93,7 @@ imports:
- name: github.com/hashicorp/go-cleanhttp - name: github.com/hashicorp/go-cleanhttp
version: ad28ea4487f05916463e2423a55166280e8254b5 version: ad28ea4487f05916463e2423a55166280e8254b5
- name: github.com/hashicorp/hcl - name: github.com/hashicorp/hcl
version: d8c773c4cba11b11539e3d45f93daeaa5dcf1fa1 version: baeb59c710717b06aac1dbe2270e8192ec593244
subpackages: subpackages:
- hcl/ast - hcl/ast
- hcl/parser - hcl/parser
@@ -100,7 +108,7 @@ imports:
subpackages: subpackages:
- registry - registry
- name: github.com/iron-io/titan - name: github.com/iron-io/titan
version: ae84854491055da1c2f3baa7c32193409f07f14f version: 58d1565025aa045bdf47b44e0eb81a52c70f7958
repo: https://github.com/iron-io/titan.git repo: https://github.com/iron-io/titan.git
vcs: git vcs: git
subpackages: subpackages:
@@ -123,9 +131,9 @@ imports:
subpackages: subpackages:
- oid - oid
- name: github.com/magiconair/properties - name: github.com/magiconair/properties
version: b3f6dd549956e8a61ea4a686a1c02a33d5bdda4b version: 61b492c03cf472e0c6419be5899b8e0dc28b1b88
- name: github.com/mailru/easyjson - name: github.com/mailru/easyjson
version: d5b7844b561a7bc640052f1b935f7b800330d7e0 version: 34560e358dc05e2c28f6fda2f5c9e7494a4b9b19
subpackages: subpackages:
- jlexer - jlexer
- jwriter - jwriter
@@ -133,15 +141,20 @@ imports:
- name: github.com/manucorporat/sse - name: github.com/manucorporat/sse
version: ee05b128a739a0fb76c7ebd3ae4810c1de808d6d version: ee05b128a739a0fb76c7ebd3ae4810c1de808d6d
- name: github.com/mitchellh/mapstructure - name: github.com/mitchellh/mapstructure
version: 21a35fb16463dfb7c8eee579c65d995d95e64d1e version: ca63d7c062ee3c9f34db231e352b60012b4fd0c1
- name: github.com/opencontainers/runc - name: github.com/opencontainers/runc
version: 142df3836b740af53dc6da59eed8dbc92f62917c version: 46d9535096662d8d6a734e4fdfc1c27ab03bc328
subpackages: subpackages:
- libcontainer/system
- libcontainer/user - libcontainer/user
- name: github.com/pelletier/go-buffruneio
version: df1e16fde7fc330a0ca68167c23bf7ed6ac31d6d
- name: github.com/pelletier/go-toml
version: 5a62685873ef617233ab5f1b825a6e4a758e16cf
- name: github.com/pivotal-golang/bytefmt - name: github.com/pivotal-golang/bytefmt
version: 24c06ce13e176cf7a7a440c8cf3b64d91c36c8e2 version: 24c06ce13e176cf7a7a440c8cf3b64d91c36c8e2
- name: github.com/pkg/errors - name: github.com/pkg/errors
version: 2a9be18ecd8c148be18be08a811e33809206da19 version: 17b591df37844cde689f4d5813e5cea0927d8dd2
- name: github.com/pkg/sftp - name: github.com/pkg/sftp
version: a71e8f580e3b622ebff585309160b1cc549ef4d2 version: a71e8f580e3b622ebff585309160b1cc549ef4d2
- name: github.com/PuerkitoBio/purell - name: github.com/PuerkitoBio/purell
@@ -155,7 +168,7 @@ imports:
subpackages: subpackages:
- hooks/syslog - hooks/syslog
- name: github.com/spf13/afero - name: github.com/spf13/afero
version: cc9c21814bb945440253108c4d3c65c85aac3c68 version: 20500e2abd0d1f4564a499e83d11d6c73cd58c27
subpackages: subpackages:
- mem - mem
- sftp - sftp
@@ -164,13 +177,17 @@ imports:
- name: github.com/spf13/jwalterweatherman - name: github.com/spf13/jwalterweatherman
version: 33c24e77fb80341fe7130ee7c594256ff08ccc46 version: 33c24e77fb80341fe7130ee7c594256ff08ccc46
- name: github.com/spf13/pflag - name: github.com/spf13/pflag
version: f676131e2660dc8cd88de99f7486d34aa8172635 version: 103ce5cd2042f2fe629c1957abb64ab3e7f50235
- name: github.com/spf13/viper - name: github.com/spf13/viper
version: 346299ea79e446ebdddb834371ceba2e5926b732 version: 7fb2782df3d83e0036cc89f461ed0422628776f4
- name: golang.org/x/crypto - name: golang.org/x/crypto
version: c10c31b5e94b6f7a0283272dc2bb27163dcea24b version: c10c31b5e94b6f7a0283272dc2bb27163dcea24b
subpackages: subpackages:
- bcrypt
- blowfish
- ssh - ssh
- curve25519
- ed25519
- name: golang.org/x/net - name: golang.org/x/net
version: f315505cf3349909cdf013ea56690da34e96a451 version: f315505cf3349909cdf013ea56690da34e96a451
subpackages: subpackages:
@@ -183,7 +200,7 @@ imports:
subpackages: subpackages:
- unix - unix
- name: golang.org/x/text - name: golang.org/x/text
version: 2910a502d2bf9e43193af9d68ca516529614eed3 version: d69c40b4be55797923cec7457fac7a244d91a9b6
subpackages: subpackages:
- transform - transform
- unicode/norm - unicode/norm
@@ -197,6 +214,13 @@ imports:
- internal/tag - internal/tag
- name: gopkg.in/go-playground/validator.v8 - name: gopkg.in/go-playground/validator.v8
version: c193cecd124b5cc722d7ee5538e945bdb3348435 version: c193cecd124b5cc722d7ee5538e945bdb3348435
- name: gopkg.in/mgo.v2
version: 3f83fa5005286a7fe593b055f0d7771a7dce4655
subpackages:
- bson
- internal/sasl
- internal/scram
- internal/json
- name: gopkg.in/yaml.v2 - name: gopkg.in/yaml.v2
version: e4d366fc3c7938e2958e662b4258c7a89e1f0e3e version: e4d366fc3c7938e2958e662b4258c7a89e1f0e3e
testImports: [] testImports: []