diff --git a/experimental/example/Makefile b/experimental/example/Makefile index 1c40168c2..ca854e597 100644 --- a/experimental/example/Makefile +++ b/experimental/example/Makefile @@ -1,7 +1,7 @@ CC=gcc CFLAGS=-g -lpthread -all: qotd.marker app.marker client.marker searchapp.marker shout.marker +all: qotd.marker app.marker client.marker searchapp.marker shout.marker frontend.marker qotd/qotd: qotd/qotd.o gcc -o $@ $< $(CFLAGS) @@ -20,6 +20,7 @@ app.marker: app/* client.marker: client/* searchapp.marker: searchapp/* searchapp/searchapp shout.marker: shout/* shout/shout +frontend.marker: frontend/* %.marker: docker build -t tomwilkie/$( app --> searchapp -> elasticsearch - | - --> qotd -> internet - | - --> redis +curl -> frontend --> app --> searchapp -> elasticsearch + (nginx) | + --> qotd -> internet + | + --> redis ``` diff --git a/experimental/example/app/app.py b/experimental/example/app/app.py index f7a2d643a..ed009947d 100644 --- a/experimental/example/app/app.py +++ b/experimental/example/app/app.py @@ -57,4 +57,4 @@ def hello(): if __name__ == "__main__": logging.basicConfig(format='%(asctime)s %(levelname)s %(filename)s:%(lineno)d - %(message)s', level=logging.INFO) WSGIRequestHandler.protocol_version = "HTTP/1.1" - app.run(host="0.0.0.0", port=5000, debug=True) + app.run(host="0.0.0.0", port=80, debug=True) diff --git a/experimental/example/client/client.py b/experimental/example/client/client.py index 29e76eb00..d73dff53d 100644 --- a/experimental/example/client/client.py +++ b/experimental/example/client/client.py @@ -3,21 +3,28 @@ import random import threading import time import logging +import socket import sys -app = 'http://app:5000/' +frontend = 'frontend' concurrency = 2 +def do_request(s): + addrs = socket.getaddrinfo(frontend, 80) + if len(addrs) <= 0: + return + addr = random.choice(addrs) + s.get("http://%s:%d" % addr[4], timeout=1.0) + def do_requests(): s = requests.Session() while True: try: - s.get(app, timeout=1.0) - logging.info("Did request") - time.sleep(1) + do_request(s) except: logging.error("Error doing request", exc_info=sys.exc_info()) - time.sleep(1) + + time.sleep(1) logging.info("Did request") def main(): diff --git a/experimental/example/frontend/Dockerfile b/experimental/example/frontend/Dockerfile new file mode 100644 index 000000000..d325d7619 --- /dev/null +++ b/experimental/example/frontend/Dockerfile @@ -0,0 +1,11 @@ +FROM ubuntu +MAINTAINER Weaveworks Inc +RUN apt-get update && \ + apt-get install -y nginx && \ + rm -rf /var/lib/apt/lists/* +RUN rm /etc/nginx/sites-available/default && \ + ln -sf /dev/stdout /var/log/nginx/access.log && \ + ln -sf /dev/stderr /var/log/nginx/error.log +COPY default.conf /etc/nginx/conf.d/ +EXPOSE 80 +CMD ["nginx", "-g", "daemon off;"] diff --git a/experimental/example/frontend/default.conf b/experimental/example/frontend/default.conf new file mode 100644 index 000000000..c32910569 --- /dev/null +++ b/experimental/example/frontend/default.conf @@ -0,0 +1,8 @@ +server { + listen 80; + resolver dns.weave.local:53; + + location / { + proxy_pass http://app.weave.local$request_uri; + } +} diff --git a/experimental/example/run.sh b/experimental/example/run.sh index 18e2425a2..ceeac18ca 100755 --- a/experimental/example/run.sh +++ b/experimental/example/run.sh @@ -2,24 +2,27 @@ set -eux -REPLICAS=${REPLICAS:-1} +eval $(weave env) start_container() { - IMAGE=$1 - BASENAME=${2:-$1} + IMAGE=$2 + BASENAME=$3 + REPLICAS=$1 + shift 3 HOSTNAME=$BASENAME.weave.local for i in $(seq $REPLICAS); do if docker inspect $BASENAME$i >/dev/null 2>&1; then docker rm -f $BASENAME$i fi - weave run --with-dns --name=$BASENAME$i --hostname=$HOSTNAME $IMAGE + docker run -d --name=$BASENAME$i --hostname=$HOSTNAME $@ $IMAGE done } -start_container elasticsearch -start_container tomwilkie/searchapp searchapp -start_container redis -start_container tomwilkie/qotd qotd -start_container tomwilkie/app app -start_container tomwilkie/client client +start_container 1 elasticsearch elasticsearch +start_container 2 tomwilkie/searchapp searchapp +start_container 1 redis redis +start_container 1 tomwilkie/qotd qotd +start_container 2 tomwilkie/app app +start_container 2 tomwilkie/frontend frontend --add-host=dns.weave.local:$(weave docker-bridge-ip) +start_container 1 tomwilkie/client client