* - Extend stack to include a test function
* - Allow _ char in routes
* - Let Dockerfile shrink by coming from alpine

* Update build.sh

* Document stack deploy

* Update README.md

* fix port in README (#3)
This commit is contained in:
Alex Ellis 2017-01-09 20:02:18 +00:00 committed by GitHub
parent fe9ada50bd
commit f944b088be
5 changed files with 57 additions and 11 deletions

View File

@ -5,17 +5,50 @@ 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 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.
## Quickstart
Minimum requirements:
## Minimum requirements:
* Docker 1.13-RC (to support attachable overlay networks)
* At least a single host in Swarm Mode. (run `docker swarm init`)
`For more information on Swarm mode and configuration please have a look at the [Swarm Mode tutorial](https://docs.docker.com/engine/swarm/swarm-tutorial/). `
> For more information on Swarm mode and configuration please read the [Swarm Mode tutorial](https://docs.docker.com/engine/swarm/swarm-tutorial/).
Check your `docker version` and upgrade to one of the latest 1.13-RCs from the [Docker Releases page](https://github.com/docker/docker/releases). This is already available through the Beta channel in Docker for Mac.
## Quickstart with `docker stack deploy`
For a complete stack of Prometheus, the gateway and the DockerHubStats function:
* Simply run `./deploy_stack.sh` - following that you can find out information about the services like this:
```
# docker stack ls
NAME SERVICES
func 3
# docker stack ps func
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE
rhzej73haufd func_gateway.1 alexellis2/faas-gateway:latest moby Running Running 26 minutes ago
fssz6unq3e74 func_hubstats.1 alexellis2/faas-dockerhubstats:latest moby Running Running 27 minutes ago
nnlzo6u3pilg func_prometheus.1 quay.io/prometheus/prometheus:latest moby Running Running 27 minutes ago
```
* Then head over to http://localhost:9090 for your Prometheus metrics
* Your function can be accessed via the gateway like this:
```
# curl -X POST http://localhost:8080/function/func_hubstats -d "alexellis2"
The organisation or user alexellis2 has 99 repositories on the Docker hub.
# curl -X POST http://localhost:8080/function/func_hubstats -d "library"
The organisation or user library has 128 repositories on the Docker hub.
```
The `-d` value passes in the argument for your function. This is read via STDIN and used to query the Docker Hub to see how many images you've created/pushed.
If you're looking for a UI checkout the [Postman plugin for Chrome](https://www.getpostman.com) where you can send POSTs without needing `curl`.
## Manual quickstart
#### Create an attachable network for the gateway and functions to join
```

View File

@ -11,10 +11,10 @@ cp ./fwatchdog ../sample-functions/catservice/
docker build --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy \
-t alexellis2/faas-catservice .
docker service rm catservice ; docker service create --network=functions --name catservice alexellis2/faas-catservice
#docker service rm catservice ; docker service create --network=functions --name catservice alexellis2/faas-catservice
cd ..
cd gateway
./build.sh
docker rm -f server; docker run -d -v /var/run/docker.sock:/var/run/docker.sock --name server -p 8080:8080 --network=functions alexellis2/faas-gateway
# docker rm -f server; docker run -d -v /var/run/docker.sock:/var/run/docker.sock --name server -p 8080:8080 --network=functions alexellis2/faas-gateway

View File

@ -4,10 +4,11 @@ services:
volumes:
- "/var/run/docker.sock:/var/run/docker.sock"
ports:
- 3000:8080
image: alexellisio/faas-gateway:latest
- 8080:8080
image: alexellis2/faas-gateway:latest
networks:
- functions
prometheus:
image: quay.io/prometheus/prometheus:latest
volumes:
@ -21,7 +22,20 @@ services:
no_proxy: "gateway"
networks:
- functions
# Sample functions go here.
hubstats:
image: alexellis2/faas-dockerhubstats:latest
depends_on:
- gateway
networks:
- functions
environment:
no_proxy: "gateway"
https_proxy: $https_proxy
networks:
functions:
driver: overlay
# Docker does not support this option yet - maybe create outside of the stack and reference as "external"?
#attachable: true

View File

@ -1,4 +1,3 @@
FROM golang:1.7.3
FROM alpine:latest
COPY gateway .

View File

@ -185,7 +185,7 @@ func main() {
r := mux.NewRouter()
r.HandleFunc("/", makeProxy(metricsOptions, false))
r.HandleFunc("/function/{name:[a-zA-Z]+}", makeProxy(metricsOptions, true))
r.HandleFunc("/function/{name:[a-zA-Z_]+}", makeProxy(metricsOptions, true))
metricsHandler := metrics.PrometheusHandler()
r.Handle("/metrics", metricsHandler)