fnproject / fn
- среда, 4 октября 2017 г. в 03:13:55
The container native, cloud agnostic serverless platform.
Fn is an event-driven, open source, functions-as-a-service compute platform that you can run anywhere. Some of it's key features:
docker loginThe command line tool isn't required, but it sure makes things a lot easier. There are a few options to install it:
If you're on a Mac and use Homebrew, this one is for you:
brew install fnThis one works on Linux and MacOS (partially on Windows):
curl -LSs https://raw.githubusercontent.com/fnproject/cli/master/install | shThis will download a shell script and execute it. If the script asks for a password, that is because it invokes sudo.
Head over to our releases and download it.
Now fire up an Fn server:
fn startThis will start Fn in single server mode, using an embedded database and message queue. You can find all the configuration options here. If you are on Windows, check here.
Functions are small but powerful blocks of code that generally do one simple thing. Forget about monoliths when using functions, just focus on the task that you want the function to perform.
First, create an empty directory called hello and cd into it.
The following is a simple Go program that outputs a string to STDOUT. Copy and paste the code below into a file called func.go.
package main
import (
"fmt"
)
func main() {
fmt.Println("Hello from Fn!")
}Now run the following CLI commands:
# Initialize your function
# This detects your runtime from the code above and creates a func.yaml
fn init
# Set your Docker Hub username
export FN_REGISTRY=<DOCKERHUB_USERNAME>
# Test your function
# This will run inside a container exactly how it will on the server
fn run
# Deploy your functions to the Fn server (default localhost:8080)
# This will create a route to your function as well
fn deploy --app myappNow you can call your function:
curl http://localhost:8080/r/myapp/hello
# or:
fn call myapp /helloOr in a browser: http://localhost:8080/r/myapp/hello
That's it! You just deployed your first function and called it. To update your function
you can update your code and run fn deploy myapp again.
fnCheck out this graphical user interface for Fn.
docker run --rm -it --link functions:api -p 4000:4000 -e "API_URL=http://api:8080" fnproject/uiFor more information, see: https://github.com/fnproject/ui
This tutorial will demonstrate some of the core Fn capabilities through a series of examples. We'll try to show examples in most major languages. This is a great Fn place to start!