This image is meant to run in an OpenShift cluster with Knative installed.
It is currently under development and incomplete. When a container for this
image starts, a process loads the JavaScript in /home/node/usr on the container
file system. If there is a package.json file in the directory, the bootstrap
process will run npm install before loading the function.
This image may also be used as a source to image builder.
- The image currently responds to
HTTPrequests on port8080and to Knative Events, which users can consume asCloudEventobject. - The function is passed a
Contextobject when it is called. This object currently contains little to no valuable information beyond the Node.jshttp.IncomingMessage(the request),http.ServerResponseobjects andcloudeventobject, which is instantiated if the function responds to incoming Knative Event.
Surely there are other limitations, but this is enough for plenty of discussion at the moment.
To build the image, run the following command.
make buildYou should end up with an image at redhat-faas/js-runtime.
You can run this image locally to play around with it, test edges and
generally get a feel for how it works. First, create a directory containing
one or more JavaScript files. One of these must be named index.js. The
bootstrap process will load this file and any other files it references
via module dependencies (e.g. const myCalc = require('./my-calc.js');).
If you have external, third party dependencies from npmjs.com, add a
package.json to the directory specifying the dependencies.
With the source in place, you can start the container and mount the source
onto a container directory. The bootstrap process expects /home/node/usr
to contain the runtime source code. To mount this into a running container
execute the following command.
docker run --rm -a stdout -a stderr -v /path/to/local/source/dir:/home/node/usr -p 8080:8080 oscf/js-runtime:candidateTo stop the running container:
$ docker ps
$ docker stop <CONTAINER ID>To test the image, run the following command.
make testThis will build a candidate image, and mount the ./test directory on the host
to the /home/node/usr directory on the running container. When the container
starts, a bootstrap process loads the test JavaScript in /home/node/usr.