From f40688435dc188d817cbbaa552915bde9fa506c1 Mon Sep 17 00:00:00 2001 From: Vishal Date: Wed, 25 Jul 2018 09:26:01 +0530 Subject: [PATCH] Added readme for JVM environment & examples (#768) Instructions for JVM environment and examples --- environments/jvm/README.md | 68 +++++++++++++++++++++++++++++++++++++ examples/jvm/java/README.md | 61 +++++++++++++++++++++++++++++++++ 2 files changed, 129 insertions(+) create mode 100644 environments/jvm/README.md create mode 100644 examples/jvm/java/README.md diff --git a/environments/jvm/README.md b/environments/jvm/README.md new file mode 100644 index 00000000..b07a41b3 --- /dev/null +++ b/environments/jvm/README.md @@ -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. + +``` + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-tomcat + + + + + + org.springframework.boot + spring-boot-starter-jetty + +``` + +## 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}. \ No newline at end of file diff --git a/examples/jvm/java/README.md b/examples/jvm/java/README.md new file mode 100644 index 00000000..fa490f11 --- /dev/null +++ b/examples/jvm/java/README.md @@ -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! + +``` \ No newline at end of file