From bdfdd5ad457347114f3e95df176ab04eca0f21a4 Mon Sep 17 00:00:00 2001 From: Alex <alexellis2@gmail.com> Date: Tue, 3 Jan 2017 23:31:55 +0000 Subject: [PATCH] Moving out the cat service as an example. --- README.md | 28 +++++++++++++++---- sample-functions/Dockerfile | 9 ------ .../catservice}/Dockerfile | 0 sample-functions/catservice/README.md | 17 +++++++++++ sample-functions/main.js | 3 -- sample-functions/package.json | 12 -------- watchdog/README.md | 8 ------ 7 files changed, 40 insertions(+), 37 deletions(-) delete mode 100644 sample-functions/Dockerfile rename {watchdog => sample-functions/catservice}/Dockerfile (100%) create mode 100644 sample-functions/catservice/README.md delete mode 100644 sample-functions/main.js delete mode 100644 sample-functions/package.json delete mode 100644 watchdog/README.md diff --git a/README.md b/README.md index 102e44f4..8f9afde6 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 03a7fcd6..00000000 --- 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 00000000..b50c03f8 --- /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 13374e73..00000000 --- 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 fa4598bc..00000000 --- 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 ec70bd07..00000000 --- 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 - -``` -- GitLab