From b99555936dddd8ebf0c0d27627b7f9126c9bcbfa Mon Sep 17 00:00:00 2001 From: Tom Wilkie Date: Fri, 18 Sep 2015 13:24:00 +0000 Subject: [PATCH] Add echo server, make it randomly take 2 secs. --- experimental/example/Makefile | 3 ++- experimental/example/app/app.py | 6 ++++- experimental/example/echo/Dockerfile | 8 +++++++ experimental/example/echo/echo.py | 27 ++++++++++++++++++++++ experimental/example/echo/requirements.txt | 2 ++ experimental/example/run.sh | 2 +- 6 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 experimental/example/echo/Dockerfile create mode 100644 experimental/example/echo/echo.py create mode 100644 experimental/example/echo/requirements.txt diff --git a/experimental/example/Makefile b/experimental/example/Makefile index ca854e597..00b8085e8 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 frontend.marker +all: qotd.marker app.marker client.marker searchapp.marker shout.marker frontend.marker echo.marker qotd/qotd: qotd/qotd.o gcc -o $@ $< $(CFLAGS) @@ -21,6 +21,7 @@ client.marker: client/* searchapp.marker: searchapp/* searchapp/searchapp shout.marker: shout/* shout/shout frontend.marker: frontend/* +echo.marker: echo/* %.marker: docker build -t tomwilkie/$( +WORKDIR /home/weave +ADD requirements.txt /home/weave/ +RUN pip install -r /home/weave/requirements.txt +ADD echo.py /home/weave/ +EXPOSE 5000 +ENTRYPOINT ["python", "/home/weave/echo.py"] diff --git a/experimental/example/echo/echo.py b/experimental/example/echo/echo.py new file mode 100644 index 000000000..68fd95ab6 --- /dev/null +++ b/experimental/example/echo/echo.py @@ -0,0 +1,27 @@ +import os +import socket +import sys +import random +import time +import threading +import logging + + +from flask import Flask +from flask import request +from werkzeug.serving import WSGIRequestHandler + +app = Flask(__name__) + +@app.route('/') +def hello(): + if random.random() > 0.6: + time.sleep(2) + else: + time.sleep(0.5) + return request.data + +if __name__ == "__main__": + logging.basicConfig(format='%(asctime)s %(levelname)s %(filename)s:%(lineno)d - %(message)s', level=logging.INFO) + WSGIRequestHandler.protocol_version = "HTTP/1.0" + app.run(host="0.0.0.0", port=80, debug=True) diff --git a/experimental/example/echo/requirements.txt b/experimental/example/echo/requirements.txt new file mode 100644 index 000000000..cd204415b --- /dev/null +++ b/experimental/example/echo/requirements.txt @@ -0,0 +1,2 @@ +flask + diff --git a/experimental/example/run.sh b/experimental/example/run.sh index 7a4dee446..8696d4dab 100755 --- a/experimental/example/run.sh +++ b/experimental/example/run.sh @@ -21,4 +21,4 @@ start_container() { start_container 1 tomwilkie/qotd qotd start_container 1 tomwilkie/app app - +start_container 1 tomwilkie/echo echo