Created
July 6, 2015 14:22
-
-
Save anonymous/a828e94693532477b167 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
from flask import Flask, request | |
from tornado.wsgi import WSGIContainer | |
from tornado.httpserver import HTTPServer | |
from tornado.ioloop import IOLoop | |
app = Flask(__name__) | |
@app.before_request | |
def start_request(*args, **kwargs): | |
request.real_ip = request.headers.get('X-Real-Ip', request.remote_addr) | |
request.start_time = time.time() | |
print("REQUEST STARTED:", request.real_ip, request.method, request.url) | |
@app.after_request | |
def end_request(response_class, *args, **kwargs): | |
request.end_time = time.time() | |
request_processing_time = "{0:.6f}".format(request.end_time - request.start_time) | |
print("REQUEST FINISHED (took ", request_processing_time, "seconds):", request.real_ip, request.method, request.url) | |
return response_class | |
@app.route('/') | |
def hello(): | |
return "Hello World!!!" | |
def main(): | |
http_server = HTTPServer(WSGIContainer(app)) | |
http_server.bind(80, address="0.0.0.0") | |
print("starting") | |
http_server.start(5) | |
IOLoop.instance().start() | |
if __name__ == '__main__': | |
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM ubuntu:14.04 | |
WORKDIR /opt/example | |
RUN apt-get update | |
run apt-get install -y make python-virtualenv | |
ADD Makefile /opt/example/Makefile | |
ADD app.py /opt/example/app.py | |
ADD requirements.txt /opt/example/requirements.txt | |
RUN make venv | |
EXPOSE 80 | |
CMD make run |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
http://localhost:8080/ | |
http://localhost:8081/ | |
http://localhost:8082/ | |
http://localhost:8083/ | |
http://localhost:8084/ | |
http://localhost:8085/ | |
http://localhost:8086/ | |
http://localhost:8087/ | |
http://localhost:8088/ | |
http://localhost:8089/ | |
http://localhost:8090/ | |
http://localhost:8091/ | |
http://localhost:8092/ | |
http://localhost:8093/ | |
http://localhost:8094/ | |
http://localhost:8095/ | |
http://localhost:8096/ | |
http://localhost:8097/ | |
http://localhost:8098/ | |
http://localhost:8099/ | |
http://localhost:8100/ | |
http://localhost:8101/ | |
http://localhost:8102/ | |
http://localhost:8103/ | |
http://localhost:8104/ | |
http://localhost:8105/ | |
http://localhost:8106/ | |
http://localhost:8107/ | |
http://localhost:8108/ | |
http://localhost:8109/ | |
http://localhost:8110/ | |
http://localhost:8111/ | |
http://localhost:8112/ | |
http://localhost:8113/ | |
http://localhost:8114/ | |
http://localhost:8115/ | |
http://localhost:8116/ | |
http://localhost:8117/ | |
http://localhost:8118/ | |
http://localhost:8119/ | |
http://localhost:8120/ | |
http://localhost:8121/ | |
http://localhost:8122/ | |
http://localhost:8123/ | |
http://localhost:8124/ | |
http://localhost:8125/ | |
http://localhost:8126/ | |
http://localhost:8127/ | |
http://localhost:8128/ | |
http://localhost:8129/ | |
http://localhost:8130/ | |
http://localhost:8131/ | |
http://localhost:8132/ | |
http://localhost:8133/ | |
http://localhost:8134/ | |
http://localhost:8135/ | |
http://localhost:8136/ | |
http://localhost:8137/ | |
http://localhost:8138/ | |
http://localhost:8139/ | |
http://localhost:8140/ | |
http://localhost:8141/ | |
http://localhost:8142/ | |
http://localhost:8143/ | |
http://localhost:8144/ | |
http://localhost:8145/ | |
http://localhost:8146/ | |
http://localhost:8147/ | |
http://localhost:8148/ | |
http://localhost:8149/ | |
http://localhost:8150/ | |
http://localhost:8151/ | |
http://localhost:8152/ | |
http://localhost:8153/ | |
http://localhost:8154/ | |
http://localhost:8155/ | |
http://localhost:8156/ | |
http://localhost:8157/ | |
http://localhost:8158/ | |
http://localhost:8159/ | |
http://localhost:8160/ | |
http://localhost:8161/ | |
http://localhost:8162/ | |
http://localhost:8163/ | |
http://localhost:8164/ | |
http://localhost:8165/ | |
http://localhost:8166/ | |
http://localhost:8167/ | |
http://localhost:8168/ | |
http://localhost:8169/ | |
http://localhost:8170/ | |
http://localhost:8171/ | |
http://localhost:8172/ | |
http://localhost:8173/ | |
http://localhost:8174/ | |
http://localhost:8175/ | |
http://localhost:8176/ | |
http://localhost:8177/ | |
http://localhost:8178/ | |
http://localhost:8179/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
venv: venv/bin/activate | |
venv/bin/activate: | |
virtualenv -p /usr/bin/python3 venv | |
venv/bin/pip install -Ur requirements.txt | |
run: venv | |
. venv/bin/activate && python3 app.py | |
build-docker: Dockerfile | |
sudo docker build -t example:0.0.1 . | |
.PHONY: venv install dist run build-docker |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
flask | |
tornado |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
for (( PORT=8080; PORT<=8180; PORT++ )) | |
do | |
docker run -p $PORT:80 -d -t example:0.0.1 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment