mirror of
https://github.com/openfaas/faas.git
synced 2025-06-09 08:46:48 +00:00
Moving out the cat service as an example.
This commit is contained in:
parent
f9fd0a08b5
commit
bdfdd5ad45
28
README.md
28
README.md
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
This project provides a way to run Docker containers as functions on Swarm Mode.
|
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.
|
* 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
|
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.
|
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:
|
Features:
|
||||||
|
|
||||||
* [todo] auto-scaling of replicas as load increases
|
* [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:
|
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
|
# docker network create --driver overlay --attachable functions
|
||||||
# git clone https://github.com/alexellis/faas && cd faas
|
# git clone https://github.com/alexellis/faas && cd faas
|
||||||
# cd watchdog
|
# cd watchdog
|
||||||
# ./build.sh
|
# ./build.sh
|
||||||
# docker build -t catservice .
|
# cd ../sample-functions/catservice/
|
||||||
# docker service rm catservice ; docker service create --network=functions --name catservice catservice
|
# cp ../../watchdog/fwatchdog ./
|
||||||
# cd ..
|
# docker build -t catservice . ; docker service rm catservice ; docker service create --network=functions --name catservice catservice
|
||||||
|
# cd ../../
|
||||||
# cd gateway
|
# 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
|
# 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:
|
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/
|
||||||
|
|
||||||
|
@ -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"]
|
|
17
sample-functions/catservice/README.md
Normal file
17
sample-functions/catservice/README.md
Normal file
@ -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....
|
||||||
|
```
|
@ -1,3 +0,0 @@
|
|||||||
'use strict'
|
|
||||||
let os = require('os');
|
|
||||||
console.log(os.platform(), os.arch(), os.cpus(), os.uptime(), os.userInfo());
|
|
@ -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"
|
|
||||||
}
|
|
@ -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
|
|
||||||
|
|
||||||
```
|
|
Loading…
x
Reference in New Issue
Block a user