diff --git a/api/models/app.go b/api/models/app.go index 2739c5182..811f60510 100644 --- a/api/models/app.go +++ b/api/models/app.go @@ -16,6 +16,7 @@ var ( ErrAppsNotFound = errors.New("App not found") ErrAppsNothingToUpdate = errors.New("Nothing to update") ErrAppsMissingNew = errors.New("Missing new application") + ErrUsableImage = errors.New("Image not found") ) type App struct { diff --git a/api/runner/runner.go b/api/runner/runner.go index b9af01a4f..0703db280 100644 --- a/api/runner/runner.go +++ b/api/runner/runner.go @@ -64,6 +64,20 @@ func (r *Runner) Run(ctx context.Context, cfg *Config) (drivers.RunResult, error return result, nil } +func (r Runner) EnsureUsableImage(cfg *Config) error { + ctask := &containerTask{ + cfg: cfg, + auth: &agent.ConfigAuth{}, + } + + err := r.driver.EnsureUsableImage(cfg.Ctx, ctask) + if err != nil { + return err + } + return nil +} + + func selectDriver(driver string, env *common.Environment, conf *driverscommon.Config) (drivers.Driver, error) { switch driver { case "docker": diff --git a/api/runner/task.go b/api/runner/task.go index 163c3f21d..cdea206d1 100644 --- a/api/runner/task.go +++ b/api/runner/task.go @@ -5,6 +5,7 @@ import ( dockercli "github.com/fsouza/go-dockerclient" "github.com/iron-io/titan/runner/tasker" + "github.com/iron-io/titan/runner/drivers" ) type containerTask struct { @@ -37,6 +38,7 @@ func (t *containerTask) Volumes() [][2]string { return [][2]string func (t *containerTask) WorkDir() string { return "" } func (t *containerTask) Close() {} +func (t *containerTask) WriteStat(drivers.Stat) {} func (t *containerTask) DockerAuth() []dockercli.AuthConfiguration { return t.auth.Auth(t.Image()) diff --git a/api/server/routes_create.go b/api/server/routes_create.go index 0d925caee..6e29fbcfe 100644 --- a/api/server/routes_create.go +++ b/api/server/routes_create.go @@ -7,6 +7,7 @@ import ( "github.com/gin-gonic/gin" "github.com/iron-io/functions/api/models" + "github.com/iron-io/functions/api/runner" titancommon "github.com/iron-io/titan/common" ) @@ -37,6 +38,16 @@ func handleRouteCreate(c *gin.Context) { return } + err = Api.Runner.EnsureUsableImage(&runner.Config{ + Ctx: ctx, + Route: wroute.Route, + }) + + if err != nil { + c.JSON(http.StatusInternalServerError, simpleError(models.ErrUsableImage)) + return + } + app, err := Api.Datastore.GetApp(wroute.Route.AppName) if err != nil { log.WithError(err).Error(models.ErrAppsGet) diff --git a/glide.lock b/glide.lock index 92ef802f9..460c5b59e 100644 --- a/glide.lock +++ b/glide.lock @@ -100,7 +100,7 @@ imports: subpackages: - registry - name: github.com/iron-io/titan - version: e309e9971583fd1b9894b250a28cb194d90e8ac5 + version: ae84854491055da1c2f3baa7c32193409f07f14f repo: https://github.com/iron-io/titan.git vcs: git subpackages: