From f944b088be34a0bac38a44318e7308c412d56611 Mon Sep 17 00:00:00 2001 From: Alex Ellis Date: Mon, 9 Jan 2017 20:02:18 +0000 Subject: [PATCH] Stack 1 (#4) * - 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) --- README.md | 43 ++++++++++++++++++++++++++++++++++++++----- build.sh | 4 ++-- docker-compose.yml | 18 ++++++++++++++++-- gateway/Dockerfile | 1 - gateway/server.go | 2 +- 5 files changed, 57 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 5c969a34..0f80438c 100644 --- a/README.md +++ b/README.md @@ -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 ``` diff --git a/build.sh b/build.sh index 9c488507..2b524325 100755 --- a/build.sh +++ b/build.sh @@ -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 diff --git a/docker-compose.yml b/docker-compose.yml index 7478f263..d5bff2f1 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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 diff --git a/gateway/Dockerfile b/gateway/Dockerfile index f337be3a..6084f1ba 100644 --- a/gateway/Dockerfile +++ b/gateway/Dockerfile @@ -1,4 +1,3 @@ -FROM golang:1.7.3 FROM alpine:latest COPY gateway . diff --git a/gateway/server.go b/gateway/server.go index 6b00b139..e5e74d53 100644 --- a/gateway/server.go +++ b/gateway/server.go @@ -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)