diff --git a/README.md b/README.md index 75f24f50..5c969a34 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ 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 have a look at 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. diff --git a/build.sh b/build.sh new file mode 100755 index 00000000..9c488507 --- /dev/null +++ b/build.sh @@ -0,0 +1,20 @@ +#!/bin/sh + +# First do - git clone https://github.com/alexellis/faas && cd faas + +docker network create --driver overlay --attachable functions + +cd watchdog +./build.sh + +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 + +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 diff --git a/deploy_stack.sh b/deploy_stack.sh new file mode 100755 index 00000000..11d3b1c7 --- /dev/null +++ b/deploy_stack.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +echo "Deploying stack" +docker stack rm func ; docker stack deploy func --compose-file docker-compose.yml + diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..7478f263 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,27 @@ +version: "3" +services: + gateway: + volumes: + - "/var/run/docker.sock:/var/run/docker.sock" + ports: + - 3000:8080 + image: alexellisio/faas-gateway:latest + networks: + - functions + prometheus: + image: quay.io/prometheus/prometheus:latest + volumes: + - ./prometheus/prometheus.yml:/etc/prometheus/prometheus.yml + command: "-config.file=/etc/prometheus/prometheus.yml -storage.local.path=/prometheus -storage.local.memory-chunks=10000" + ports: + - 9090:9090 + depends_on: + - gateway + environment: + no_proxy: "gateway" + networks: + - functions +networks: + functions: + driver: overlay + #attachable: true diff --git a/gateway/Dockerfile b/gateway/Dockerfile index db3d4df6..27812a05 100644 --- a/gateway/Dockerfile +++ b/gateway/Dockerfile @@ -1,19 +1,9 @@ -from golang:1.7.3 +FROM golang:1.7.3 -RUN go get -d github.com/docker/docker/api/types \ - && go get -d github.com/docker/docker/api/types/filters \ - && go get -d github.com/docker/docker/api/types/swarm \ - && go get -d github.com/docker/docker/client \ - && go get github.com/gorilla/mux \ - && go get github.com/prometheus/client_golang/prometheus +COPY gateway . -WORKDIR /go/src/github.com/alexellis/faas/gateway - -COPY metrics metrics -COPY server.go . - -RUN find /go/src/github.com/alexellis/faas/gateway/ -RUN go build EXPOSE 8080 +ENV http_proxy "" +ENV https_proxy "" CMD ["./gateway"] diff --git a/gateway/Dockerfile.build b/gateway/Dockerfile.build new file mode 100644 index 00000000..f7498e98 --- /dev/null +++ b/gateway/Dockerfile.build @@ -0,0 +1,16 @@ +FROM golang:1.7.3 + +RUN go get -d github.com/docker/docker/api/types \ + && go get -d github.com/docker/docker/api/types/filters \ + && go get -d github.com/docker/docker/api/types/swarm \ + && go get -d github.com/docker/docker/client \ + && go get github.com/gorilla/mux \ + && go get github.com/prometheus/client_golang/prometheus + +WORKDIR /go/src/github.com/alexellis/faas/gateway + +COPY metrics metrics +COPY server.go . + +RUN find /go/src/github.com/alexellis/faas/gateway/ +RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o app . diff --git a/gateway/build.sh b/gateway/build.sh index 3b05335b..50a753b1 100755 --- a/gateway/build.sh +++ b/gateway/build.sh @@ -1,4 +1,13 @@ #!/bin/sh -echo Building server:latest +echo Building alexellis2/faas-gateway:build -docker build -t server . +docker build --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy \ + -t alexellis2/faas-gateway:build . -f Dockerfile.build + +docker create --name gateway_extract alexellis2/faas-gateway:build +docker cp gateway_extract:/go/src/github.com/alexellis/faas/gateway/app ./gateway +docker rm -f gateway_extract + +echo Building alexellis2/faas-gateway:latest + +docker build -t alexellis2/faas-gateway:latest . diff --git a/monitor/._prometheus.yml b/monitor/._prometheus.yml new file mode 100755 index 00000000..576dbecf Binary files /dev/null and b/monitor/._prometheus.yml differ diff --git a/oneshot.sh b/oneshot.sh deleted file mode 100755 index 53aac2e7..00000000 --- a/oneshot.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/sh - -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 gateway -docker build -t server . ;docker rm -f server; docker run -d -v /var/run/docker.sock:/var/run/docker.sock --name server -p 8080:8080 --network=functions server - diff --git a/prometheus/prometheus.yml b/prometheus/prometheus.yml new file mode 100644 index 00000000..ad723850 --- /dev/null +++ b/prometheus/prometheus.yml @@ -0,0 +1,34 @@ +# my global config +global: + scrape_interval: 15s # By default, scrape targets every 15 seconds. + evaluation_interval: 15s # By default, scrape targets every 15 seconds. + # scrape_timeout is set to the global default (10s). + + # Attach these labels to any time series or alerts when communicating with + # external systems (federation, remote storage, Alertmanager). + external_labels: + monitor: 'codelab-monitor' + +# Load rules once and periodically evaluate them according to the global 'evaluation_interval'. +rule_files: + # - "first.rules" + # - "second.rules" + +# A scrape configuration containing exactly one endpoint to scrape: +# Here it's Prometheus itself. +scrape_configs: + # The job name is added as a label `job=` to any timeseries scraped from this config. + - job_name: 'prometheus' + + # Override the global default and scrape targets from this job every 5 seconds. + scrape_interval: 5s + + # metrics_path defaults to '/metrics' + # scheme defaults to 'http'. + static_configs: + - targets: ['localhost:9090'] + + - job_name: "gateway" + scrape_interval: "15s" + static_configs: + - targets: ['gateway:8080'] diff --git a/watchdog/build.sh b/watchdog/build.sh index 2ac2ae03..c48da1f7 100755 --- a/watchdog/build.sh +++ b/watchdog/build.sh @@ -3,7 +3,8 @@ # Below makes use of "builder pattern" so that binary is extracted separate # from the golang runtime/SDK -docker build -t watchdog:latest . -docker create --name buildoutput watchdog:latest +docker build --build-arg https_proxy=$https_proxy --build-arg http_proxy=$http_proxy \ + -t alexellis2/faas-watchdog:build . +docker create --name buildoutput alexellis2/faas-watchdog:build docker cp buildoutput:/go/src/app/app ./fwatchdog docker rm buildoutput