Added readme for JVM environment & examples (#768)

Instructions for JVM environment and examples
This commit is contained in:
Vishal
2018-07-25 09:26:01 +05:30
committed by GitHub
parent e8b2a26a3b
commit f40688435d
2 changed files with 129 additions and 0 deletions
+68
View File
@@ -0,0 +1,68 @@
# Fission: Java and JVM Environment
This is the JVM environment for Fission.
It's a Docker image containing a OpenJDK8 runtime, along with a
dynamic loader. A few dependencies are included in the
pom.xml file.
## Customizing this image
To add package dependencies, edit pom.xml to add what you
need, and rebuild this image (instructions below).
## Rebuilding and pushing the image
You'll need access to a Docker registry to push the image: you can
sign up for Docker hub at hub.docker.com, or use registries from
gcr.io, quay.io, etc. Let's assume you're using a docker hub account
called USER. Build and push the image to the the registry:
```
docker build -t USER/jvm-env . && docker push USER/jvm-env
```
## Using the image in fission
You can add this customized image to fission with "fission env
create":
```
fission env create --name jvm --image USER/jvm-env
```
Or, if you already have an environment, you can update its image:
```
fission env update --name jvm --image USER/jvm-env
```
After this, fission functions that have the env parameter set to the
same environment name as this command will use this environment.
## Web Server Framework
JVM environment uses Tomcat HTTP server by default as it is included in spring web. You can choose to use jetty or undertow by changing the dependency in pom.xml file as shown below.
```
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<!-- Exclude the Tomcat dependency -->
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- Use Jetty instead -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jetty</artifactId>
</dependency>
```
## Java and JVM builder
JVM environment builder is based on OpenJDK8 and Maven 3.5.4 version. The default build command runs `mvn clean package` and uses the target/*with-dependencies.jar file for function. The default build command can be overridden as long as the uber jar file is copied to ${DEPLOY_PKG}.
+61
View File
@@ -0,0 +1,61 @@
# Hello World in JVM/Java on Fission
The `io.fission.HelloWorld.java` class is a 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-env-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
$ ./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!
```