Moving out Environments to own repo (#1810)
Moved out environments and examples out of main Fission repo to their own repo. This is to allow changes to environment releases to be independent of main Fission releases.
This commit is contained in:
@@ -1,80 +0,0 @@
|
||||
# Binary Environment Examples
|
||||
|
||||
The `binary` runtime is a go server that uses a subprocess to invoke executables or execute shell scripts.
|
||||
|
||||
For more info read the [environment README](../../environments/binary/README.md).
|
||||
|
||||
## Requirements
|
||||
|
||||
First, set up your fission deployment with the binary environment.
|
||||
|
||||
```bash
|
||||
fission env create --name binary-env --image fission/binary-env
|
||||
```
|
||||
|
||||
## Example Usage
|
||||
|
||||
### hello.sh
|
||||
`hello.sh` is an very basic shell script that returns `"Hello, World!"`.
|
||||
|
||||
```bash
|
||||
# Upload the function to fission
|
||||
fission function create --name hello --env binary-env --code hello.sh
|
||||
|
||||
# Map /hello to the hello function
|
||||
fission route create --method GET --url /hello --function hello
|
||||
|
||||
# Run the function
|
||||
curl http://$FISSION_ROUTER/hello
|
||||
```
|
||||
|
||||
This should return a HTTP response with the body `Hello World!`
|
||||
|
||||
### echo.sh
|
||||
`echo.sh` shows the the use of STDIN to read the request body, echoing the input back in the response.
|
||||
|
||||
```bash
|
||||
# Upload the function to fission
|
||||
fission function create --name echo --env binary-env --code echo.sh
|
||||
|
||||
# Map /hello to the hello function
|
||||
fission route create --method POST --url /echo --function echo
|
||||
|
||||
# Run the function
|
||||
curl -XPOST -d 'Echoooooo!' http://$FISSION_ROUTER/echo
|
||||
```
|
||||
This should return a HTTP response with the body `... Echoooooo!`.
|
||||
|
||||
|
||||
### headers.sh
|
||||
`headers.sh` shows the access to the environment variables that hold the HTTP headers, returning the set HTTP headers.
|
||||
|
||||
```bash
|
||||
# Upload the function to fission
|
||||
fission function create --name headers --env binary-env --code headers.sh
|
||||
|
||||
# Map /hello to the hello function
|
||||
fission route create --url /headers --function headers
|
||||
|
||||
# Run the function
|
||||
curl -H 'X-FOO: BAR' http://$FISSION_ROUTER/headers
|
||||
```
|
||||
This should return a HTTP response with the body `... Echoooooo!`.
|
||||
|
||||
### hello..go
|
||||
This example shows the differences between using shell scripts and binaries. `hello.go` returns `Hello World!` + the
|
||||
environment variables it received from the server.
|
||||
|
||||
```bash
|
||||
# Build the function targeted at the right architecture
|
||||
GOOS=linux GOARCH=386 go build -o hello-go-func hello.go
|
||||
|
||||
# Upload the function to fission
|
||||
fission function create --name hello-go --env binary-env --code hello-go-func
|
||||
|
||||
# Map /hello to the hello function
|
||||
fission route create --url /hello-go --function hello-go
|
||||
|
||||
# Run the function
|
||||
curl -H 'X-GO: AWESOME!' http://$FISSION_ROUTER/hello-go
|
||||
```
|
||||
@@ -1,4 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
printf "... "
|
||||
cat -
|
||||
@@ -1,3 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
env | grep "^HTTP_"
|
||||
@@ -1,12 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
// See README.md in the examples/binary directory for instructions
|
||||
func main() {
|
||||
fmt.Println("Hello World!")
|
||||
fmt.Printf("Environment: %v", os.Environ())
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
echo "Hello World!"
|
||||
@@ -1,11 +0,0 @@
|
||||
using System;
|
||||
using Fission.DotNetCore.Api;
|
||||
|
||||
public class FissionFunction
|
||||
{
|
||||
public string Execute(FissionContext context){
|
||||
var x = Convert.ToInt32(context.Arguments["x"]);
|
||||
var y = Convert.ToInt32(context.Arguments["y"]);
|
||||
return (x+y).ToString();
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
using Fission.DotNetCore.Api;
|
||||
|
||||
public class FissionFunction
|
||||
{
|
||||
public string Execute(FissionContext context)
|
||||
{
|
||||
return "Hello World!";
|
||||
}
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
using System.IO;
|
||||
using System.Runtime.Serialization.Json;
|
||||
using Fission.DotNetCore.Api;
|
||||
|
||||
public class FissionFunction
|
||||
{
|
||||
public string Execute(FissionContext context)
|
||||
{
|
||||
var person = Person.Deserialize(context.Request.Body);
|
||||
return $"Hello, my name is {person.Name} and I am {person.Age} years old.";
|
||||
}
|
||||
}
|
||||
|
||||
public class Person
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public int Age { get; set; }
|
||||
|
||||
public static Person Deserialize(Stream json)
|
||||
{
|
||||
var serializer = new DataContractJsonSerializer(typeof(Person));
|
||||
return (Person)serializer.ReadObject(json);
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
using System;
|
||||
using Fission.DotNetCore.Api;
|
||||
|
||||
public class FissionFunction
|
||||
{
|
||||
public string Execute(FissionContext context){
|
||||
var buffer = new System.Text.StringBuilder();
|
||||
foreach(var header in context.Request.Headers){
|
||||
buffer.AppendLine(header.Key);
|
||||
foreach(var item in header.Value){
|
||||
buffer.AppendLine($"\t{item}");
|
||||
}
|
||||
}
|
||||
buffer.AppendLine($"Url: {context.Request.Url}, method: {context.Request.Method}");
|
||||
return buffer.ToString();
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
using System;
|
||||
using Fission.DotNetCore.Api;
|
||||
|
||||
public class FissionFunction
|
||||
{
|
||||
public string Execute(FissionContext context){
|
||||
var x = Convert.ToInt32(context.Arguments["x"]);
|
||||
var y = Convert.ToInt32(context.Arguments["y"]);
|
||||
return (x+y).ToString();
|
||||
}
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
using System;
|
||||
using Fission.DotNetCore.Api;
|
||||
|
||||
public class FissionFunction
|
||||
{
|
||||
public string Execute(FissionContext context){
|
||||
context.Logger.WriteInfo("executing.. {0}", context.Arguments["text"]);
|
||||
return (string)context.Arguments["text"];
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
using Fission.DotNetCore.Api;
|
||||
|
||||
public class FissionFunction
|
||||
{
|
||||
public string Execute(FissionContext context)
|
||||
{
|
||||
return "Hello World!";
|
||||
}
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
using System.IO;
|
||||
using System.Runtime.Serialization.Json;
|
||||
using Fission.DotNetCore.Api;
|
||||
|
||||
public class FissionFunction
|
||||
{
|
||||
public string Execute(FissionContext context)
|
||||
{
|
||||
var person = Person.Deserialize(context.Request.Body);
|
||||
return $"Hello, my name is {person.Name} and I am {person.Age} years old.";
|
||||
}
|
||||
}
|
||||
|
||||
public class Person
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public int Age { get; set; }
|
||||
|
||||
public static Person Deserialize(Stream json)
|
||||
{
|
||||
var serializer = new DataContractJsonSerializer(typeof(Person));
|
||||
return (Person)serializer.ReadObject(json);
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
using System;
|
||||
using Fission.DotNetCore.Api;
|
||||
|
||||
public class FissionFunction
|
||||
{
|
||||
public string Execute(FissionContext context){
|
||||
var buffer = new System.Text.StringBuilder();
|
||||
foreach(var header in context.Request.Headers){
|
||||
buffer.AppendLine(header.Key);
|
||||
foreach(var item in header.Value){
|
||||
buffer.AppendLine($"\t{item}");
|
||||
}
|
||||
}
|
||||
buffer.AppendLine($"Url: {context.Request.Url}, method: {context.Request.Method}");
|
||||
return buffer.ToString();
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
# Hello World in Go on Fission
|
||||
|
||||
`hello.go` contains a very simple fission function that says "Hello, World!".
|
||||
|
||||
## Deploying this function on your cluster
|
||||
|
||||
```bash
|
||||
|
||||
# Create the Fission Go environment and function, and wait for the
|
||||
# function to build. (Take a look at the YAML files in the specs
|
||||
# directory for details about how the environment and function are
|
||||
# specified.)
|
||||
|
||||
$ fission spec apply --wait
|
||||
1 environment created
|
||||
1 package created
|
||||
1 function created
|
||||
|
||||
# Now, run the function with the "fission function test" command:
|
||||
|
||||
$ fission function test --name hello-go
|
||||
Hello, World!
|
||||
```
|
||||
@@ -1,11 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Handler is the entry point for this fission function
|
||||
func Handler(w http.ResponseWriter, r *http.Request) {
|
||||
msg := "Hello, world!\n"
|
||||
w.Write([]byte(msg))
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
# Go module usage
|
||||
|
||||
1. Initialize your project
|
||||
|
||||
```bash
|
||||
$ go mod init "<module>"
|
||||
```
|
||||
|
||||
For example,
|
||||
|
||||
```bash
|
||||
$ go mod init "github.com/fission/fission/examples/go/go-module-example"
|
||||
```
|
||||
|
||||
2. Add dependencies
|
||||
|
||||
* See [here](https://github.com/golang/go/wiki/Modules#daily-workflow)
|
||||
|
||||
3. Verify
|
||||
|
||||
```bash
|
||||
$ go mod verify
|
||||
```
|
||||
|
||||
4. Archive and create package as usual
|
||||
|
||||
```bash
|
||||
$ zip -r go.zip .
|
||||
adding: go.mod (deflated 26%)
|
||||
adding: go.sum (deflated 1%)
|
||||
adding: README.md (deflated 37%)
|
||||
adding: main.go (deflated 30%)
|
||||
|
||||
$ fission pkg create --env go --src go.zip
|
||||
```
|
||||
@@ -1,3 +0,0 @@
|
||||
module github.com/fission/fission/examples/go/go-module-example
|
||||
|
||||
require github.com/golang/example v0.0.0-20170904185048-46695d81d1fa
|
||||
@@ -1 +0,0 @@
|
||||
github.com/golang/example v0.0.0-20170904185048-46695d81d1fa/go.mod h1:tO/5UvQ/uKigUjQBPqzstj6uxd3fUIjddi19DxGJeWg=
|
||||
@@ -1,13 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/golang/example/stringutil"
|
||||
)
|
||||
|
||||
// Handler is the entry point for this fission function
|
||||
func Handler(w http.ResponseWriter, r *http.Request) {
|
||||
msg := stringutil.Reverse(stringutil.Reverse("Vendor Example Test"))
|
||||
w.Write([]byte(msg))
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
apiVersion: fission.io/v1
|
||||
kind: Environment
|
||||
metadata:
|
||||
name: go
|
||||
namespace: default
|
||||
spec:
|
||||
version: 2
|
||||
builder:
|
||||
command: build
|
||||
image: fission/go-builder-1.12:1.5.0
|
||||
runtime:
|
||||
image: fission/go-env-1.12:1.5.0
|
||||
@@ -1,6 +0,0 @@
|
||||
# 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
|
||||
@@ -1,39 +0,0 @@
|
||||
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
|
||||
functionTimeout: 60
|
||||
package:
|
||||
functionName: Handler
|
||||
packageref:
|
||||
name: hello-go-pkg
|
||||
namespace: default
|
||||
@@ -1,4 +0,0 @@
|
||||
.project
|
||||
.settings
|
||||
.classpath
|
||||
target/
|
||||
@@ -1,60 +0,0 @@
|
||||
# Hello World in JVM/Java on Fission
|
||||
|
||||
The `io.fission.HelloWorld.java` class is a very simple fission function that implements `io.fission.Function` and says "Hello, World!" .
|
||||
|
||||
## Building and deploying using Fission
|
||||
|
||||
Fission's builder can be used to create the binary artifact from source code. Create an environment with builder image and then create a package.
|
||||
|
||||
```
|
||||
$ zip -r java-src-pkg.zip *
|
||||
$ fission env create --name java --image fission/jvm-env --version 2 --keeparchive --builder fission/jvm-builder
|
||||
$ fission package create --sourcearchive java-src-pkg.zip --env java
|
||||
java-src-pkg-zip-tvd0
|
||||
$ fission package info --name java-src-pkg-zip-tvd0
|
||||
Name: java-src-pkg-zip-tvd0
|
||||
Environment: java
|
||||
Status: succeeded
|
||||
Build Logs:
|
||||
[INFO] Scanning for projects...
|
||||
[INFO]
|
||||
[INFO] -----------------------< io.fission:hello-world >-----------------------
|
||||
[INFO] Building hello-world 1.0-SNAPSHOT
|
||||
[INFO] --------------------------------[ jar ]---------------------------------
|
||||
```
|
||||
|
||||
Once package's status is `succeeded` then that package can be used to create and execute a function.
|
||||
|
||||
```
|
||||
$ fission fn create --name hello --pkg java-src-pkg-zip-tvd0 --env java --entrypoint io.fission.HelloWorld
|
||||
$ fission fn test --name hello
|
||||
Hello World!
|
||||
```
|
||||
|
||||
## Building locally and deploying with Fission
|
||||
|
||||
You can build the jar file in one of the two ways below based on your setup:
|
||||
|
||||
- You can use docker without the need to install JDK and Maven to build the jar file from source code:
|
||||
|
||||
```bash
|
||||
$ bash -x ./build.sh
|
||||
|
||||
```
|
||||
- If you have JDK and Maven installed, you can directly build the JAR file using command:
|
||||
|
||||
```
|
||||
$ mvn clean package
|
||||
```
|
||||
|
||||
Both of above steps will generate a target subdirectory which has the archive `target/hello-world-1.0-SNAPSHOT-jar-with-dependencies.jar` which will be used for creating function.
|
||||
|
||||
- The archive created above will be used as a deploy package when creating the function.
|
||||
|
||||
```
|
||||
$ fission env create --name jvm --image fission/jvm-env --version 2 --keeparchive=true
|
||||
$ fission fn create --name hello --deploy target/hello-world-1.0-SNAPSHOT-jar-with-dependencies.jar --env jvm --entrypoint io.fission.HelloWorld
|
||||
$ fission route create --function hello --url /hellop --method GET
|
||||
$ fission fn test --name hello
|
||||
Hello World!
|
||||
```
|
||||
@@ -1,5 +0,0 @@
|
||||
#!/bin/sh
|
||||
# This script allows you to build the jar without needing Maven & JDK installed locally.
|
||||
# You need docker, as it uses a Docker image to build source code
|
||||
set -eou pipefail
|
||||
docker run -it --rm -v "$(pwd)":/usr/src/mymaven -w /usr/src/mymaven maven:3.5-jdk-8 mvn clean package
|
||||
@@ -1,76 +0,0 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>io.fission</groupId>
|
||||
<artifactId>jersey-hello-world</artifactId>
|
||||
<version>0.0.1</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>hello-world</name>
|
||||
<url>http://maven.apache.org</url>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.source>1.6</maven.compiler.source>
|
||||
<maven.compiler.target>1.6</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>io.fission</groupId>
|
||||
<artifactId>fission-jvm-jersey</artifactId>
|
||||
<version>0.0.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.ws.rs</groupId>
|
||||
<artifactId>javax.ws.rs-api</artifactId>
|
||||
<version>2.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.glassfish.jersey.containers</groupId>
|
||||
<artifactId>jersey-container-servlet-core</artifactId>
|
||||
<version>2.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.13</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<configuration>
|
||||
<descriptorRefs>
|
||||
<descriptorRef>jar-with-dependencies</descriptorRef>
|
||||
</descriptorRefs>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>make-assembly</id> <!-- this is used for inheritance merges -->
|
||||
<phase>package</phase> <!-- bind to the packaging phase -->
|
||||
<goals>
|
||||
<goal>single</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.22.1</version>
|
||||
<configuration>
|
||||
<useSystemClassLoader>false</useSystemClassLoader>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
@@ -1,42 +0,0 @@
|
||||
|
||||
Fission Specs
|
||||
=============
|
||||
|
||||
This is a set of specifications for a Fission app. This includes functions,
|
||||
environments, and triggers; we collectively call these things "resources".
|
||||
|
||||
How to use these specs
|
||||
----------------------
|
||||
|
||||
These specs are handled with the 'fission spec' command. See 'fission spec --help'.
|
||||
|
||||
'fission spec apply' will "apply" all resources specified in this directory to your
|
||||
cluster. That means it checks what resources exist on your cluster, what resources are
|
||||
specified in the specs directory, and reconciles the difference by creating, updating or
|
||||
deleting resources on the cluster.
|
||||
|
||||
'fission spec apply' will also package up your source code (or compiled binaries) and
|
||||
upload the archives to the cluster if needed. It uses 'ArchiveUploadSpec' resources in
|
||||
this directory to figure out which files to archive.
|
||||
|
||||
You can use 'fission spec apply --watch' to watch for file changes and continuously keep
|
||||
the cluster updated.
|
||||
|
||||
You can add YAMLs to this directory by writing them manually, but it's easier to generate
|
||||
them. Use 'fission function create --spec' to generate a function spec,
|
||||
'fission environment create --spec' to generate an environment spec, and so on.
|
||||
|
||||
You can edit any of the files in this directory, except 'fission-deployment-config.yaml',
|
||||
which contains a UID that you should never change. To apply your changes simply use
|
||||
'fission spec apply'.
|
||||
|
||||
fission-deployment-config.yaml
|
||||
------------------------------
|
||||
|
||||
fission-deployment-config.yaml contains a UID. This UID is what fission uses to correlate
|
||||
resources on the cluster to resources in this directory.
|
||||
|
||||
All resources created by 'fission spec apply' are annotated with this UID. Resources on
|
||||
the cluster that are _not_ annotated with this UID are never modified or deleted by
|
||||
fission.
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
apiVersion: fission.io/v1
|
||||
kind: Environment
|
||||
metadata:
|
||||
creationTimestamp: null
|
||||
name: java-jersey
|
||||
namespace: default
|
||||
spec:
|
||||
builder:
|
||||
command: build
|
||||
image: fission/jvm-jersey-builder
|
||||
imagepullsecret: ""
|
||||
keeparchive: true
|
||||
poolsize: 3
|
||||
resources: {}
|
||||
runtime:
|
||||
image: fission/jvm-jersey-env
|
||||
version: 2
|
||||
@@ -1,7 +0,0 @@
|
||||
# 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'
|
||||
apiVersion: fission.io/v1
|
||||
kind: DeploymentConfig
|
||||
name: java-jersey
|
||||
uid: 908a303a-bf23-4bae-a22c-b1db9a1f71a9
|
||||
@@ -1,27 +0,0 @@
|
||||
apiVersion: fission.io/v1
|
||||
kind: Function
|
||||
metadata:
|
||||
creationTimestamp: null
|
||||
name: hello
|
||||
namespace: default
|
||||
spec:
|
||||
InvokeStrategy:
|
||||
ExecutionStrategy:
|
||||
ExecutorType: poolmgr
|
||||
MaxScale: 0
|
||||
MinScale: 0
|
||||
SpecializationTimeout: 120
|
||||
TargetCPUPercent: 0
|
||||
StrategyType: execution
|
||||
configmaps: null
|
||||
environment:
|
||||
name: java-jersey
|
||||
namespace: default
|
||||
functionTimeout: 60
|
||||
package:
|
||||
functionName: io.fission.HelloWorld
|
||||
packageref:
|
||||
name: hellojava
|
||||
namespace: default
|
||||
resources: {}
|
||||
secrets: null
|
||||
@@ -1,26 +0,0 @@
|
||||
include:
|
||||
- src
|
||||
- pom.xml
|
||||
kind: ArchiveUploadSpec
|
||||
name: src-URlE
|
||||
|
||||
---
|
||||
apiVersion: fission.io/v1
|
||||
kind: Package
|
||||
metadata:
|
||||
creationTimestamp: null
|
||||
name: hellojavajersey
|
||||
namespace: default
|
||||
spec:
|
||||
deployment:
|
||||
checksum: {}
|
||||
environment:
|
||||
name: java-jersey
|
||||
namespace: default
|
||||
source:
|
||||
checksum: {}
|
||||
type: url
|
||||
url: archive://src-URlE
|
||||
status:
|
||||
buildstatus: pending
|
||||
lastUpdateTimestamp: "2020-01-29T09:43:56Z"
|
||||
@@ -1,25 +0,0 @@
|
||||
package io.fission;
|
||||
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.container.ContainerRequestContext;
|
||||
import io.fission.Function;
|
||||
import java.io.BufferedReader;
|
||||
import java.util.stream.Collectors;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
public class HelloWorld implements Function<ContainerRequestContext,Response> {
|
||||
|
||||
public static final String RETURN_STRING = "Hello World!";
|
||||
|
||||
@Override
|
||||
public Response call(ContainerRequestContext request, Context arg1) {
|
||||
if(request.getMethod().equals("GET")) {
|
||||
return Response.ok(RETURN_STRING).build();
|
||||
}
|
||||
else {
|
||||
String body = new BufferedReader(new InputStreamReader(request.getEntityStream())).lines()
|
||||
.parallel().collect(Collectors.joining("\n"));
|
||||
return Response.ok("Echo: " + body).build();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
package io.fission;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import org.glassfish.jersey.server.ContainerRequest;
|
||||
import javax.ws.rs.core.Response;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
public class HelloWorldTest {
|
||||
|
||||
@Test
|
||||
public void testResponse() {
|
||||
HelloWorld hw = new HelloWorld();
|
||||
ContainerRequest request = null;
|
||||
try {
|
||||
request = new ContainerRequest(new URI("http://example.com/"),new URI("/hello"),"GET",null,null);
|
||||
} catch (URISyntaxException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
Response response = hw.call(request, null);
|
||||
Assert.assertTrue(response.getEntity().toString().equals(HelloWorld.RETURN_STRING));
|
||||
}
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
.project
|
||||
.settings
|
||||
.classpath
|
||||
target/
|
||||
@@ -1,60 +0,0 @@
|
||||
# Hello World in JVM/Java on Fission
|
||||
|
||||
The `io.fission.HelloWorld.java` class is a very simple fission function that implements `io.fission.Function` and says "Hello, World!" .
|
||||
|
||||
## Building and deploying using Fission
|
||||
|
||||
Fission's builder can be used to create the binary artifact from source code. Create an environment with builder image and then create a package.
|
||||
|
||||
```
|
||||
$ zip -r java-src-pkg.zip *
|
||||
$ fission env create --name java --image fission/jvm-env --version 2 --keeparchive --builder fission/jvm-builder
|
||||
$ fission package create --sourcearchive java-src-pkg.zip --env java
|
||||
java-src-pkg-zip-tvd0
|
||||
$ fission package info --name java-src-pkg-zip-tvd0
|
||||
Name: java-src-pkg-zip-tvd0
|
||||
Environment: java
|
||||
Status: succeeded
|
||||
Build Logs:
|
||||
[INFO] Scanning for projects...
|
||||
[INFO]
|
||||
[INFO] -----------------------< io.fission:hello-world >-----------------------
|
||||
[INFO] Building hello-world 1.0-SNAPSHOT
|
||||
[INFO] --------------------------------[ jar ]---------------------------------
|
||||
```
|
||||
|
||||
Once package's status is `succeeded` then that package can be used to create and execute a function.
|
||||
|
||||
```
|
||||
$ fission fn create --name hello --pkg java-src-pkg-zip-tvd0 --env java --entrypoint io.fission.HelloWorld
|
||||
$ fission fn test --name hello
|
||||
Hello World!
|
||||
```
|
||||
|
||||
## Building locally and deploying with Fission
|
||||
|
||||
You can build the jar file in one of the two ways below based on your setup:
|
||||
|
||||
- You can use docker without the need to install JDK and Maven to build the jar file from source code:
|
||||
|
||||
```bash
|
||||
$ bash -x ./build.sh
|
||||
|
||||
```
|
||||
- If you have JDK and Maven installed, you can directly build the JAR file using command:
|
||||
|
||||
```
|
||||
$ mvn clean package
|
||||
```
|
||||
|
||||
Both of above steps will generate a target subdirectory which has the archive `target/hello-world-1.0-SNAPSHOT-jar-with-dependencies.jar` which will be used for creating function.
|
||||
|
||||
- The archive created above will be used as a deploy package when creating the function.
|
||||
|
||||
```
|
||||
$ fission env create --name jvm --image fission/jvm-env --version 2 --keeparchive=true
|
||||
$ fission fn create --name hello --deploy target/hello-world-1.0-SNAPSHOT-jar-with-dependencies.jar --env jvm --entrypoint io.fission.HelloWorld
|
||||
$ fission route create --function hello --url /hellop --method GET
|
||||
$ fission fn test --name hello
|
||||
Hello World!
|
||||
```
|
||||
@@ -1,5 +0,0 @@
|
||||
#!/bin/sh
|
||||
# This script allows you to build the jar without needing Maven & JDK installed locally.
|
||||
# You need docker, as it uses a Docker image to build source code
|
||||
set -eou pipefail
|
||||
docker run -it --rm -v "$(pwd)":/usr/src/mymaven -w /usr/src/mymaven maven:3.5-jdk-8 mvn clean package
|
||||
@@ -1,72 +0,0 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>io.fission</groupId>
|
||||
<artifactId>hello-world</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>hello-world</name>
|
||||
<url>http://maven.apache.org</url>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
<version>2.0.1.RELEASE</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.fission</groupId>
|
||||
<artifactId>fission-java-core</artifactId>
|
||||
<version>0.0.2-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<configuration>
|
||||
<descriptorRefs>
|
||||
<descriptorRef>jar-with-dependencies</descriptorRef>
|
||||
</descriptorRefs>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>make-assembly</id> <!-- this is used for inheritance merges -->
|
||||
<phase>package</phase> <!-- bind to the packaging phase -->
|
||||
<goals>
|
||||
<goal>single</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.22.1</version>
|
||||
<configuration>
|
||||
<useSystemClassLoader>false</useSystemClassLoader>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<!-- Adding Sonatype repository to pull snapshots -->
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>fission-java-core</id>
|
||||
<name>fission-java-core-snapshot</name>
|
||||
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
</project>
|
||||
@@ -1,42 +0,0 @@
|
||||
|
||||
Fission Specs
|
||||
=============
|
||||
|
||||
This is a set of specifications for a Fission app. This includes functions,
|
||||
environments, and triggers; we collectively call these things "resources".
|
||||
|
||||
How to use these specs
|
||||
----------------------
|
||||
|
||||
These specs are handled with the 'fission spec' command. See 'fission spec --help'.
|
||||
|
||||
'fission spec apply' will "apply" all resources specified in this directory to your
|
||||
cluster. That means it checks what resources exist on your cluster, what resources are
|
||||
specified in the specs directory, and reconciles the difference by creating, updating or
|
||||
deleting resources on the cluster.
|
||||
|
||||
'fission spec apply' will also package up your source code (or compiled binaries) and
|
||||
upload the archives to the cluster if needed. It uses 'ArchiveUploadSpec' resources in
|
||||
this directory to figure out which files to archive.
|
||||
|
||||
You can use 'fission spec apply --watch' to watch for file changes and continuously keep
|
||||
the cluster updated.
|
||||
|
||||
You can add YAMLs to this directory by writing them manually, but it's easier to generate
|
||||
them. Use 'fission function create --spec' to generate a function spec,
|
||||
'fission environment create --spec' to generate an environment spec, and so on.
|
||||
|
||||
You can edit any of the files in this directory, except 'fission-deployment-config.yaml',
|
||||
which contains a UID that you should never change. To apply your changes simply use
|
||||
'fission spec apply'.
|
||||
|
||||
fission-deployment-config.yaml
|
||||
------------------------------
|
||||
|
||||
fission-deployment-config.yaml contains a UID. This UID is what fission uses to correlate
|
||||
resources on the cluster to resources in this directory.
|
||||
|
||||
All resources created by 'fission spec apply' are annotated with this UID. Resources on
|
||||
the cluster that are _not_ annotated with this UID are never modified or deleted by
|
||||
fission.
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
apiVersion: fission.io/v1
|
||||
kind: Environment
|
||||
metadata:
|
||||
creationTimestamp: null
|
||||
name: java
|
||||
namespace: default
|
||||
spec:
|
||||
builder:
|
||||
command: build
|
||||
image: fission/jvm-builder:1.7.1
|
||||
imagepullsecret: ""
|
||||
keeparchive: true
|
||||
poolsize: 3
|
||||
resources: {}
|
||||
runtime:
|
||||
image: fission/jvm-env:1.7.1
|
||||
version: 2
|
||||
@@ -1,7 +0,0 @@
|
||||
# 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'
|
||||
apiVersion: fission.io/v1
|
||||
kind: DeploymentConfig
|
||||
name: java
|
||||
uid: 908a303a-bf23-4bae-a22c-b1db9a1f71a9
|
||||
@@ -1,27 +0,0 @@
|
||||
apiVersion: fission.io/v1
|
||||
kind: Function
|
||||
metadata:
|
||||
creationTimestamp: null
|
||||
name: hello
|
||||
namespace: default
|
||||
spec:
|
||||
InvokeStrategy:
|
||||
ExecutionStrategy:
|
||||
ExecutorType: poolmgr
|
||||
MaxScale: 0
|
||||
MinScale: 0
|
||||
SpecializationTimeout: 120
|
||||
TargetCPUPercent: 0
|
||||
StrategyType: execution
|
||||
configmaps: null
|
||||
environment:
|
||||
name: java
|
||||
namespace: default
|
||||
functionTimeout: 60
|
||||
package:
|
||||
functionName: io.fission.HelloWorld
|
||||
packageref:
|
||||
name: hellojava
|
||||
namespace: default
|
||||
resources: {}
|
||||
secrets: null
|
||||
@@ -1,26 +0,0 @@
|
||||
include:
|
||||
- src
|
||||
- pom.xml
|
||||
kind: ArchiveUploadSpec
|
||||
name: src-URlE
|
||||
|
||||
---
|
||||
apiVersion: fission.io/v1
|
||||
kind: Package
|
||||
metadata:
|
||||
creationTimestamp: null
|
||||
name: hellojava
|
||||
namespace: default
|
||||
spec:
|
||||
deployment:
|
||||
checksum: {}
|
||||
environment:
|
||||
name: java
|
||||
namespace: default
|
||||
source:
|
||||
checksum: {}
|
||||
type: url
|
||||
url: archive://src-URlE
|
||||
status:
|
||||
buildstatus: pending
|
||||
lastUpdateTimestamp: "2020-01-29T09:43:56Z"
|
||||
@@ -1,16 +0,0 @@
|
||||
package io.fission;
|
||||
|
||||
import org.springframework.http.RequestEntity;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
|
||||
import io.fission.Function;
|
||||
import io.fission.Context;
|
||||
|
||||
public class HelloWorld implements Function {
|
||||
|
||||
@Override
|
||||
public ResponseEntity<?> call(RequestEntity req, Context context) {
|
||||
return ResponseEntity.ok("Hello World!");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
package io.fission;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.RequestEntity;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
public class HelloWorldTest {
|
||||
|
||||
public void testResponse() {
|
||||
HelloWorld hw = new HelloWorld();
|
||||
RequestEntity request = null;
|
||||
try {
|
||||
request = RequestEntity.get(new URI("http://example.com/bar")).build();
|
||||
} catch (URISyntaxException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
ResponseEntity resp = hw.call(request, null);
|
||||
Assert.hasText(resp.getBody().toString(), "Hello World!");
|
||||
}
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
# Message Queue Trigger Demonstration - NATS Streaming
|
||||
|
||||
## Create spec
|
||||
|
||||
```bash
|
||||
$ fission spec init
|
||||
$ fission env create --name go --image fission/go-env-1.12:1.7.1 --builder fission/go-builder-1.12:1.7.1 --period 5 --spec
|
||||
$ fission pkg create --name publisher --src mqtrigger/* --spec
|
||||
$ fission fn create --name publisher --env go --pkg publisher --entrypoint "Handler" --spec
|
||||
$ fission fn create --name hello --env go --src https://raw.githubusercontent.com/fission/fission/master/examples/go/hello.go --entrypoint "Handler" --spec
|
||||
$ fission mqt create --name mqtrigger --function hello --mqtype nats-streaming --topic foobar --spec
|
||||
```
|
||||
|
||||
## Apply CRDs
|
||||
|
||||
```bash
|
||||
$ fission spec apply
|
||||
|
||||
# wait for package build status become succeeded
|
||||
$ fission pkg list
|
||||
NAME BUILD_STATUS ENV LASTUPDATEDAT
|
||||
hello-98476132-84ff-4e74-8b0f-2d1005871d1c succeeded go 19 Dec 19 17:31 UTC
|
||||
publisher succeeded go 19 Dec 19 17:19 UTC
|
||||
|
||||
# you can rebuild the package if it shows failed
|
||||
$ fission pkg rebuild --name <pkg-name>
|
||||
|
||||
$ fission fn test --name publisher
|
||||
Publish Success
|
||||
|
||||
$ kubectl -n fission-function get pod -l functionName=hello
|
||||
NAME READY STATUS RESTARTS AGE
|
||||
poolmgr-go-default-610954-55664ccc68-b258c 2/2 Running 0 18m
|
||||
|
||||
# you should be able to see the function prints message
|
||||
$ kubectl -n fission-function logs -f -c go poolmgr-go-default-610954-55664ccc68-b258c
|
||||
{"level":"info","ts":1576775701.7085218,"caller":"go/server.go:209","msg":"listening on 8888 ..."}
|
||||
{"level":"info","ts":1576776720.3545933,"logger":"specialize_v2_handler","caller":"go/server.go:171","msg":"specializing ..."}
|
||||
{"level":"info","ts":1576776720.3546736,"logger":"specialize_v2_handler","caller":"go/server.go:62","msg":"loading plugin","location":"/userfunc/15382797-f381-48af-9189-561f45f9285c/hello-98476132-84ff-4e74-8b0f-2d1005871d1c-7693uh-pwsz5u"}
|
||||
{"level":"info","ts":1576776720.3640525,"logger":"specialize_v2_handler","caller":"go/server.go:180","msg":"done"}
|
||||
2019/12/19 17:32:00 Hello, world!
|
||||
```
|
||||
@@ -1,13 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Handler is the entry point for this fission function
|
||||
func Handler(w http.ResponseWriter, r *http.Request) {
|
||||
log.Print("Hello, world!")
|
||||
msg := "Hello, world!\n"
|
||||
w.Write([]byte(msg))
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
module github.com/fission/mqtrigger
|
||||
|
||||
go 1.12
|
||||
|
||||
require (
|
||||
github.com/golang/protobuf v1.3.3 // indirect
|
||||
github.com/kr/pretty v0.2.0 // indirect
|
||||
github.com/nats-io/nats-streaming-server v0.17.0 // indirect
|
||||
github.com/nats-io/stan.go v0.6.0
|
||||
github.com/satori/go.uuid v1.2.0
|
||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
|
||||
)
|
||||
@@ -1,104 +0,0 @@
|
||||
github.com/DataDog/datadog-go v2.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ=
|
||||
github.com/armon/go-metrics v0.0.0-20190430140413-ec5e00d3c878 h1:EFSB7Zo9Eg91v7MJPVsifUysc/wPdN+NOnVe6bWbdBM=
|
||||
github.com/armon/go-metrics v0.0.0-20190430140413-ec5e00d3c878/go.mod h1:3AMJUQhVx52RsWOnlkpikZr01T/yAVN2gn0861vByNg=
|
||||
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
|
||||
github.com/boltdb/bolt v1.3.1/go.mod h1:clJnj/oiGkjum5o1McbSZDSLxVThjynRyGBgiAx27Ps=
|
||||
github.com/circonus-labs/circonus-gometrics v2.3.1+incompatible/go.mod h1:nmEj6Dob7S7YxXgwXpfOuvO54S+tGdZdw9fuRZt25Ag=
|
||||
github.com/circonus-labs/circonusllhist v0.1.3/go.mod h1:kMXHVDlOchFAehlya5ePtbp5jckzBHf4XRpQvBOLI+I=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/go-sql-driver/mysql v1.5.0 h1:ozyZYNQW3x3HtqT1jira07DN2PArx2v7/mN66gGcHOs=
|
||||
github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
|
||||
github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4=
|
||||
github.com/gogo/protobuf v1.3.1 h1:DqDEcV5aeaTmdFBePNpYsp3FlcVH/2ISVVM9Qf8PSls=
|
||||
github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o=
|
||||
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/golang/protobuf v1.3.3 h1:gyjaxf+svBWX08ZjK86iN9geUJF0H6gp2IRKX6Nf6/I=
|
||||
github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw=
|
||||
github.com/google/go-cmp v0.3.1 h1:Xye71clBPdm5HgqGwUkwhbynsUJZhDbS20FvLhQ2izg=
|
||||
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||
github.com/hashicorp/go-cleanhttp v0.5.0/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
|
||||
github.com/hashicorp/go-hclog v0.9.1 h1:9PZfAcVEvez4yhLH2TBU64/h/z4xlFI80cWXRrxuKuM=
|
||||
github.com/hashicorp/go-hclog v0.9.1/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ=
|
||||
github.com/hashicorp/go-immutable-radix v1.0.0 h1:AKDB1HM5PWEA7i4nhcpwOrO2byshxBjXVn/J/3+z5/0=
|
||||
github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60=
|
||||
github.com/hashicorp/go-msgpack v0.5.5 h1:i9R9JSrqIz0QVLz3sz+i3YJdT7TTSLcfLLzJi9aZTuI=
|
||||
github.com/hashicorp/go-msgpack v0.5.5/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM=
|
||||
github.com/hashicorp/go-retryablehttp v0.5.3/go.mod h1:9B5zBasrRhHXnJnui7y6sL7es7NDiJgTc6Er0maI1Xs=
|
||||
github.com/hashicorp/go-uuid v1.0.0 h1:RS8zrF7PhGwyNPOtxSClXXj9HA8feRnJzgnI1RJCSnM=
|
||||
github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
|
||||
github.com/hashicorp/golang-lru v0.5.0 h1:CL2msUPvZTLb5O648aiLNJw3hnBxN2+1Jq8rCOH9wdo=
|
||||
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
|
||||
github.com/hashicorp/raft v1.1.1 h1:HJr7UE1x/JrJSc9Oy6aDBHtNHUUBHjcQjTgvUVihoZs=
|
||||
github.com/hashicorp/raft v1.1.1/go.mod h1:vPAJM8Asw6u8LxC3eJCUZmRP/E4QmUGE1R7g7k8sG/8=
|
||||
github.com/hashicorp/raft-boltdb v0.0.0-20171010151810-6e5ba93211ea/go.mod h1:pNv7Wc3ycL6F5oOWn+tPGo2gWD4a5X+yp/ntwdKLjRk=
|
||||
github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=
|
||||
github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00=
|
||||
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
|
||||
github.com/kr/pretty v0.2.0 h1:s5hAObm+yFO5uHYt5dYjxi2rXrsnmRpJx4OYvIWUaQs=
|
||||
github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
|
||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
|
||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
github.com/lib/pq v1.3.0 h1:/qkRGz8zljWiDcFvgpwUpwIAPu3r07TDvs3Rws+o/pU=
|
||||
github.com/lib/pq v1.3.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
|
||||
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
|
||||
github.com/nats-io/jwt v0.3.0 h1:xdnzwFETV++jNc4W1mw//qFyJGb2ABOombmZJQS4+Qo=
|
||||
github.com/nats-io/jwt v0.3.0/go.mod h1:fRYCDE99xlTsqUzISS1Bi75UBJ6ljOJQOAAu5VglpSg=
|
||||
github.com/nats-io/jwt v0.3.2 h1:+RB5hMpXUUA2dfxuhBTEkMOrYmM+gKIZYS1KjSostMI=
|
||||
github.com/nats-io/jwt v0.3.2/go.mod h1:/euKqTS1ZD+zzjYrY7pseZrTtWQSjujC7xjPc8wL6eU=
|
||||
github.com/nats-io/nats-server/v2 v2.1.4 h1:BILRnsJ2Yb/fefiFbBWADpViGF69uh4sxe8poVDQ06g=
|
||||
github.com/nats-io/nats-server/v2 v2.1.4/go.mod h1:Jw1Z28soD/QasIA2uWjXyM9El1jly3YwyFOuR8tH1rg=
|
||||
github.com/nats-io/nats-streaming-server v0.17.0 h1:eYhSmjRmRsCYNsoUshmZ+RgKbhq6B+7FvMHXo3M5yMs=
|
||||
github.com/nats-io/nats-streaming-server v0.17.0/go.mod h1:ewPBEsmp62Znl3dcRsYtlcfwudxHEdYMtYqUQSt4fE0=
|
||||
github.com/nats-io/nats.go v1.9.1 h1:ik3HbLhZ0YABLto7iX80pZLPw/6dx3T+++MZJwLnMrQ=
|
||||
github.com/nats-io/nats.go v1.9.1/go.mod h1:ZjDU1L/7fJ09jvUSRVBR2e7+RnLiiIQyqyzEE/Zbp4w=
|
||||
github.com/nats-io/nkeys v0.1.0/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w=
|
||||
github.com/nats-io/nkeys v0.1.3 h1:6JrEfig+HzTH85yxzhSVbjHRJv9cn0p6n3IngIcM5/k=
|
||||
github.com/nats-io/nkeys v0.1.3/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w=
|
||||
github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw=
|
||||
github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c=
|
||||
github.com/nats-io/stan.go v0.6.0 h1:26IJPeykh88d8KVLT4jJCIxCyUBOC5/IQup8oWD/QYY=
|
||||
github.com/nats-io/stan.go v0.6.0/go.mod h1:eIcD5bi3pqbHT/xIIvXMwvzXYElgouBvaVRftaE+eac=
|
||||
github.com/pascaldekloe/goe v0.1.0 h1:cBOtyMzM9HTpWjXfbbunk26uA6nG3a8n06Wieeh0MwY=
|
||||
github.com/pascaldekloe/goe v0.1.0/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
|
||||
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/prometheus/client_golang v0.9.2/go.mod h1:OsXs2jCmiKlQ1lTBmv21f2mNfw4xf/QclQDMrYNZzcM=
|
||||
github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
|
||||
github.com/prometheus/common v0.0.0-20181126121408-4724e9255275/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro=
|
||||
github.com/prometheus/procfs v0.0.0-20181204211112-1dc9a6cbc91a/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
|
||||
github.com/prometheus/procfs v0.0.8 h1:+fpWZdT24pJBiqJdAwYBjPSk+5YmQzYNPYzQsdzLkt8=
|
||||
github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A=
|
||||
github.com/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww=
|
||||
github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM=
|
||||
go.etcd.io/bbolt v1.3.3 h1:MUGmc65QhB3pIlaQ5bB4LwqSj6GIonVJXpZiaKNyaKk=
|
||||
go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4 h1:HuIa8hRrWRSrqYzx1qI49NNxhdi2PrY7gxVSq1JjLDc=
|
||||
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20200206161412-a0c6ece9d31a h1:aczoJ0HPNE92XKa7DrIzkNN6esOKO2TBwiiYoKcINhA=
|
||||
golang.org/x/crypto v0.0.0-20200206161412-a0c6ece9d31a/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/net v0.0.0-20181201002055-351d144fa1fc/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190523142557-0e01d883c5c5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5 h1:LfCXLvNmTYH9kEmVgqbnsWfruoXZIrh4YBgqVHtDvw0=
|
||||
golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20181030221726-6c7e314b6563/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
|
||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
@@ -1,39 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
nats "github.com/nats-io/stan.go"
|
||||
uuid "github.com/satori/go.uuid"
|
||||
)
|
||||
|
||||
const (
|
||||
authToken = "defaultFissionAuthToken"
|
||||
host = "nats-streaming.fission"
|
||||
clusterID = "fissionMQTrigger"
|
||||
topic = "foobar"
|
||||
)
|
||||
|
||||
func Handler(w http.ResponseWriter, r *http.Request) {
|
||||
addr := fmt.Sprintf("nats://%v@%v:4222", authToken, host)
|
||||
nc, err := nats.Connect(clusterID, uuid.NewV4().String(), nats.NatsURL(addr))
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
log.Printf("Publishing message to topic '%v'\n", topic)
|
||||
|
||||
err = nc.Publish(topic, []byte("dummy"))
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
w.Write([]byte(err.Error()))
|
||||
log.Printf("error sending message to topic: %v", err.Error())
|
||||
return
|
||||
}
|
||||
nc.Close()
|
||||
|
||||
w.WriteHeader(http.StatusOK)
|
||||
w.Write([]byte("Publish Success"))
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
|
||||
Fission Specs
|
||||
=============
|
||||
|
||||
This is a set of specifications for a Fission app. This includes functions,
|
||||
environments, and triggers; we collectively call these things "resources".
|
||||
|
||||
How to use these specs
|
||||
----------------------
|
||||
|
||||
These specs are handled with the 'fission spec' command. See 'fission spec --help'.
|
||||
|
||||
'fission spec apply' will "apply" all resources specified in this directory to your
|
||||
cluster. That means it checks what resources exist on your cluster, what resources are
|
||||
specified in the specs directory, and reconciles the difference by creating, updating or
|
||||
deleting resources on the cluster.
|
||||
|
||||
'fission spec apply' will also package up your source code (or compiled binaries) and
|
||||
upload the archives to the cluster if needed. It uses 'ArchiveUploadSpec' resources in
|
||||
this directory to figure out which files to archive.
|
||||
|
||||
You can use 'fission spec apply --watch' to watch for file changes and continuously keep
|
||||
the cluster updated.
|
||||
|
||||
You can add YAMLs to this directory by writing them manually, but it's easier to generate
|
||||
them. Use 'fission function create --spec' to generate a function spec,
|
||||
'fission environment create --spec' to generate an environment spec, and so on.
|
||||
|
||||
You can edit any of the files in this directory, except 'fission-deployment-config.yaml',
|
||||
which contains a UID that you should never change. To apply your changes simply use
|
||||
'fission spec apply'.
|
||||
|
||||
fission-deployment-config.yaml
|
||||
------------------------------
|
||||
|
||||
fission-deployment-config.yaml contains a UID. This UID is what fission uses to correlate
|
||||
resources on the cluster to resources in this directory.
|
||||
|
||||
All resources created by 'fission spec apply' are annotated with this UID. Resources on
|
||||
the cluster that are _not_ annotated with this UID are never modified or deleted by
|
||||
fission.
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
apiVersion: fission.io/v1
|
||||
kind: Environment
|
||||
metadata:
|
||||
creationTimestamp: null
|
||||
name: go
|
||||
namespace: default
|
||||
spec:
|
||||
builder:
|
||||
command: build
|
||||
image: fission/go-builder-1.12:1.7.1
|
||||
imagepullsecret: ""
|
||||
keeparchive: false
|
||||
poolsize: 3
|
||||
resources: {}
|
||||
runtime:
|
||||
image: fission/go-env-1.12:1.7.1
|
||||
version: 2
|
||||
@@ -1,7 +0,0 @@
|
||||
# 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'
|
||||
apiVersion: fission.io/v1
|
||||
kind: DeploymentConfig
|
||||
name: nats-streaming
|
||||
uid: 9d6b82e4-3d73-49de-9007-1e47fbc377de
|
||||
@@ -1,54 +0,0 @@
|
||||
include:
|
||||
- hello.go
|
||||
kind: ArchiveUploadSpec
|
||||
name: hello-go-zqZW
|
||||
|
||||
---
|
||||
apiVersion: fission.io/v1
|
||||
kind: Package
|
||||
metadata:
|
||||
creationTimestamp: null
|
||||
name: hello-98476132-84ff-4e74-8b0f-2d1005871d1c
|
||||
namespace: default
|
||||
spec:
|
||||
deployment:
|
||||
checksum: {}
|
||||
environment:
|
||||
name: go
|
||||
namespace: default
|
||||
source:
|
||||
checksum: {}
|
||||
type: url
|
||||
url: archive://hello-go-zqZW
|
||||
status:
|
||||
buildstatus: pending
|
||||
lastUpdateTimestamp: "2019-12-19T17:31:23.43918Z"
|
||||
|
||||
---
|
||||
apiVersion: fission.io/v1
|
||||
kind: Function
|
||||
metadata:
|
||||
creationTimestamp: null
|
||||
name: hello
|
||||
namespace: default
|
||||
spec:
|
||||
InvokeStrategy:
|
||||
ExecutionStrategy:
|
||||
ExecutorType: poolmgr
|
||||
MaxScale: 0
|
||||
MinScale: 0
|
||||
SpecializationTimeout: 120
|
||||
TargetCPUPercent: 0
|
||||
StrategyType: execution
|
||||
configmaps: null
|
||||
environment:
|
||||
name: go
|
||||
namespace: default
|
||||
functionTimeout: 60
|
||||
package:
|
||||
functionName: Handler
|
||||
packageref:
|
||||
name: hello-98476132-84ff-4e74-8b0f-2d1005871d1c
|
||||
namespace: default
|
||||
resources: {}
|
||||
secrets: null
|
||||
@@ -1,27 +0,0 @@
|
||||
apiVersion: fission.io/v1
|
||||
kind: Function
|
||||
metadata:
|
||||
creationTimestamp: null
|
||||
name: publisher
|
||||
namespace: default
|
||||
spec:
|
||||
InvokeStrategy:
|
||||
ExecutionStrategy:
|
||||
ExecutorType: poolmgr
|
||||
MaxScale: 0
|
||||
MinScale: 0
|
||||
SpecializationTimeout: 120
|
||||
TargetCPUPercent: 0
|
||||
StrategyType: execution
|
||||
configmaps: null
|
||||
environment:
|
||||
name: go
|
||||
namespace: default
|
||||
functionTimeout: 60
|
||||
package:
|
||||
functionName: Handler
|
||||
packageref:
|
||||
name: publisher
|
||||
namespace: default
|
||||
resources: {}
|
||||
secrets: null
|
||||
@@ -1,25 +0,0 @@
|
||||
include:
|
||||
- mqtrigger/*
|
||||
kind: ArchiveUploadSpec
|
||||
name: mqtrigger-Z3l6
|
||||
|
||||
---
|
||||
apiVersion: fission.io/v1
|
||||
kind: Package
|
||||
metadata:
|
||||
creationTimestamp: null
|
||||
name: publisher
|
||||
namespace: default
|
||||
spec:
|
||||
deployment:
|
||||
checksum: {}
|
||||
environment:
|
||||
name: go
|
||||
namespace: default
|
||||
source:
|
||||
checksum: {}
|
||||
type: url
|
||||
url: archive://mqtrigger-Z3l6
|
||||
status:
|
||||
buildstatus: pending
|
||||
lastUpdateTimestamp: "2019-12-19T17:18:45.81397Z"
|
||||
@@ -1,131 +0,0 @@
|
||||
# Fission Node.js Examples
|
||||
|
||||
This is V2 example, check [here](README_V1.md) for V1.
|
||||
|
||||
This directory contains several examples to get you started using Node.js with Fission.
|
||||
|
||||
Before running any of these functions, make sure you have created a `nodejs` Fission environment:
|
||||
|
||||
```bash
|
||||
# Create an environment with default nodejs images
|
||||
$ fission env create --name nodeenv --image fission/node-env:latest --builder fission/node-builder:latest
|
||||
# Create zip file from our example
|
||||
$ zip -jr nodejs.zip nodejs/
|
||||
# Create a package with the zip file
|
||||
$ fission pkg create --sourcearchive nodejs.zip --env nodeenv
|
||||
```
|
||||
|
||||
## Function signature
|
||||
|
||||
Every Node.js function has the same basic form:
|
||||
|
||||
```javascript
|
||||
module.exports = async function(context) {
|
||||
return {
|
||||
status: 200,
|
||||
body: 'Your body here',
|
||||
headers: {
|
||||
'Foo': 'Bar'
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
## hello.js
|
||||
|
||||
This is a basic "Hello, World!" example. It simply returns a status of `200` and text body.
|
||||
|
||||
### Usage
|
||||
Since it is an `async` function, you can `await` `Promise`s, as demonstrated in the `weather.js` function.
|
||||
|
||||
```bash
|
||||
# Create a function
|
||||
$ fission fn create --name hello --pkg [pkgname] --entrypoint "hello"
|
||||
|
||||
# Test the function
|
||||
$ fission fn test --name hello
|
||||
```
|
||||
|
||||
## index.js
|
||||
|
||||
This file does nothing but for demonstrating `require` feature.
|
||||
|
||||
### Usage
|
||||
```bash
|
||||
# Create a function, you can skip `--entrypoint` as node will look for `index.js` by default
|
||||
$ fission fn create --name index --pkg [pkgname]
|
||||
|
||||
# Test the function
|
||||
$ fission fn test --name index
|
||||
```
|
||||
|
||||
## multi-entry.js
|
||||
|
||||
This is a multiple exports example. There are two exports: entry1 and entry2
|
||||
|
||||
### Usage
|
||||
```bash
|
||||
# Create a function for entry1
|
||||
$ fission fn create --name entry1 --pkg [pkgname] --entrypoint "multi-entry.entry1"
|
||||
|
||||
# Test the function
|
||||
$ fission fn test --name entry1
|
||||
|
||||
# Create a function for entry2
|
||||
$ fission fn create --name entry2 --pkg [pkgname] --entrypoint "multi-entry.entry2"
|
||||
|
||||
# Test the function
|
||||
$ fission fn test --name entry2
|
||||
```
|
||||
|
||||
## hello-callback.js
|
||||
|
||||
This is a basic "Hello, World!" example implemented with the legacy callback implementation. If you declare your function with two arguments (`context`, `callback`), a callback taking three arguments (`status`, `body`, `headers`) is provided.
|
||||
|
||||
⚠️️ Callback support is only provided for backwards compatibility! We recommend that you use `async` functions instead.
|
||||
|
||||
### Usage
|
||||
|
||||
```bash
|
||||
# Create a function
|
||||
$ fission fn create --name hello-callback --pkg [pkgname] --entrypoint "hello-callback"
|
||||
|
||||
# Map GET /hello-callback to your new function
|
||||
$ fission route create --method GET --url /hello-callback --function hello-callback
|
||||
|
||||
# Run the function.
|
||||
$ curl http://$FISSION_ROUTER/hello-callback
|
||||
Hello, world!
|
||||
```
|
||||
|
||||
## kubeEventsSlack.js
|
||||
|
||||
This example watches Kubernetes events and sends them to a Slack channel. To use this, create an incoming webhook for your Slack channel, and replace the `slackWebhookPath` in the example code.
|
||||
|
||||
### Usage
|
||||
|
||||
```bash
|
||||
# Upload your function code to fission
|
||||
$ fission fn create --name kubeEventsSlack --pkg [pkgname] --entrypoint "hello-callback"
|
||||
|
||||
# Watch all services in the default namespace:
|
||||
$ fission watch create --function kubeEventsSlack --type service --ns default
|
||||
```
|
||||
|
||||
## weather.js
|
||||
|
||||
In this example, the Yahoo Weather API is used to current weather at a given location.
|
||||
|
||||
### Usage
|
||||
|
||||
```bash
|
||||
# Upload your function code to fission
|
||||
$ fission function create --name weather --pkg [pkgname] --entrypoint "weather"
|
||||
|
||||
# Map GET /stock to your new function
|
||||
$ fission route create --method POST --url /weather --function weather
|
||||
|
||||
# Run the function.
|
||||
$ curl -H "Content-Type: application/json" -X POST -d '{"location":"Sieteiglesias, Spain"}' http://$FISSION_ROUTER/weather
|
||||
|
||||
{"text":"It is 2 celsius degrees in Sieteiglesias, Spain and Mostly Clear"}
|
||||
```
|
||||
@@ -1,105 +0,0 @@
|
||||
# Fission Node.js Examples
|
||||
|
||||
This directory contains several examples to get you started using Node.js with Fission.
|
||||
|
||||
## Environment
|
||||
|
||||
Before running any of these functions, make sure you have created a `nodejs` Fission environment:
|
||||
|
||||
```
|
||||
$ fission env create --name nodejs --image fission/node-env
|
||||
```
|
||||
|
||||
Note: The default `fission/node-env` image is based on Alpine, which is much smaller than the main Debian Node image (65MB vs 680MB) while still being suitable for most use cases.
|
||||
If you need to use the full Debian image use the `fission/node-env-debian` image instead.
|
||||
See the [official Node docker hub repo](https://hub.docker.com/_/node/) for considerations
|
||||
relating to this choice.
|
||||
|
||||
## Function signature
|
||||
|
||||
Every Node.js function has the same basic form:
|
||||
|
||||
```javascript
|
||||
module.exports = async function(context) {
|
||||
return {
|
||||
status: 200,
|
||||
body: 'Your body here',
|
||||
headers: {
|
||||
'Foo': 'Bar'
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Since it is an `async` function, you can `await` `Promise`s, as demonstrated in the `weather.js` function.
|
||||
|
||||
## hello.js
|
||||
|
||||
This is a basic "Hello, World!" example. It simply returns a status of `200` and text body.
|
||||
|
||||
### Usage
|
||||
|
||||
```bash
|
||||
# Upload your function code to fission
|
||||
$ fission function create --name hello --env nodejs --code hello.js
|
||||
|
||||
# Map GET /hello to your new function
|
||||
$ fission route create --method GET --url /hello --function hello
|
||||
|
||||
# Run the function.
|
||||
$ curl http://$FISSION_ROUTER/hello
|
||||
Hello, world!
|
||||
```
|
||||
|
||||
## hello-callback.js
|
||||
|
||||
This is a basic "Hello, World!" example implemented with the legacy callback implementation. If you declare your function with two arguments (`context`, `callback`), a callback taking three arguments (`status`, `body`, `headers`) is provided.
|
||||
|
||||
⚠️️ Callback support is only provided for backwards compatibility! We recommend that you use `async` functions instead.
|
||||
|
||||
### Usage
|
||||
|
||||
```bash
|
||||
# Upload your function code to fission
|
||||
$ fission function create --name hello-callback --env nodejs --code hello-callback.js
|
||||
|
||||
# Map GET /hello-callback to your new function
|
||||
$ fission route create --method GET --url /hello-callback --function hello-callback
|
||||
|
||||
# Run the function.
|
||||
$ curl http://$FISSION_ROUTER/hello-callback
|
||||
Hello, world!
|
||||
```
|
||||
|
||||
## kubeEventsSlack.js
|
||||
|
||||
This example watches Kubernetes events and sends them to a Slack channel. To use this, create an incoming webhook for your Slack channel, and replace the `slackWebhookPath` in the example code.
|
||||
|
||||
### Usage
|
||||
|
||||
```bash
|
||||
# Upload your function code to fission
|
||||
$ fission fn create --name kubeEventsSlack --env nodejs --code kubeEventsSlack.js
|
||||
|
||||
# Watch all services in the default namespace:
|
||||
$ fission watch create --function kubeEventsSlack --type service --ns default
|
||||
```
|
||||
|
||||
## weather.js
|
||||
|
||||
In this example, the Yahoo Weather API is used to current weather at a given location.
|
||||
|
||||
### Usage
|
||||
|
||||
```bash
|
||||
# Upload your function code to fission
|
||||
$ fission function create --name weather --env nodejs --code weather.js
|
||||
|
||||
# Map GET /stock to your new function
|
||||
$ fission route create --method POST --url /weather --function weather
|
||||
|
||||
# Run the function.
|
||||
$ curl -H "Content-Type: application/json" -X POST -d '{"location":"Sieteiglesias, Spain"}' http://$FISSION_ROUTER/weather
|
||||
|
||||
{"text":"It is 2 celsius degrees in Sieteiglesias, Spain and Mostly Clear"}
|
||||
```
|
||||
@@ -1,4 +0,0 @@
|
||||
|
||||
module.exports = function(context, callback) {
|
||||
callback(200, "Hello, world callback!\n");
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
|
||||
module.exports = async function(context) {
|
||||
return {
|
||||
status: 200,
|
||||
body: "hello, world!\n"
|
||||
};
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
module.exports = require('./hello');
|
||||
@@ -1,67 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
//
|
||||
// Watch kubernetes events and send them to a slack channel. This
|
||||
// uses Slack's incoming webhooks. To use this, create an incoming
|
||||
// webhook for your slack channel through Slack's UI, and populate the
|
||||
// relative path below.
|
||||
//
|
||||
// Create the function in fission:
|
||||
//
|
||||
// fission fn create --name kubeEventsSlack --env nodejs --code kubeEventsSlack.js
|
||||
//
|
||||
// Then, watch all services in the default namespace:
|
||||
//
|
||||
// fission watch create --function kubeEventsSlack --type service --ns default
|
||||
//
|
||||
|
||||
let https = require('https');
|
||||
|
||||
const slackWebhookPath = "YOUR RELATIVE PATH HERE"; // Something like "/services/XXX/YYY/zZz123"
|
||||
|
||||
function upcaseFirst(s) {
|
||||
return s.charAt(0).toUpperCase() + s.slice(1).toLowerCase();
|
||||
}
|
||||
|
||||
async function sendSlackMessage(msg) {
|
||||
let postData = `{"text": "${msg}"}`;
|
||||
let options = {
|
||||
hostname: "hooks.slack.com",
|
||||
path: slackWebhookPath,
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
}
|
||||
};
|
||||
|
||||
return new Promise(function(resolve, reject) {
|
||||
let req = https.request(options, function(res) {
|
||||
console.log(`slack request status = ${res.statusCode}`);
|
||||
return resolve();
|
||||
});
|
||||
req.write(postData);
|
||||
req.end();
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = async function(context) {
|
||||
console.log(context.request.headers);
|
||||
|
||||
let obj = context.request.body;
|
||||
let version = obj.metadata.resourceVersion;
|
||||
let eventType = context.request.get('X-Kubernetes-Event-Type');
|
||||
let objType = context.request.get('X-Kubernetes-Object-Type');
|
||||
|
||||
let msg = `${upcaseFirst(eventType)} ${objType} ${obj.metadata.name}`;
|
||||
console.log(msg, version);
|
||||
|
||||
if (eventType == 'DELETED' || eventType == 'ADDED') {
|
||||
console.log("sending event to slack")
|
||||
await sendSlackMessage(msg);
|
||||
}
|
||||
|
||||
return {
|
||||
status: 200,
|
||||
body: ""
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
module.exports.entry1 = async function(context) {
|
||||
return {
|
||||
status: 200,
|
||||
body: "Hello, entry 1!\n"
|
||||
};
|
||||
}
|
||||
|
||||
module.exports.entry2 = async function(context) {
|
||||
return {
|
||||
status: 200,
|
||||
body: "Hello, entry 2!\n"
|
||||
};
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
{
|
||||
"name": "fission-nodejs-example",
|
||||
"version": "0.1.0",
|
||||
"author": "Soam Vasani",
|
||||
"contributors": [
|
||||
{
|
||||
"name": "Soam Vasani",
|
||||
"email": "soamvasani+1@gmail.com"
|
||||
},
|
||||
{
|
||||
"name": "Gary Yeap",
|
||||
"email": "contact@garyyeap.com"
|
||||
}
|
||||
],
|
||||
"description": "Nodejs example for Fission framework",
|
||||
"engines": {
|
||||
"node": ">=7.6.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"body-parser": "*",
|
||||
"co": "~4.6.0",
|
||||
"express": "*",
|
||||
"minimist": "*",
|
||||
"morgan": "*",
|
||||
"mz": "~2.7.0",
|
||||
"request": "^2.81.0",
|
||||
"request-promise-native": "^1.0.3",
|
||||
"underscore": ">=1.8.3"
|
||||
}
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
const rp = require('request-promise-native');
|
||||
|
||||
module.exports = async function (context) {
|
||||
const stringBody = JSON.stringify(context.request.body);
|
||||
const body = JSON.parse(stringBody);
|
||||
const location = body.location;
|
||||
|
||||
if (!location) {
|
||||
return {
|
||||
status: 400,
|
||||
body: {
|
||||
text: 'You must provide a location.'
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await rp(`https://query.yahooapis.com/v1/public/yql?q=select item.condition from weather.forecast where woeid in (select woeid from geo.places(1) where text="${location}") and u="c"&format=json`);
|
||||
const condition = JSON.parse(response).query.results.channel.item.condition;
|
||||
const text = condition.text;
|
||||
const temperature = condition.temp;
|
||||
return {
|
||||
status: 200,
|
||||
body: {
|
||||
text: `It is ${temperature} celsius degrees in ${location} and ${text}`
|
||||
},
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
};
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
return {
|
||||
status: 500,
|
||||
body: e
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
=pod
|
||||
|
||||
You return a CODEREF from the package that will be called as your function.
|
||||
|
||||
The code in the server is something like this (simplified):
|
||||
|
||||
my $sub = require('hello.pm');
|
||||
$sub->(request);
|
||||
|
||||
As you can see, you get the L<Dancer2::Core::Request> object as first argument
|
||||
to your function. You can use it to retrieve params given to your function or
|
||||
anything else Dancer2 offers. You can also use Dancer2 and use its DSL.
|
||||
|
||||
=cut
|
||||
|
||||
use utf8;
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
# Get more helper functions (status and send_as below)
|
||||
use Dancer2;
|
||||
|
||||
return sub {
|
||||
my ($request) = @_;
|
||||
|
||||
my ($name) = $request->query_parameters->{'name'} // 'world';
|
||||
|
||||
# set status code by name
|
||||
status 'i_m_a_teapot';
|
||||
|
||||
# send message as JSON
|
||||
send_as JSON => {
|
||||
msg => "Hello, $name",
|
||||
auth => $request->header('Authorization'), # read request header
|
||||
};
|
||||
};
|
||||
@@ -1,3 +0,0 @@
|
||||
<?php
|
||||
echo "Hello from PHP";
|
||||
$logger->warning("Hello logger");
|
||||
@@ -1,12 +0,0 @@
|
||||
<?php
|
||||
function handler($context){
|
||||
/** @var \Psr\Http\Message\ResponseInterface $response */
|
||||
$response = $context["response"];
|
||||
/** @var \Psr\Http\Message\ServerRequestInterface $request */
|
||||
$request = $context["request"];
|
||||
/** @var \Psr\Log\LoggerInterface $logger */
|
||||
$logger = $context["logger"];
|
||||
|
||||
$response->getBody()->write("Hello from handler PHP");
|
||||
$logger->warning("Hello logger");
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
This is an example of creating a deployment package with multiple
|
||||
files including external libraries via composer.
|
||||
|
||||
### Create an environment
|
||||
|
||||
```
|
||||
fission env create --name php --image fission/php-env:latest --builder fission/php-builder:latest --version 2
|
||||
```
|
||||
|
||||
### Create a zip file with all your files
|
||||
|
||||
```
|
||||
zip -r multifile.zip . -i *.php *.txt composer.json
|
||||
```
|
||||
|
||||
### Create a package
|
||||
```
|
||||
fission package create --sourcearchive multifile.zip --env php
|
||||
```
|
||||
This command will print the created package. We will use it in the next step.
|
||||
|
||||
|
||||
### Create a function
|
||||
|
||||
Since there are multiple files, you have to specify an _entrypoint_ to
|
||||
for the function. Its format is `<file path>::<function name>`. In our
|
||||
example, that's `handlers/FileReader.php::execute`, to run function `execute` in `handlers/FileReader.php`.
|
||||
|
||||
```
|
||||
fission function create --name multifile --env php --pkg <created-pkg-name> --entrypoint "handlers/FileReader.php::execute"
|
||||
```
|
||||
|
||||
### Test it
|
||||
|
||||
```
|
||||
fission function test --name multifile
|
||||
```
|
||||
|
||||
You should see the "Hello, world" message.
|
||||
|
||||
|
||||
## Updating the function
|
||||
|
||||
### Edit a file
|
||||
|
||||
```
|
||||
echo "I said hellooooo!" > message.txt
|
||||
```
|
||||
|
||||
### Update the deployment package
|
||||
|
||||
```
|
||||
zip -r multifile.zip . -i *.php *.txt composer.json
|
||||
```
|
||||
|
||||
### Update the package
|
||||
|
||||
```
|
||||
fission package update --name <created-pkg-name> --sourcearchive multifile.zip --env php
|
||||
```
|
||||
|
||||
### Test it
|
||||
|
||||
```
|
||||
fission function test --name multifile
|
||||
```
|
||||
|
||||
You should now see your new, edited message.
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
{
|
||||
"name": "example/php7",
|
||||
"description": "Example for php7 environment",
|
||||
"require": {
|
||||
"psr/log": "^1.1",
|
||||
"psr/http-message": "^1.0"
|
||||
},
|
||||
"authors": [
|
||||
{
|
||||
"name": "Alberto Lopez",
|
||||
"email": "alberto.lopez.benito@gmail.com"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
require __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
function execute($context)
|
||||
{
|
||||
/** @var ResponseInterface $response */
|
||||
$response = $context["response"];
|
||||
/** @var LoggerInterface $logger */
|
||||
$logger = $context["logger"];
|
||||
$response->getBody()->write(file_get_contents(__DIR__ . '/message.txt'));
|
||||
$logger->debug('File read: example.txt');
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
I said hellooooo!
|
||||
@@ -1,47 +0,0 @@
|
||||
<?php
|
||||
use \Psr\Http\Message\ResponseInterface;
|
||||
use \Psr\Http\Message\ServerRequestInterface;
|
||||
use \Psr\Log\LoggerInterface;
|
||||
|
||||
function sendError($response,$message){
|
||||
$response = $response->withStatus(500);
|
||||
$response->getBody()->write($message);
|
||||
return $response;
|
||||
}
|
||||
|
||||
function handler($context){
|
||||
/** @var ResponseInterface $response */
|
||||
$response = $context["response"];
|
||||
/** @var ServerRequestInterface $request */
|
||||
$request = $context["request"];
|
||||
/** @var LoggerInterface $logger */
|
||||
$logger = $context["logger"];
|
||||
|
||||
$logger->debug("Request : ",$request->getParsedBody());
|
||||
if($request->getMethod() != "POST")
|
||||
return sendError($response,"You must use POST method");
|
||||
|
||||
$body = $request->getParsedBody();
|
||||
if(!isset($body["currency"]))
|
||||
return sendError($response,"'currency' is not present in the POST request");
|
||||
|
||||
$allowedCurrency = ["ltc","btc"];
|
||||
if(!in_array($body["currency"],$allowedCurrency))
|
||||
return sendError($response,"'currency' is non allowed. Use one of them : ".implode(",",$allowedCurrency));
|
||||
|
||||
$curl = curl_init();
|
||||
curl_setopt_array($curl, array(
|
||||
CURLOPT_RETURNTRANSFER => 1,
|
||||
CURLOPT_URL => 'https://api.cryptonator.com/api/ticker/'.$body["currency"].'-usd'
|
||||
));
|
||||
$result = curl_exec($curl);
|
||||
curl_close($curl);
|
||||
|
||||
$result = json_decode($result,true);
|
||||
if($result){
|
||||
$logger->debug("Response API",$result);
|
||||
$response->getBody()->write(json_encode(array("text"=>sprintf("%s-USB = %02f",$body["currency"],$result["ticker"]["price"]))));
|
||||
}else
|
||||
return sendError($response,"Cryptonator API not available");
|
||||
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
# Python Examples
|
||||
|
||||
This directory contains a Python examples to show different the features of the Fission Python environment:
|
||||
- `hello.py` is a simple Pythonic _hello world_ function.
|
||||
- `requestdata.py` shows how you can access the HTTP request fields, such as the body, headers and query.
|
||||
- `statuscode.py` is an example of how you can change the response status code.
|
||||
- `multifile/` shows how to create Fission Python functions with multiple source files.
|
||||
- `guestbook/` is a more realistic demonstration of using Python and Fission to create a serverless guestbook.
|
||||
- `sourcepkg/` is an example of how to use the Fission Python Build environment to resolve (pip) dependencies
|
||||
before deploying the function.
|
||||
|
||||
## Getting Started
|
||||
|
||||
Create a Fission Python environment with the default Python runtime image (this does not include the build environment):
|
||||
```
|
||||
fission environment create --name python --image fission/python-env
|
||||
```
|
||||
|
||||
Use the `hello.py` to create a Fission Python function:
|
||||
```
|
||||
fission function create --name hello-py --env python --code hello.py
|
||||
```
|
||||
|
||||
Test the function:
|
||||
```
|
||||
fission function test --name hello-py
|
||||
```
|
||||
|
||||
For a full guide see the [official documentation on Python with Fission](https://docs.fission.io/languages/python/).
|
||||
@@ -1,18 +0,0 @@
|
||||
#
|
||||
# Handles POST /guestbook -- adds item to guestbook
|
||||
#
|
||||
|
||||
from flask import request, redirect
|
||||
import redis
|
||||
|
||||
# Connect to redis.
|
||||
redisConnection = redis.StrictRedis(host='redis.guestbook', port=6379, db=0)
|
||||
|
||||
def main():
|
||||
# Read the item from POST params, add it to redis, and redirect
|
||||
# back to the list
|
||||
item = request.form['text']
|
||||
redisConnection.rpush('guestbook', item)
|
||||
r = redirect('/guestbook', code=303)
|
||||
r.autocorrect_location_header = False
|
||||
return r
|
||||
@@ -1,18 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -e
|
||||
|
||||
kubectl create -f redis.yaml
|
||||
|
||||
if [ -z "$FISSION_URL" ]
|
||||
then
|
||||
echo "Need $FISSION_URL set to a fission controller address"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Create python env if it doesn't exist
|
||||
fission env get --name python || fission env create --name python --image fission/python-env
|
||||
|
||||
# Register functions and routes with fission
|
||||
fission function create --name guestbook-get --env python --code get.py --url /guestbook --method GET
|
||||
fission function create --name guestbook-add --env python --code add.py --url /guestbook --method POST
|
||||
@@ -1,28 +0,0 @@
|
||||
#
|
||||
# Handles GET /guestbook -- returns a list of items in the guestbook
|
||||
# with a form to add more.
|
||||
#
|
||||
|
||||
from flask import current_app, escape
|
||||
import redis
|
||||
|
||||
# Connect to redis. This is run only when this file is loaded; as
|
||||
# long as the pod is alive, the connection is reused.
|
||||
redisConnection = redis.StrictRedis(host='redis.guestbook', port=6379, db=0)
|
||||
|
||||
def main():
|
||||
messages = redisConnection.lrange('guestbook', 0, -1)
|
||||
|
||||
items = [("<li>%s</li>" % escape(m.decode('utf-8'))) for m in messages]
|
||||
ul = "<ul>%s</ul>" % "\n".join(items)
|
||||
return """
|
||||
<html><body style="font-family:sans-serif;font-size:2rem;padding:40px">
|
||||
<h1>Guestbook</h1>
|
||||
<form action="/guestbook" method="POST">
|
||||
<input type="text" name="text">
|
||||
<button type="submit">Add</button>
|
||||
</form>
|
||||
<hr/>
|
||||
%s
|
||||
</body></html>
|
||||
""" % ul
|
||||
@@ -1,45 +0,0 @@
|
||||
apiVersion: v1
|
||||
kind: Namespace
|
||||
metadata:
|
||||
name: guestbook
|
||||
labels:
|
||||
name: guestbook
|
||||
|
||||
---
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
labels:
|
||||
run: redis
|
||||
name: redis
|
||||
namespace: guestbook
|
||||
spec:
|
||||
replicas: 1
|
||||
selector:
|
||||
matchLabels:
|
||||
run: redis
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
run: redis
|
||||
spec:
|
||||
containers:
|
||||
- image: redis
|
||||
name: redis
|
||||
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
labels:
|
||||
run: redis
|
||||
name: redis
|
||||
namespace: guestbook
|
||||
spec:
|
||||
selector:
|
||||
run: redis
|
||||
type: ClusterIP
|
||||
ports:
|
||||
- port: 6379
|
||||
protocol: TCP
|
||||
targetPort: 6379
|
||||
@@ -1,2 +0,0 @@
|
||||
def main():
|
||||
return "Hello, world!\n"
|
||||
@@ -1,62 +0,0 @@
|
||||
This is an example of creating a deployment package with multiple
|
||||
files including some static data in text file.
|
||||
|
||||
### Create an environment
|
||||
|
||||
```
|
||||
fission env create --name python --image fission/python-env:0.4.0rc --version 2
|
||||
```
|
||||
|
||||
### Create a zip file with all your files
|
||||
|
||||
```
|
||||
zip -jr multifile.zip *.py *.txt
|
||||
```
|
||||
|
||||
### Create a function
|
||||
|
||||
Since there are multiple files, you have to specify an _entrypoint_ to
|
||||
for the function. Its format is `<file name>.<function name>`. In our
|
||||
example, that's `main.main`, to run function `main` in `main.py`.
|
||||
|
||||
```
|
||||
fission function create --name multifile --env python --code multifile.zip --entrypoint main.main
|
||||
```
|
||||
|
||||
### Test it
|
||||
|
||||
```
|
||||
fission function test --name multifile
|
||||
```
|
||||
|
||||
You should see the "Hello, world" message.
|
||||
|
||||
|
||||
## Updating the function
|
||||
|
||||
### Edit a file
|
||||
|
||||
```
|
||||
echo "I said hellooooo!" > message.txt
|
||||
```
|
||||
|
||||
### Update the deployment package
|
||||
|
||||
```
|
||||
zip -jr multifile.zip *.py *.txt
|
||||
```
|
||||
|
||||
### Update the function
|
||||
|
||||
```
|
||||
fission function update --name multifile --code multifile.zip
|
||||
```
|
||||
|
||||
### Test it
|
||||
|
||||
```
|
||||
fission function test --name multifile
|
||||
```
|
||||
|
||||
You should now see your new, edited message.
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
from flask import current_app
|
||||
import sys
|
||||
import readfile
|
||||
import os
|
||||
|
||||
def main():
|
||||
current_app.logger.info("Hi")
|
||||
|
||||
current_dir = os.path.dirname(__file__)
|
||||
|
||||
return readfile.readFile(os.path.join(current_dir, "message.txt"))
|
||||
@@ -1 +0,0 @@
|
||||
Hello, world!
|
||||
@@ -1,3 +0,0 @@
|
||||
def readFile(name):
|
||||
with open(name) as f:
|
||||
return f.read()
|
||||
@@ -1,7 +0,0 @@
|
||||
from flask import request
|
||||
from flask import current_app
|
||||
|
||||
def main():
|
||||
current_app.logger.info("Received request")
|
||||
msg = "---HEADERS---\n%s\n--BODY--\n%s\n-----\n" % (request.headers, request.get_data())
|
||||
return msg
|
||||
@@ -1,2 +0,0 @@
|
||||
#!/bin/sh
|
||||
pip3 install -r ${SRC_PKG}/requirements.txt -t ${SRC_PKG} && cp -r ${SRC_PKG} ${DEPLOY_PKG}
|
||||
@@ -1 +0,0 @@
|
||||
pyyaml
|
||||
@@ -1,11 +0,0 @@
|
||||
import yaml
|
||||
|
||||
document = """
|
||||
a: 1
|
||||
b:
|
||||
c: 3
|
||||
d: 4
|
||||
"""
|
||||
|
||||
def main():
|
||||
return yaml.dump(yaml.load(document), default_flow_style=None)
|
||||
@@ -1,4 +0,0 @@
|
||||
def main():
|
||||
# You can return any http status code you like, simply place a comma after
|
||||
# your return statement, and typing in the status code.
|
||||
return "Not Found\n", 404
|
||||
@@ -1,115 +0,0 @@
|
||||
# Ruby examples
|
||||
|
||||
This directory contains several examples to get you started using Ruby
|
||||
with Fission.
|
||||
|
||||
Before running any of these functions, make sure you have created a
|
||||
`ruby` Fission environment:
|
||||
|
||||
```
|
||||
$ fission env create --name ruby --image USER/ruby-env
|
||||
```
|
||||
|
||||
## Method signature
|
||||
|
||||
A standard Ruby function has the basic form:
|
||||
|
||||
```ruby
|
||||
def handler(context)
|
||||
return [200, {}, []]
|
||||
end
|
||||
```
|
||||
|
||||
If the fission context is not required, the function can be simplified:
|
||||
|
||||
```ruby
|
||||
def handler
|
||||
[200, {}, ["Hello, world!\n"]]
|
||||
end
|
||||
```
|
||||
|
||||
If a simple text response is to be returned, with a status of 200, this
|
||||
can be further simplified.
|
||||
|
||||
```ruby
|
||||
def handler
|
||||
"Hello, world!\n"
|
||||
end
|
||||
```
|
||||
|
||||
## Hello example (`hello.rb`)
|
||||
|
||||
This example is the simplest possible Ruby function, as described above.
|
||||
|
||||
To run the example:
|
||||
|
||||
```
|
||||
$ fission function create --name hello --env ruby --code examples/ruby/hello.rb
|
||||
|
||||
$ fission route create --method GET --url /hello --function hello
|
||||
|
||||
$ curl http://$FISSION_ROUTER/hello
|
||||
Hello, world!
|
||||
```
|
||||
|
||||
## Request data example (`request_data.rb`)
|
||||
|
||||
This example shows basic use of the `Fission::Context` and
|
||||
`Fission::Request` objects.
|
||||
|
||||
To run the example:
|
||||
|
||||
```
|
||||
$ fission function create --name request --env ruby --code examples/ruby/request_data.rb
|
||||
|
||||
$ fission route create --method GET --url /request/{id} --function request
|
||||
|
||||
$ curl http://$FISSION_ROUTER/request/123?key=abc
|
||||
---ENV---
|
||||
GATEWAY_INTERFACE=CGI/1.1
|
||||
PATH_INFO=/
|
||||
QUERY_STRING=key=abc
|
||||
REMOTE_ADDR=172.17.0.8
|
||||
REMOTE_HOST=172.17.0.8
|
||||
REQUEST_METHOD=GET
|
||||
REQUEST_URI=http://192.168.64.200:31314/?key=abc
|
||||
SCRIPT_NAME=
|
||||
SERVER_NAME=192.168.64.200
|
||||
SERVER_PORT=31314
|
||||
SERVER_PROTOCOL=HTTP/1.1
|
||||
SERVER_SOFTWARE=WEBrick/1.3.1 (Ruby/2.4.1/2017-03-22)
|
||||
HTTP_HOST=192.168.64.200:31314
|
||||
HTTP_USER_AGENT=curl/7.52.1
|
||||
HTTP_ACCEPT=*/*
|
||||
HTTP_X_FISSION_PARAMS_ID=123
|
||||
HTTP_X_FORWARDED_FOR=172.17.0.1
|
||||
HTTP_ACCEPT_ENCODING=gzip
|
||||
rack.version=1=3
|
||||
...
|
||||
HTTP_VERSION=HTTP/1.1
|
||||
REQUEST_PATH=/
|
||||
|
||||
---HEADERS---
|
||||
Accept: */*
|
||||
Accept-Encoding: gzip
|
||||
Host: 192.168.64.200:31314
|
||||
User-Agent: curl/7.52.1
|
||||
Version: HTTP/1.1
|
||||
X-Fission-Params-Id: 123
|
||||
X-Forwarded-For: 172.17.0.1
|
||||
|
||||
---PARAMS---
|
||||
key=abc
|
||||
id=123
|
||||
|
||||
--BODY--
|
||||
|
||||
```
|
||||
|
||||
## V2 Specification Example (with builder support)
|
||||
|
||||
```
|
||||
$ fission function create --name parse --env ruby --src "parse/*" --entrypoint handler
|
||||
$ fission fn test --name parse --body '<message>This is my message</message>'
|
||||
This is my message
|
||||
```
|
||||
@@ -1,33 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
require 'net/http'
|
||||
require 'uri'
|
||||
require 'json'
|
||||
|
||||
SLACK_BASE_URL = 'https://hooks.slack.com/'
|
||||
SLACK_WEBHOOK_PATH = 'YOUR RELATIVE PATH HERE' # Something like "/services/XXX/YYY/zZz123"
|
||||
|
||||
def send_slack_message(message)
|
||||
uri = URI.join(SLACK_BASE_URL, SLACK_WEBHOOK_PATH)
|
||||
data = "{'channel': '#hackdays-serverless', 'username': 'fissionbot', 'text': \"#{message}\", 'icon_emoji': ':fission:'}"
|
||||
res = Net::HTTP.post_form(uri, payload: data)
|
||||
res.success?
|
||||
end
|
||||
|
||||
def handler(context)
|
||||
request = context.request
|
||||
|
||||
event_type = request.headers['X-Kubernetes-Event-Type']
|
||||
object_type = request.headers['X-Kubernetes-Object-Type']
|
||||
|
||||
object = JSON.parse(request.body.read)
|
||||
object_name = object.dig('metadata', 'name')
|
||||
object_namespace = object.dig('metadata', 'namespace')
|
||||
|
||||
message = "#{event_type} #{object_type} #{object_namespace}/#{object_name}"
|
||||
|
||||
if send_slack_message(message)
|
||||
"Slack message sent - #{message}"
|
||||
else
|
||||
Rack::Response.new(["Failed to send Slack message - #{message}"], 500).finish
|
||||
end
|
||||
end
|
||||
@@ -1,4 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
def handler
|
||||
"Hello, world!\n"
|
||||
end
|
||||
@@ -1,7 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
source "https://rubygems.org"
|
||||
|
||||
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
|
||||
|
||||
gem "nokogiri"
|
||||
@@ -1,15 +0,0 @@
|
||||
GEM
|
||||
remote: https://rubygems.org/
|
||||
specs:
|
||||
mini_portile2 (2.4.0)
|
||||
nokogiri (1.10.8)
|
||||
mini_portile2 (~> 2.4.0)
|
||||
|
||||
PLATFORMS
|
||||
ruby
|
||||
|
||||
DEPENDENCIES
|
||||
nokogiri
|
||||
|
||||
BUNDLED WITH
|
||||
1.16.1
|
||||
@@ -1,13 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'nokogiri'
|
||||
|
||||
def handler(context)
|
||||
context.logger.info("Received request")
|
||||
|
||||
doc = Nokogiri::XML(context.request.body.read)
|
||||
ele = doc.at_xpath('//message')
|
||||
msg = ele.nil? ? 'No Message' : ele.content
|
||||
|
||||
Rack::Response.new([msg, "\n"]).finish
|
||||
end
|
||||
@@ -1,20 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
def handler(context)
|
||||
context.logger.info("Received request")
|
||||
|
||||
msg = <<~MSG
|
||||
---ENV---
|
||||
#{context.request.env.map { |h| h.join('=') }.join("\n") }
|
||||
|
||||
---HEADERS---
|
||||
#{context.request.headers.map { |h| h.join(': ') }.join("\n") }
|
||||
|
||||
---PARAMS---
|
||||
#{context.request.params.map { |h| h.join('=') }.join("\n") }
|
||||
|
||||
--BODY--
|
||||
#{context.request.body.read}
|
||||
MSG
|
||||
|
||||
Rack::Response.new([msg]).finish
|
||||
end
|
||||
@@ -1,11 +0,0 @@
|
||||
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`.
|
||||
@@ -1,9 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -e
|
||||
|
||||
# check syntax
|
||||
python3 -m compileall -l ${SRC_PKG}
|
||||
|
||||
# install deps
|
||||
pip3 install -r ${SRC_PKG}/requirements.txt -t ${SRC_PKG} && cp -r ${SRC_PKG} ${DEPLOY_PKG}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user