mirror of
https://github.com/openfaas/faas.git
synced 2025-06-13 18:56:46 +00:00
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)
This commit is contained in:
parent
fe9ada50bd
commit
f944b088be
43
README.md
43
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.
|
* 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.
|
||||||
|
|
||||||
## Quickstart
|
## Minimum requirements:
|
||||||
|
|
||||||
Minimum requirements:
|
|
||||||
|
|
||||||
* Docker 1.13-RC (to support attachable overlay networks)
|
* Docker 1.13-RC (to support attachable overlay networks)
|
||||||
* At least a single host in Swarm Mode. (run `docker swarm init`)
|
* 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.
|
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
|
#### Create an attachable network for the gateway and functions to join
|
||||||
|
|
||||||
```
|
```
|
||||||
|
4
build.sh
4
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 \
|
docker build --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy \
|
||||||
-t alexellis2/faas-catservice .
|
-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 ..
|
||||||
|
|
||||||
cd gateway
|
cd gateway
|
||||||
./build.sh
|
./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
|
||||||
|
@ -4,10 +4,11 @@ services:
|
|||||||
volumes:
|
volumes:
|
||||||
- "/var/run/docker.sock:/var/run/docker.sock"
|
- "/var/run/docker.sock:/var/run/docker.sock"
|
||||||
ports:
|
ports:
|
||||||
- 3000:8080
|
- 8080:8080
|
||||||
image: alexellisio/faas-gateway:latest
|
image: alexellis2/faas-gateway:latest
|
||||||
networks:
|
networks:
|
||||||
- functions
|
- functions
|
||||||
|
|
||||||
prometheus:
|
prometheus:
|
||||||
image: quay.io/prometheus/prometheus:latest
|
image: quay.io/prometheus/prometheus:latest
|
||||||
volumes:
|
volumes:
|
||||||
@ -21,7 +22,20 @@ services:
|
|||||||
no_proxy: "gateway"
|
no_proxy: "gateway"
|
||||||
networks:
|
networks:
|
||||||
- functions
|
- 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:
|
networks:
|
||||||
functions:
|
functions:
|
||||||
driver: overlay
|
driver: overlay
|
||||||
|
# Docker does not support this option yet - maybe create outside of the stack and reference as "external"?
|
||||||
#attachable: true
|
#attachable: true
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
FROM golang:1.7.3
|
|
||||||
FROM alpine:latest
|
FROM alpine:latest
|
||||||
|
|
||||||
COPY gateway .
|
COPY gateway .
|
||||||
|
@ -185,7 +185,7 @@ func main() {
|
|||||||
r := mux.NewRouter()
|
r := mux.NewRouter()
|
||||||
r.HandleFunc("/", makeProxy(metricsOptions, false))
|
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()
|
metricsHandler := metrics.PrometheusHandler()
|
||||||
r.Handle("/metrics", metricsHandler)
|
r.Handle("/metrics", metricsHandler)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user