diff --git a/README.md b/README.md index 102e44f40cbdf3271229b89ab0fbf273069a3b6c..8f9afde6407b84a1d3b9c97c785f217853e43b72 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ This project provides a way to run Docker containers as functions on Swarm Mode. -* Each container has a watchdog process that hosts a web server allowing a JSON post request to be fowarded to a desired process via STDIN. The respose is sent to the caller via STDOUT. +* Each container has a watchdog process that hosts a web server allowing a JSON post request to be forwarded to a desired process via STDIN. The respose is sent to the caller via STDOUT. * A gateway provides a view to the containers/functions to the public Internet and collects metrics for Prometheus and in a future version will manage replicas and scale as throughput increases. Minimum requirements: Docker 1.13 @@ -12,6 +12,14 @@ gateway This container acts in a similar way to the API Gateway on AWS. Requests can be made to this endpoint with a JSON body. +**Incoming requests and routing** + +There are three options for routing: + +* Routing is enabled through a `X-Function` header which matches a service name (function) directly. +* Routing automatically detects Alexa SDK requests and forwards to a service name (function) that matches the Intent name +* [todo] individual routes can be set up mapping to a specific service name (function). + Features: * [todo] auto-scaling of replicas as load increases @@ -33,14 +41,17 @@ This binary fwatchdog acts as a watchdog for your function. Features: Complete example: ================= +To use multiple hosts you should push your services (functions) to the Docker Hub or a registry accessible to all nodes. + ``` # docker network create --driver overlay --attachable functions # git clone https://github.com/alexellis/faas && cd faas # cd watchdog # ./build.sh -# docker build -t catservice . -# docker service rm catservice ; docker service create --network=functions --name catservice catservice -# cd .. +# cd ../sample-functions/catservice/ +# cp ../../watchdog/fwatchdog ./ +# docker build -t catservice . ; docker service rm catservice ; docker service create --network=functions --name catservice catservice +# cd ../../ # cd gateway # docker build -t server . ;docker rm -f server; docker run -v /var/run/docker.sock:/var/run/docker.sock --name server -p 8080:8080 --network=functions server ``` @@ -48,6 +59,13 @@ Complete example: Accessing the `cat` (read echo) service: ``` -# curl -X POST -H 'x-function: catservice' --data-binary @/etc/hostname -v http://localhost:8080/curl -X POST -H 'x-function: catservice' --data-binary @$HOME/.ssh/known_hosts -v http://localhost:8080/ +# curl -X POST -H 'x-function: catservice' --data-binary @$HOME/.ssh/known_hosts -v http://localhost:8080/ + +# curl -X POST -H 'x-function: catservice' --data-binary @/etc/hostname -v http://localhost:8080/ ``` +Prometheus metrics / instrumentation +==================================== + +* Standard go metrics and function invocation count / duration are available at http://localhost:8080/metrics/ + diff --git a/sample-functions/Dockerfile b/sample-functions/Dockerfile deleted file mode 100644 index 03a7fcd603b1d92daa9da4f36f4fc345ba912dbc..0000000000000000000000000000000000000000 --- a/sample-functions/Dockerfile +++ /dev/null @@ -1,9 +0,0 @@ -FROM alpine:latest -RUN apk --update add nodejs -COPY ./fwatchdog /usr/bin/ - -COPY package.json . -COPY main.js . -RUN npm i -ENV fprocess="node main.js" -CMD ["fwatchdog"] diff --git a/watchdog/Dockerfile b/sample-functions/catservice/Dockerfile similarity index 100% rename from watchdog/Dockerfile rename to sample-functions/catservice/Dockerfile diff --git a/sample-functions/catservice/README.md b/sample-functions/catservice/README.md new file mode 100644 index 0000000000000000000000000000000000000000..b50c03f83ae9e93cd7654b9c797aad8146ae2635 --- /dev/null +++ b/sample-functions/catservice/README.md @@ -0,0 +1,17 @@ +* Build the watchdog app which outputs fwatchdog + +* Copy fwatchdog to the directory of each function you want to build. + +* Create a service for each function: + +``` +# docker build -t catservice . +# docker service rm catservice ; docker service create --network=functions --name catservice catservice +``` + +* Consume it like this: + +``` +# curl -X POST -d @$HOME/.ssh/id_rsa.pub -H "X-Function: catservice" localhost:8080/ +ssh-rsa AAAAB3NzaC1yc2.... +``` diff --git a/sample-functions/main.js b/sample-functions/main.js deleted file mode 100644 index 13374e73078adea0dba8f6c32ccdeb73ff931b2b..0000000000000000000000000000000000000000 --- a/sample-functions/main.js +++ /dev/null @@ -1,3 +0,0 @@ -'use strict' -let os = require('os'); -console.log(os.platform(), os.arch(), os.cpus(), os.uptime(), os.userInfo()); diff --git a/sample-functions/package.json b/sample-functions/package.json deleted file mode 100644 index fa4598bc3bffa204be9a34e72552c2078edf852a..0000000000000000000000000000000000000000 --- a/sample-functions/package.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "name": "sample-functions", - "version": "1.0.0", - "description": "", - "main": "main.js", - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" - }, - "keywords": [], - "author": "", - "license": "ISC" -} diff --git a/watchdog/README.md b/watchdog/README.md deleted file mode 100644 index ec70bd073b89bcb7fff6169e757bc0e546bef80a..0000000000000000000000000000000000000000 --- a/watchdog/README.md +++ /dev/null @@ -1,8 +0,0 @@ -``` -# ./build.sh -# docker build -t catservice . -# docker run -ti -p 8080:8080 catservice - -# curl -X POST --data-binary @main.go localhost:8080 - -```