mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
functions: hot containers (#332)
* functions: modify datastore to accomodate hot containers support * functions: protocol between functions and hot containers * functions: add hot containers clockwork * fn: add hot containers support
This commit is contained in:
@@ -23,16 +23,18 @@ var (
|
||||
)
|
||||
|
||||
type funcfile struct {
|
||||
App *string `yaml:"app,omitempty",json:"app,omitempty"`
|
||||
Name string `yaml:"name,omitempty",json:"name,omitempty"`
|
||||
Version string `yaml:"version,omitempty",json:"version,omitempty"`
|
||||
Runtime *string `yaml:"runtime,omitempty",json:"runtime,omitempty"`
|
||||
Entrypoint *string `yaml:"entrypoint,omitempty",json:"entrypoint,omitempty"`
|
||||
Route *string `yaml:"route,omitempty",json:"route,omitempty"`
|
||||
Type *string `yaml:"type,omitempty",json:"type,omitempty"`
|
||||
Memory *int64 `yaml:"memory,omitempty",json:"memory,omitempty"`
|
||||
Config map[string]string `yaml:"config,omitempty",json:"config,omitempty"`
|
||||
Build []string `yaml:"build,omitempty",json:"build,omitempty"`
|
||||
App *string `yaml:"app,omitempty",json:"app,omitempty"`
|
||||
Name string `yaml:"name,omitempty",json:"name,omitempty"`
|
||||
Version string `yaml:"version,omitempty",json:"version,omitempty"`
|
||||
Runtime *string `yaml:"runtime,omitempty",json:"runtime,omitempty"`
|
||||
Entrypoint *string `yaml:"entrypoint,omitempty",json:"entrypoint,omitempty"`
|
||||
Route *string `yaml:"route,omitempty",json:"route,omitempty"`
|
||||
Type *string `yaml:"type,omitempty",json:"type,omitempty"`
|
||||
Memory *int64 `yaml:"memory,omitempty",json:"memory,omitempty"`
|
||||
Format *string `yaml:"format,omitempty",json:"format,omitempty"`
|
||||
MaxConcurrency *int `yaml:"int,omitempty",json:"int,omitempty"`
|
||||
Config map[string]string `yaml:"config,omitempty",json:"config,omitempty"`
|
||||
Build []string `yaml:"build,omitempty",json:"build,omitempty"`
|
||||
}
|
||||
|
||||
func (ff *funcfile) FullName() string {
|
||||
|
||||
32
fn/init.go
32
fn/init.go
@@ -40,10 +40,12 @@ func init() {
|
||||
}
|
||||
|
||||
type initFnCmd struct {
|
||||
name string
|
||||
force bool
|
||||
runtime string
|
||||
entrypoint string
|
||||
name string
|
||||
force bool
|
||||
runtime string
|
||||
entrypoint string
|
||||
format string
|
||||
maxConcurrency int
|
||||
}
|
||||
|
||||
func initFn() cli.Command {
|
||||
@@ -71,6 +73,18 @@ func initFn() cli.Command {
|
||||
Usage: "entrypoint is the command to run to start this function - equivalent to Dockerfile ENTRYPOINT.",
|
||||
Destination: &a.entrypoint,
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "format",
|
||||
Usage: "hot container IO format - json or http",
|
||||
Destination: &a.format,
|
||||
Value: "",
|
||||
},
|
||||
cli.IntFlag{
|
||||
Name: "max-concurrency",
|
||||
Usage: "maximum concurrency for hot container",
|
||||
Destination: &a.maxConcurrency,
|
||||
Value: 1,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -92,10 +106,12 @@ func (a *initFnCmd) init(c *cli.Context) error {
|
||||
}
|
||||
|
||||
ff := &funcfile{
|
||||
Name: a.name,
|
||||
Runtime: &a.runtime,
|
||||
Version: initialVersion,
|
||||
Entrypoint: &a.entrypoint,
|
||||
Name: a.name,
|
||||
Runtime: &a.runtime,
|
||||
Version: initialVersion,
|
||||
Entrypoint: &a.entrypoint,
|
||||
Format: &a.format,
|
||||
MaxConcurrency: &a.maxConcurrency,
|
||||
}
|
||||
|
||||
if err := encodeFuncfileYAML("func.yaml", ff); err != nil {
|
||||
|
||||
39
fn/routes.go
39
fn/routes.go
@@ -64,6 +64,16 @@ func routes() cli.Command {
|
||||
Name: "config,c",
|
||||
Usage: "route configuration",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "format,f",
|
||||
Usage: "hot container IO format - json or http",
|
||||
Value: "",
|
||||
},
|
||||
cli.IntFlag{
|
||||
Name: "max-concurrency,m",
|
||||
Usage: "maximum concurrency for hot container",
|
||||
Value: 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -229,6 +239,8 @@ func (a *routesCmd) create(c *cli.Context) error {
|
||||
appName := c.Args().Get(0)
|
||||
route := c.Args().Get(1)
|
||||
image := c.Args().Get(2)
|
||||
var format string
|
||||
var maxC int
|
||||
if image == "" {
|
||||
ff, err := findFuncfile()
|
||||
if err != nil {
|
||||
@@ -239,16 +251,31 @@ func (a *routesCmd) create(c *cli.Context) error {
|
||||
}
|
||||
}
|
||||
image = ff.FullName()
|
||||
if ff.Format != nil {
|
||||
format = *ff.Format
|
||||
}
|
||||
if ff.MaxConcurrency != nil {
|
||||
maxC = *ff.MaxConcurrency
|
||||
}
|
||||
}
|
||||
|
||||
if f := c.String("format"); f != "" {
|
||||
format = f
|
||||
}
|
||||
if m := c.Int("max-concurrency"); m > 0 {
|
||||
maxC = m
|
||||
}
|
||||
|
||||
body := functions.RouteWrapper{
|
||||
Route: functions.Route{
|
||||
AppName: appName,
|
||||
Path: route,
|
||||
Image: image,
|
||||
Memory: c.Int64("memory"),
|
||||
Type_: c.String("type"),
|
||||
Config: extractEnvConfig(c.StringSlice("config")),
|
||||
AppName: appName,
|
||||
Path: route,
|
||||
Image: image,
|
||||
Memory: c.Int64("memory"),
|
||||
Type_: c.String("type"),
|
||||
Config: extractEnvConfig(c.StringSlice("config")),
|
||||
Format: format,
|
||||
MaxConcurrency: int32(maxC),
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user