GithubHelp home page GithubHelp logo

openshift-cloud-functions / faas-js-runtime-image Goto Github PK

View Code? Open in Web Editor NEW
0.0 4.0 4.0 34 KB

A runtime image for Node.js FaaS on OpenShift

Dockerfile 5.38% Makefile 11.16% Shell 69.17% JavaScript 14.28%

faas-js-runtime-image's Introduction

FaaS Node.js Runtime Image CircleCI

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.

Source to Image

This image may also be used as a source to image builder.

Limitations

  • The image currently responds to HTTP requests on port 8080 and to Knative Events, which users can consume as CloudEvent object.
  • The function is passed a Context object when it is called. This object currently contains little to no valuable information beyond the Node.js http.IncomingMessage (the request), http.ServerResponse objects and cloudevent object, 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.

Building

To build the image, run the following command.

make build

You should end up with an image at redhat-faas/js-runtime.

Running locally

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:candidate

To stop the running container:

$ docker ps
$ docker stop <CONTAINER ID>

Testing

To test the image, run the following command.

make test

This 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.

faas-js-runtime-image's People

Contributors

danbev avatar lance avatar lholmquist avatar slinkydeveloper avatar zroubalik avatar

Watchers

 avatar  avatar  avatar  avatar

faas-js-runtime-image's Issues

Convert cloud event into a JS Object

The CloudEvent data that is unmarshalled and attached to the Context instance before calling the hosted function is really only accessible via the CloudEvent.toString() function, which returns a string that looks like this:

 {"specversion":"0.2","id":"32904c7b-1988-4f15-b124-7de161ea4029","type":"dev.knative.cronjob.event","source":"/apis/v1/namespaces/js-faas-demo/cronjobsources/testfunc-cronjob-source","time":"2019-09-17T21:06:00.000Z","contenttype":"application/json","knativehistory":"testfunc-channel-tn4h6.js-faas-demo.svc.cluster.local","data":{"message":"Example message to test Knative Eventing functionality."}}

Why don't we just do this when attaching it to the context?

context.cloudevent = JSON.parse(cldevent.toString());

Since this is almost certainly what the function writer will do in the end.

Getting Permission errors running Make test

Getting this error when doing make test

~/develop/openshift-cloud-functions/faas-js-runtime-image(master) » make test                                                                                        lucasholmquist@lincolnhawk2
./run-test.sh oscf/js-runtime:candidate
Testing oscf/js-runtime:candidate
Building image...
Sending build context to Docker daemon  153.6kB
Step 1/8 : FROM node:12-alpine
 ---> ef7d474eab14
Step 2/8 : EXPOSE 8080
 ---> Using cache
 ---> 84ebcbf8b92a
Step 3/8 : COPY src /home/node/src
 ---> 9f9e8d16bfe5
Step 4/8 : COPY s2i /usr/libexec/s2i
 ---> e4c2046ab91e
Step 5/8 : RUN mkdir -p /home/node/usr &&   chmod -R 777 /home/node &&   cd /home/node/src &&   npm install
 ---> Running in 35e9bc1e9f2d
npm WARN [email protected] No description
npm WARN [email protected] No repository field.
npm WARN [email protected] No license field.

added 17 packages from 23 contributors and audited 19 packages in 1.16s
found 0 vulnerabilities

Removing intermediate container 35e9bc1e9f2d
 ---> 3f84f0333268
Step 6/8 : ENV HOME /home/node
 ---> Running in e76842bd63b6
Removing intermediate container e76842bd63b6
 ---> 6e28b495e827
Step 7/8 : USER 1001
 ---> Running in afddc4255572
Removing intermediate container afddc4255572
 ---> f2d48bf7548a
Step 8/8 : CMD ["/home/node/src/run.sh"]
 ---> Running in 5e0f628179eb
Removing intermediate container 5e0f628179eb
 ---> d4f65e29c875
Successfully built d4f65e29c875
Successfully tagged oscf/js-runtime:candidate
Starting container for oscf/js-runtime:candidate...
docker run --rm --cidfile 157001023422934.cid -a stdout -a stderr -v /home/lucasholmquist/develop/openshift-cloud-functions/faas-js-runtime-image/test:/home/node/usr -p 8080:8080 oscf/js-runtime:candidate &
Giving it a few seconds to initialize...
Waiting for 157001023422934.cid...
+ umask 000
+ cd /home/node/usr
+ '[' -f package.json ]
+ export 'NO_UPDATE_NOTIFIER=true'
+ npm install '--only=prod'
Waiting for package-lock.json...
npm WARN checkPermissions Missing write access to /home/node/usr
npm WARN [email protected] No description
npm WARN [email protected] No repository field.

npm ERR! code EACCES
npm ERR! syscall access
npm ERR! path /home/node/usr
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, access '/home/node/usr'
npm ERR!  [Error: EACCES: permission denied, access '/home/node/usr'] {
npm ERR!   stack: "Error: EACCES: permission denied, access '/home/node/usr'",
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'access',
npm ERR!   path: '/home/node/usr'
npm ERR! }
npm ERR! 
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR! 
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/node/.npm/_logs/2019-10-02T09_57_19_008Z-debug.log
+ cd ../src
+ node .
internal/modules/cjs/loader.js:775
    throw err;
    ^

Error: Cannot find module 'is-number'
Require stack:
- /home/node/usr/index.js
- /home/node/src/index.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:772:15)
    at Function.Module._load (internal/modules/cjs/loader.js:677:27)
    at Module.require (internal/modules/cjs/loader.js:830:19)
    at require (internal/modules/cjs/helpers.js:68:18)
    at Object.<anonymous> (/home/node/usr/index.js:5:18)
    at Module._compile (internal/modules/cjs/loader.js:936:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:947:10)
    at Module.load (internal/modules/cjs/loader.js:790:32)
    at Function.Module._load (internal/modules/cjs/loader.js:703:12)
    at Module.require (internal/modules/cjs/loader.js:830:19)
    at require (internal/modules/cjs/helpers.js:68:18)
    at Object.<anonymous> (/home/node/src/index.js:13:14)
    at Module._compile (internal/modules/cjs/loader.js:936:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:947:10)
    at Module.load (internal/modules/cjs/loader.js:790:32)
    at Function.Module._load (internal/modules/cjs/loader.js:703:12)
    at Function.Module.runMain (internal/modules/cjs/loader.js:999:10)
    at internal/main/run_main_module.js:17:11 {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ '/home/node/usr/index.js', '/home/node/src/index.js' ]
}
Waiting for package-lock.json...
Waiting for package-lock.json...
Waiting for package-lock.json...
Waiting for package-lock.json...
Waiting for package-lock.json...
Waiting for package-lock.json...
Waiting for package-lock.json...
^Cmake: *** [Makefile:15: test] Interrupt

My Docker version on Fedora 29

Client:
 Version:           18.09.3
 API version:       1.39
 Go version:        go1.10.8
 Git commit:        774a1f4
 Built:             Thu Feb 28 06:34:10 2019
 OS/Arch:           linux/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          18.09.3
  API version:      1.39 (minimum version 1.12)
  Go version:       go1.10.8
  Git commit:       774a1f4
  Built:            Thu Feb 28 06:02:24 2019
  OS/Arch:          linux/amd64
  Experimental:     false

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.