commit | 296859884a872687bf0028ec1e08afb885ae8304 | [log] [tgz] |
---|---|---|
author | falkzoll <falkzoll@de.ibm.com> | Fri Mar 13 22:38:58 2020 +0100 |
committer | GitHub <noreply@github.com> | Fri Mar 13 22:38:58 2020 +0100 |
tree | 4983ae03d9ceb04b6b1847f4739bef9dd69ab86a | |
parent | 3faee44ba46151b8548bfbbd7764d89d1b201b54 [diff] |
Get latest security fixes with every build. (#110) - Add 'apt-get upgrade' to the image builds to include security fixes with each build in case the used base image is not updated frequently. In case the base image is updated frequently, the 'apt-get upgrade' is a no operation. If not it will catch the security updates available since the last update of the base image.
A Java action is a Java program with a method called main
that has the exact signature as follows:
public static com.google.gson.JsonObject main(com.google.gson.JsonObject);
For example, create a Java file called Hello.java
with the following content:
import com.google.gson.JsonObject; public class Hello { public static JsonObject main(JsonObject args) { String name = "stranger"; if (args.has("name")) name = args.getAsJsonPrimitive("name").getAsString(); JsonObject response = new JsonObject(); response.addProperty("greeting", "Hello " + name + "!"); return response; } }
In order to compile, test and archive Java files, you must have a JDK 8 installed locally.
Then, compile Hello.java
into a JAR file hello.jar
as follows:
javac Hello.java
jar cvf hello.jar Hello.class
Note: google-gson must exist in your Java CLASSPATH when compiling the Java file.
You need to specify the name of the main class using --main
. An eligible main class is one that implements a static main
method as described above. If the class is not in the default package, use the Java fully-qualified class name, e.g., --main com.example.MyMain
.
If needed you can also customize the method name of your Java action. This can be done by specifying the Java fully-qualified method name of your action, e.q., --main com.example.MyMain#methodName
To use as a docker action:
wsk action update helloJava hello.jar --main Hello --docker openwhisk/java8action
This works on any deployment of Apache OpenWhisk
To use on a deployment of OpenWhisk that contains the runtime as a kind:
wsk action update helloJava hello.jar --main Hello --kind java:8
Action invocation is the same for Java actions as it is for Swift and JavaScript actions:
wsk action invoke --result helloJava --param name World
{ "greeting": "Hello World!" }
Start Docker Desktop (i.e., Docker daemon)
Build the Docker runtime image locally using Gradle:
./gradlew core:java8:distDocker
This will produce the image whisk/java8action
and push it to the local Docker Desktop registry with the latest
tag.
$ docker images whisk/* REPOSITORY TAG IMAGE ID CREATED SIZE whisk/java8action latest 35f90453905a 7 minutes ago 521MB
Build the Docker runtime image locally using Gradle supplying the image Prefix and Registry domain (default port):
docker login ./gradlew core:java8:distDocker -PdockerImagePrefix=$prefix-user -PdockerRegistry=docker.io
Deploy OpenWhisk using ansible environment that contains the kind java:8
Assuming you have OpenWhisk already deployed locally and OPENWHISK_HOME
pointing to root directory of OpenWhisk core repository.
Set ROOTDIR
to the root directory of this repository.
Redeploy OpenWhisk
cd $OPENWHISK_HOME/ansible ANSIBLE_CMD="ansible-playbook -i ${ROOTDIR}/ansible/environments/local" $ANSIBLE_CMD setup.yml $ANSIBLE_CMD couchdb.yml $ANSIBLE_CMD initdb.yml $ANSIBLE_CMD wipe.yml $ANSIBLE_CMD openwhisk.yml
Or you can use wskdev
and create a soft link to the target ansible environment, for example:
ln -s ${ROOTDIR}/ansible/environments/local ${OPENWHISK_HOME}/ansible/environments/local-java wskdev fresh -t local-java
Install dependencies from the root directory on $OPENWHISK_HOME repository
pushd $OPENWHISK_HOME ./gradlew install popd $OPENWHISK_HOME
Using gradle to run all tests
./gradlew :tests:test
Using gradle to run some tests
./gradlew :tests:test --tests *ActionContainerTests*
Using IntelliJ:
To use as docker action push to your own dockerhub account
docker tag whisk/java8action $user_prefix/java8action docker push $user_prefix/java8action
Then create the action using your the image from dockerhub
wsk action update helloJava hello.jar --main Hello --docker $user_prefix/java8action
The $user_prefix
is usually your dockerhub user id.
This may occur on MacOS as the default maximum # of file handles per session is 256
. The gradle build requires many more and is unable to open more files (e.g., java.io.FileNotFoundException
). For example, you may see something like:
> java.io.FileNotFoundException: /Users/XXX/.gradle/caches/4.6/scripts-remapped/build_4mpzm2wl8gipqoxzlms7n6ctq/7gdodk7z6t5iivcgfvflmhqsm/cp_projdf5583fde4f7f1f2f3f5ea117e2cdff1/cache.properties (Too many open files)
You can see this limit by issuing:
$ ulimit -a open files (-n) 256
In order to increase the limit, open a new terminal session and issue the command (and verify):
$ ulimit -n 10000 $ ulimit -a open files (-n) 10000
:core:java8:tagImage
Docker daemon is not started and the Task is not able to push the image to your local registry.