mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
Some small cleanup to docs.
This commit is contained in:
committed by
Reed Allman
parent
ed46a61f51
commit
69f0201818
@@ -14,8 +14,8 @@ import (
|
|||||||
|
|
||||||
"github.com/Sirupsen/logrus"
|
"github.com/Sirupsen/logrus"
|
||||||
"gitlab.oracledx.com/odx/functions/api/models"
|
"gitlab.oracledx.com/odx/functions/api/models"
|
||||||
"gitlab.oracledx.com/odx/functions/api/runner/task"
|
|
||||||
"gitlab.oracledx.com/odx/functions/api/runner/common"
|
"gitlab.oracledx.com/odx/functions/api/runner/common"
|
||||||
|
"gitlab.oracledx.com/odx/functions/api/runner/task"
|
||||||
)
|
)
|
||||||
|
|
||||||
func getTask(ctx context.Context, url string) (*models.Task, error) {
|
func getTask(ctx context.Context, url string) (*models.Task, error) {
|
||||||
@@ -42,22 +42,23 @@ func getTask(ctx context.Context, url string) (*models.Task, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getCfg(t *models.Task) *task.Config {
|
func getCfg(t *models.Task) *task.Config {
|
||||||
timeout := int32(30)
|
|
||||||
if t.Timeout == nil {
|
|
||||||
t.Timeout = &timeout
|
|
||||||
}
|
|
||||||
if t.IdleTimeout == nil {
|
|
||||||
t.IdleTimeout = &timeout
|
|
||||||
}
|
|
||||||
|
|
||||||
cfg := &task.Config{
|
cfg := &task.Config{
|
||||||
Image: *t.Image,
|
Image: *t.Image,
|
||||||
Timeout: time.Duration(*t.Timeout) * time.Second,
|
|
||||||
IdleTimeout: time.Duration(*t.IdleTimeout) * time.Second,
|
|
||||||
ID: t.ID,
|
ID: t.ID,
|
||||||
AppName: t.AppName,
|
AppName: t.AppName,
|
||||||
Env: t.EnvVars,
|
Env: t.EnvVars,
|
||||||
}
|
}
|
||||||
|
if t.Timeout == nil || *t.Timeout <= 0 {
|
||||||
|
cfg.Timeout = DefaultTimeout
|
||||||
|
} else {
|
||||||
|
cfg.Timeout = time.Duration(*t.Timeout) * time.Second
|
||||||
|
}
|
||||||
|
if t.IdleTimeout == nil || *t.IdleTimeout <= 0 {
|
||||||
|
cfg.IdleTimeout = DefaultIdleTimeout
|
||||||
|
} else {
|
||||||
|
cfg.IdleTimeout = time.Duration(*t.IdleTimeout) * time.Second
|
||||||
|
}
|
||||||
|
|
||||||
return cfg
|
return cfg
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -37,8 +37,12 @@ type Runner struct {
|
|||||||
var (
|
var (
|
||||||
ErrTimeOutNoMemory = errors.New("Task timed out. No available memory.")
|
ErrTimeOutNoMemory = errors.New("Task timed out. No available memory.")
|
||||||
ErrFullQueue = errors.New("The runner queue is full")
|
ErrFullQueue = errors.New("The runner queue is full")
|
||||||
|
WaitMemoryTimeout = 10 * time.Second
|
||||||
|
)
|
||||||
|
|
||||||
WaitMemoryTimeout = 10 * time.Second
|
const (
|
||||||
|
DefaultTimeout = 30 * time.Second
|
||||||
|
DefaultIdleTimeout = 30 * time.Second
|
||||||
)
|
)
|
||||||
|
|
||||||
func New(ctx context.Context, flog FuncLogger, mlog MetricLogger) (*Runner, error) {
|
func New(ctx context.Context, flog FuncLogger, mlog MetricLogger) (*Runner, error) {
|
||||||
|
|||||||
@@ -14,12 +14,12 @@ import (
|
|||||||
|
|
||||||
"github.com/Sirupsen/logrus"
|
"github.com/Sirupsen/logrus"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
uuid "github.com/satori/go.uuid"
|
||||||
"gitlab.oracledx.com/odx/functions/api"
|
"gitlab.oracledx.com/odx/functions/api"
|
||||||
"gitlab.oracledx.com/odx/functions/api/models"
|
"gitlab.oracledx.com/odx/functions/api/models"
|
||||||
"gitlab.oracledx.com/odx/functions/api/runner"
|
"gitlab.oracledx.com/odx/functions/api/runner"
|
||||||
"gitlab.oracledx.com/odx/functions/api/runner/task"
|
|
||||||
"gitlab.oracledx.com/odx/functions/api/runner/common"
|
"gitlab.oracledx.com/odx/functions/api/runner/common"
|
||||||
uuid "github.com/satori/go.uuid"
|
"gitlab.oracledx.com/odx/functions/api/runner/task"
|
||||||
)
|
)
|
||||||
|
|
||||||
type runnerResponse struct {
|
type runnerResponse struct {
|
||||||
@@ -162,13 +162,14 @@ func (s *Server) serve(ctx context.Context, c *gin.Context, appName string, foun
|
|||||||
var stdout bytes.Buffer // TODO: should limit the size of this, error if gets too big. akin to: https://golang.org/pkg/io/#LimitReader
|
var stdout bytes.Buffer // TODO: should limit the size of this, error if gets too big. akin to: https://golang.org/pkg/io/#LimitReader
|
||||||
|
|
||||||
envVars := map[string]string{
|
envVars := map[string]string{
|
||||||
"METHOD": c.Request.Method,
|
"METHOD": c.Request.Method,
|
||||||
"ROUTE": found.Path,
|
"ROUTE": found.Path,
|
||||||
"REQUEST_URL": fmt.Sprintf("%v//%v%v", func() string {
|
"REQUEST_URL": fmt.Sprintf("%v//%v%v", func() string {
|
||||||
if c.Request.TLS == nil {
|
if c.Request.TLS == nil {
|
||||||
return "http"
|
return "http"
|
||||||
}
|
}
|
||||||
return "https"}(), c.Request.Host, c.Request.URL.String()),
|
return "https"
|
||||||
|
}(), c.Request.Host, c.Request.URL.String()),
|
||||||
}
|
}
|
||||||
|
|
||||||
// app config
|
// app config
|
||||||
@@ -190,18 +191,26 @@ func (s *Server) serve(ctx context.Context, c *gin.Context, appName string, foun
|
|||||||
}
|
}
|
||||||
|
|
||||||
cfg := &task.Config{
|
cfg := &task.Config{
|
||||||
AppName: appName,
|
AppName: appName,
|
||||||
Path: found.Path,
|
Path: found.Path,
|
||||||
Env: envVars,
|
Env: envVars,
|
||||||
Format: found.Format,
|
Format: found.Format,
|
||||||
ID: reqID,
|
ID: reqID,
|
||||||
Image: found.Image,
|
Image: found.Image,
|
||||||
MaxConcurrency: found.MaxConcurrency,
|
MaxConcurrency: found.MaxConcurrency,
|
||||||
Memory: found.Memory,
|
Memory: found.Memory,
|
||||||
Stdin: payload,
|
Stdin: payload,
|
||||||
Stdout: &stdout,
|
Stdout: &stdout,
|
||||||
Timeout: time.Duration(found.Timeout) * time.Second,
|
Timeout: time.Duration(found.Timeout) * time.Second,
|
||||||
IdleTimeout: time.Duration(found.IdleTimeout) * time.Second,
|
IdleTimeout: time.Duration(found.IdleTimeout) * time.Second,
|
||||||
|
}
|
||||||
|
|
||||||
|
// ensure valid values
|
||||||
|
if cfg.Timeout <= 0 {
|
||||||
|
cfg.Timeout = DefaultTimeout
|
||||||
|
}
|
||||||
|
if cfg.IdleTimeout <= 0 {
|
||||||
|
cfg.IdleTimeout = DefaultIdleTimeout
|
||||||
}
|
}
|
||||||
|
|
||||||
s.Runner.Enqueue()
|
s.Runner.Enqueue()
|
||||||
|
|||||||
@@ -1,22 +1,19 @@
|
|||||||
# Oracle Functions Documentation
|
# Oracle Functions Documentation
|
||||||
|
|
||||||
* [FAQ](faq.md)
|
|
||||||
|
|
||||||
## For Developers
|
## For Developers
|
||||||
|
|
||||||
If you are a developer using Oracle Functions through the API, this section is for you.
|
If you are a developer using Oracle Functions through the API, this section is for you.
|
||||||
|
|
||||||
* [Quickstart](https://github.com/treeder/functions#quickstart)
|
* [Quickstart](https://github.com/treeder/functions#quickstart)
|
||||||
* [Usage](usage.md)
|
* [Usage](usage.md)
|
||||||
* [Definitions](definitions.md)
|
|
||||||
* [fn (CLI Tool)](/fn/README.md)
|
|
||||||
* [Writing functions](writing.md)
|
* [Writing functions](writing.md)
|
||||||
* [Writing Lambda functions](lambda/README.md)
|
* [fn (CLI Tool)](/fn/README.md)
|
||||||
* [Function file (func.yaml)](function-file.md)
|
* [Function file (func.yaml)](function-file.md)
|
||||||
* [Packaging functions](packaging.md)
|
* [Packaging functions](packaging.md)
|
||||||
* [Open Function Format](function-format.md)
|
* [Open Function Format](function-format.md)
|
||||||
* [API Reference](http://petstore.swagger.io/?url=https://raw.githubusercontent.com/treeder/functions/master/docs/swagger.yml)
|
* [API Reference](http://petstore.swagger.io/?url=https://raw.githubusercontent.com/treeder/functions/master/docs/swagger.yml)
|
||||||
* [Hot functions](hot-functions.md)
|
* [Hot functions](hot-functions.md)
|
||||||
|
* [FAQ](faq.md)
|
||||||
|
|
||||||
## For Operators
|
## For Operators
|
||||||
|
|
||||||
|
|||||||
@@ -45,6 +45,8 @@ Default: `sync`.
|
|||||||
function. If this function exceeds this limit during execution, it is stopped
|
function. If this function exceeds this limit during execution, it is stopped
|
||||||
and error message is logged. Default: `128`.
|
and error message is logged. Default: `128`.
|
||||||
|
|
||||||
|
`timeout` (optional) is the maximum time a function will be allowed to run. Default is 30 seconds.
|
||||||
|
|
||||||
`headers` (optional) is a set of HTTP headers to be returned in the response of
|
`headers` (optional) is a set of HTTP headers to be returned in the response of
|
||||||
this function calls.
|
this function calls.
|
||||||
|
|
||||||
@@ -61,6 +63,9 @@ hot functions support also adds two extra options to this configuration file.
|
|||||||
|
|
||||||
`format` (optional) is one of the streaming formats covered at [function-format.md](function-format.md).
|
`format` (optional) is one of the streaming formats covered at [function-format.md](function-format.md).
|
||||||
|
|
||||||
|
`idle_timeout` (optional) is the time in seconds a container will remain alive without receiving any new requests;
|
||||||
|
hot functions will stay alive as long as they receive a request in this interval. Default: `30`.
|
||||||
|
|
||||||
`max_concurrency` (optional) is the maximum of hot functions per node to be
|
`max_concurrency` (optional) is the maximum of hot functions per node to be
|
||||||
started for a certain function. It defaults to one per function. If you
|
started for a certain function. It defaults to one per function. If you
|
||||||
understand you need more processing power, make sure to raise this number.
|
understand you need more processing power, make sure to raise this number.
|
||||||
|
|||||||
@@ -13,3 +13,5 @@ fn init --runtime lambda-node <DOCKER_HUB_USERNAME>/lambda-node
|
|||||||
```
|
```
|
||||||
|
|
||||||
Be sure the filename for your main handler is `func.js`.
|
Be sure the filename for your main handler is `func.js`.
|
||||||
|
|
||||||
|
TODO: Make Java and Python use the new workflow too.
|
||||||
|
|||||||
@@ -1,48 +0,0 @@
|
|||||||
|
|
||||||
|
|
||||||
AWS Lambda introduced serverless computing to the masses. Wouldn't it be nice
|
|
||||||
if you could run the same Lambda functions on any platform, in any cloud?
|
|
||||||
Oracle is proud to release a set of tools that allow just this. Package your
|
|
||||||
Lambda function in a Docker container and run it anywhere with an environment
|
|
||||||
similar to AWS Lambda.
|
|
||||||
|
|
||||||
Using a job scheduler such as Oracle Functions, you can connect these functions to
|
|
||||||
webhooks and run them on-demand, at scale. You can also use a container
|
|
||||||
management system paired with a task queue to run these functions in
|
|
||||||
a self-contained, platform-independent manner.
|
|
||||||
|
|
||||||
## Use cases
|
|
||||||
|
|
||||||
Lambda functions are great for writing "worker" processes that perform some
|
|
||||||
simple, parallelizable task like image processing, ETL transformations,
|
|
||||||
asynchronous operations driven by Web APIs, or large batch processing.
|
|
||||||
|
|
||||||
All the benefits that containerization brings apply here. Our tools make it
|
|
||||||
easy to write containerized applications that will run anywhere without having
|
|
||||||
to fiddle with Docker and get the various runtimes set up. Instead you can just
|
|
||||||
write a simple function and have an "executable" ready to go.
|
|
||||||
|
|
||||||
## How does it work?
|
|
||||||
|
|
||||||
We provide base Docker images for the various runtimes that AWS Lambda
|
|
||||||
supports. The `fn` tool helps package up your Lambda function into
|
|
||||||
a Docker image layered on the base image. We provide a bootstrap script and
|
|
||||||
utilities that provide a AWS Lambda environment to your code. You can then run
|
|
||||||
the Docker image on any platform that supports Docker. This allows you to
|
|
||||||
easily move Lambda functions to any cloud provider, or host it yourself.
|
|
||||||
|
|
||||||
## Next steps
|
|
||||||
|
|
||||||
Write, package and run your Lambda functions with our [Getting started
|
|
||||||
guide](./getting-started.md). [Here is the environment](./environment.md) that
|
|
||||||
Lambda provides. `fn lambda` lists the commands to work with Lambda
|
|
||||||
functions locally.
|
|
||||||
|
|
||||||
You can [import](./import.md) existing Lambda functions hosted on Amazon!
|
|
||||||
The Docker environment required to run Lambda functions is described
|
|
||||||
[here](./docker.md).
|
|
||||||
|
|
||||||
Non-AWS Lambda functions can continue to interact with AWS services. [Working
|
|
||||||
with AWS](./aws.md) describes how to access AWS credentials, interact with
|
|
||||||
services like S3 and how to launch a Lambda function due a notification from
|
|
||||||
SNS.
|
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
# OUT OF DATE - NEEDS TO BE UPDATED
|
||||||
|
|
||||||
Interacting with AWS Services
|
Interacting with AWS Services
|
||||||
=============================
|
=============================
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
# OUT OF DATE - NEEDS TO BE UPDATED
|
||||||
|
|
||||||
# Creating Docker images out of Lambda functions
|
# Creating Docker images out of Lambda functions
|
||||||
|
|
||||||
Docker images created by running the `create-function` subcommand on a Lambda function are ready to execute.
|
Docker images created by running the `create-function` subcommand on a Lambda function are ready to execute.
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
# OUT OF DATE - NEEDS TO BE UPDATED
|
||||||
|
|
||||||
Import existing AWS Lambda functions
|
Import existing AWS Lambda functions
|
||||||
====================================
|
====================================
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
# OUT OF DATE - NEEDS TO BE UPDATED
|
||||||
|
|
||||||
# Testing the Lambda Docker images
|
# Testing the Lambda Docker images
|
||||||
|
|
||||||
The `test-function` subcommand can pass the correct parameters to `docker run`
|
The `test-function` subcommand can pass the correct parameters to `docker run`
|
||||||
|
|||||||
@@ -1,15 +1,18 @@
|
|||||||
# Packaging your Function
|
# Packaging your Function
|
||||||
|
|
||||||
|
## Option 1 (recommended): Use the `fn` cli tool
|
||||||
|
|
||||||
|
We recommend using the [fn cli tool](../fn/README.md) which will handle all of this for you. But if you'd like to dig in
|
||||||
|
and customize your images, look at Option 2.
|
||||||
|
|
||||||
|
## Option 2: Build your own images
|
||||||
|
|
||||||
Packaging a function has two parts:
|
Packaging a function has two parts:
|
||||||
|
|
||||||
* Create a Docker image for your function with an ENTRYPOINT
|
* Create a Docker image for your function with an ENTRYPOINT
|
||||||
* Push your Docker image to a registry (Docker Hub by default)
|
* Push your Docker image to a registry (Docker Hub by default)
|
||||||
|
|
||||||
Once it's pushed to a registry, you can use it by referencing it when adding a route.
|
Once it's pushed to a registry, you can use the image location when adding a route.
|
||||||
|
|
||||||
## Using fn
|
|
||||||
|
|
||||||
This is the easiest way to build, package and deploy your functions.
|
|
||||||
|
|
||||||
### Creating an image
|
### Creating an image
|
||||||
|
|
||||||
@@ -17,7 +20,7 @@ The basic Dockerfile for most languages is along these lines:
|
|||||||
|
|
||||||
```
|
```
|
||||||
# Choose base image
|
# Choose base image
|
||||||
FROM golang:alpine
|
FROM funcy/node:dev
|
||||||
# Set the working directory
|
# Set the working directory
|
||||||
WORKDIR /function
|
WORKDIR /function
|
||||||
# Add your binary or code to the working directory
|
# Add your binary or code to the working directory
|
||||||
@@ -26,29 +29,16 @@ ADD funcbin /function/
|
|||||||
ENTRYPOINT ["./funcbin"]
|
ENTRYPOINT ["./funcbin"]
|
||||||
```
|
```
|
||||||
|
|
||||||
Then you simply build your function:
|
Then build your function image:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
docker run --rm -v ${pwd}:/go/src/$FUNCPKG -w /go/src/$FUNCPKG funcy/go:dev go build -o funcbin
|
|
||||||
docker build -t $USERNAME/myfunction .
|
docker build -t $USERNAME/myfunction .
|
||||||
```
|
```
|
||||||
|
|
||||||
Or using [fn](../fn/README.md):
|
|
||||||
|
|
||||||
```sh
|
|
||||||
fn build
|
|
||||||
```
|
|
||||||
|
|
||||||
### Push your image
|
### Push your image
|
||||||
|
|
||||||
This part is simple:
|
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
docker push $USERNAME/myfunction
|
docker push $USERNAME/myfunction
|
||||||
```
|
```
|
||||||
|
|
||||||
Or using [fn](../fn/README.md):
|
Now you can use that image when creating or updating routes.
|
||||||
|
|
||||||
```sh
|
|
||||||
fn push
|
|
||||||
```
|
|
||||||
|
|||||||
@@ -18,9 +18,9 @@ body = JSON.parse(STDIN)
|
|||||||
# Do something
|
# Do something
|
||||||
return_struct = doSomething(body)
|
return_struct = doSomething(body)
|
||||||
|
|
||||||
# Respond if sync:
|
# If sync, respond:
|
||||||
STDOUT.write(JSON.generate(return_struct))
|
STDOUT.write(JSON.generate(return_struct))
|
||||||
# or update something if async
|
# If async, update something:
|
||||||
db.update(return_struct)
|
db.update(return_struct)
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -66,7 +66,24 @@ In Ruby:
|
|||||||
STDERR.puts("hi")
|
STDERR.puts("hi")
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Using Lambda Functions
|
||||||
|
|
||||||
|
### Lambda everywhere
|
||||||
|
|
||||||
|
Lambda support for Oracle Functios enables you to take your AWS Lambda functions and run them
|
||||||
|
anywhere. You should be able to take your code and run them without any changes.
|
||||||
|
|
||||||
|
Creating Lambda functions is not much different than using regular functions, just use
|
||||||
|
the `lambda-node` runtime.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
fn init --runtime lambda-node <DOCKER_HUB_USERNAME>/lambda-node
|
||||||
|
```
|
||||||
|
|
||||||
|
Be sure the filename for your main handler is `func.js`.
|
||||||
|
|
||||||
|
TODO: Make Java and Python use the new workflow too.
|
||||||
|
|
||||||
## Next Steps
|
## Next Steps
|
||||||
|
|
||||||
* [Packaging your function](packaging.md)
|
* [Packaging your function](packaging.md)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user