Declarative application specifications for Fission (#422)

This change enables users to have declarative specifications for Fission resources. Users can specify their "app" in a set of spec files, and use a new fission CLI command to "apply" these specs to a running cluster.

The new "spec" CLI also includes archiving of local source files, and a file watcher that re-builds archives and uploads them on file changes, and a package build watcher that waits for package builds on the CLI. 

A "--spec" option is also added to "function create", and will be added to other resources in future changes.  This option causes a YAML to be outputted to the specs directory instead of the resource being created on the cluster.

The CLI "fission spec --help" outputs usage information.
This commit is contained in:
Soam Vasani
2018-02-05 21:58:44 -08:00
committed by GitHub
parent 6af13e7e29
commit 07c7b759d2
26 changed files with 2013 additions and 85 deletions
+11 -34
View File
@@ -1,40 +1,17 @@
# Go examples
# Hello World in Go on Fission
The `go` runtime uses the [`plugin` package](https://golang.org/pkg/plugin/) to dynamically load an HTTP handler.
## Requirements
First, set up your fission deployment with the go environment.
```
fission env create --name go-env --image fission/go-env:1.8.1
```
To ensure that you build functions using the same version as the
runtime, fission provides a docker image and helper script for
building functions.
## Example Usage
### hello.go
`hello.go` is an very basic HTTP handler returning `"Hello, World!"`.
`hello.go` is an very simple fission function that says "Hello, World!".
```bash
# Download the build helper script
$ curl https://raw.githubusercontent.com/fission/fission/master/environments/go/builder/go-function-build > go-function-build
$ chmod +x go-function-build
# This command creates the environment and function, and waits for the
# function build. Look at the YAML files in specs/ for details about
# how those are specified.
$ fission spec apply --wait
1 environment created
1 package created
1 function created
# Build the function as a plugin. Outputs result to 'function.so'
$ go-function-build hello.go
# Upload the function to fission
$ fission function create --name hello --env go-env --package function.so
# Map /hello to the hello function
$ fission route create --method GET --url /hello --function hello
# Run the function
$ curl http://$FISSION_ROUTER/hello
# This run the function and prints its output
$ fission function test --name hello
Hello, World!
```
+2 -1
View File
@@ -4,7 +4,8 @@ import (
"net/http"
)
// Handler is the entry point for this fission function
func Handler(w http.ResponseWriter, r *http.Request) {
msg := "Hello, World!"
msg := "Hello, world!\n"
w.Write([]byte(msg))
}
+12
View File
@@ -0,0 +1,12 @@
apiVersion: fission.io/v1
kind: Environment
metadata:
name: go
namespace: default
spec:
version: 2
builder:
command: build
image: fission/go-build-env:20171206-2
runtime:
image: fission/go-env:20171206
@@ -0,0 +1,6 @@
# This file is generated by the 'fission spec init' command.
# See the README in this directory for background and usage information.
# Do not edit the UID below: that will break 'fission spec apply'
kind: DeploymentConfig
name: hello-go
uid: a8cdb63c-9be8-4a59-9427-89051afecd7b
+38
View File
@@ -0,0 +1,38 @@
kind: ArchiveUploadSpec
name: hello-go
include:
- hello.go
---
apiVersion: fission.io/v1
kind: Package
metadata:
creationTimestamp: null
name: hello-go-pkg
namespace: default
spec:
environment:
name: go
namespace: default
source:
type: url
url: archive://hello-go
status:
buildstatus: pending
---
apiVersion: fission.io/v1
kind: Function
metadata:
creationTimestamp: null
name: hello-go
namespace: default
spec:
environment:
name: go
namespace: default
package:
functionName: Handler
packageref:
name: hello-go-pkg
namespace: default
+11
View File
@@ -0,0 +1,11 @@
This is the root directory of a declaratively specified fission "application". The app
contains source code for one function (a simple "hello world") in the hello/hello.py
file.
The `specs` directory contains YAML files that specify the Fission environment and
function.
You can create this app on your cluster by running `fission spec apply` from this
directory. See `fission spec --help` for other options.
After applying the spec, you can test the function with `fission fn test --name hello`.
+9
View File
@@ -0,0 +1,9 @@
#!/bin/sh
set -e
# check syntax
python -m compileall -l ${SRC_PKG}
# install deps
pip install -r ${SRC_PKG}/requirements.txt -t ${SRC_PKG} && cp -r ${SRC_PKG} ${DEPLOY_PKG}
+4
View File
@@ -0,0 +1,4 @@
import yaml
def main():
return "hello, world!!\n"
@@ -0,0 +1 @@
pyyaml
+12
View File
@@ -0,0 +1,12 @@
apiVersion: fission.io/v1
kind: Environment
metadata:
name: python-27
namespace: default
spec:
version: 2
builder:
command: build
image: fission/python-build-env-2.7:0.4.0rc
runtime:
image: fission/python-env-2.7:0.4.0rc
@@ -0,0 +1,3 @@
kind: DeploymentConfig
name: spec-example
uid: 27438a48-4191-4b5e-95b2-7793624317b9
+38
View File
@@ -0,0 +1,38 @@
apiVersion: fission.io/v1
kind: Function
metadata:
name: hello
namespace: default
spec:
environment:
name: python-27
namespace: default
package:
packageref:
name: hello-pkg
namespace: default
functionName: hello.main
---
apiVersion: fission.io/v1
kind: Package
metadata:
name: hello-pkg
namespace: default
spec:
source:
url: archive://hello-archive
buildcmd: "./build.sh"
environment:
name: python-27
namespace: default
status:
buildstatus: pending
---
kind: ArchiveUploadSpec
name: hello-archive
include:
- "hello/*.py"
- "hello/*.sh"
- "hello/requirements.txt"