Skip to content
Snippets Groups Projects
Commit bdfdd5ad authored by Alex's avatar Alex
Browse files

Moving out the cat service as an example.

parent f9fd0a08
No related branches found
No related tags found
No related merge requests found
......@@ -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/
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"]
File moved
* 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....
```
'use strict'
let os = require('os');
console.log(os.platform(), os.arch(), os.cpus(), os.uptime(), os.userInfo());
{
"name": "sample-functions",
"version": "1.0.0",
"description": "",
"main": "main.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC"
}
```
# ./build.sh
# docker build -t catservice .
# docker run -ti -p 8080:8080 catservice
# curl -X POST --data-binary @main.go localhost:8080
```
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment