From: Ben Darnell Date: Sat, 28 Mar 2015 19:27:56 +0000 (-0400) Subject: Add a docker-based environment for running the blog demo. X-Git-Tag: v4.2.0b1~47 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c360c34890910de7ae0d70f5d7e1f89cc18a1773;p=thirdparty%2Ftornado.git Add a docker-based environment for running the blog demo. --- diff --git a/demos/blog/Dockerfile b/demos/blog/Dockerfile new file mode 100644 index 000000000..c9aab508d --- /dev/null +++ b/demos/blog/Dockerfile @@ -0,0 +1,7 @@ +FROM python:2.7-onbuild + +EXPOSE 8888 + +RUN apt-get update && apt-get install -y mysql-client + +CMD python blog.py --mysql_host=mysql diff --git a/demos/blog/README b/demos/blog/README index dc2a4d8e9..72f0774f3 100644 --- a/demos/blog/README +++ b/demos/blog/README @@ -4,6 +4,9 @@ This demo is a simple blogging engine that uses MySQL to store posts and Google Accounts for author authentication. Since it depends on MySQL, you need to set up MySQL and the database schema for the demo to run. +If you have `docker` and `docker-compose` installed, the demo and all +its prerequisites can be installed with `docker-compose up`. + 1. Install prerequisites and build tornado See http://www.tornadoweb.org/ for installation instructions. If you can diff --git a/demos/blog/blog.py b/demos/blog/blog.py index 05ef84db3..26748dec6 100755 --- a/demos/blog/blog.py +++ b/demos/blog/blog.py @@ -14,9 +14,11 @@ # License for the specific language governing permissions and limitations # under the License. +import MySQLdb import markdown import os.path import re +import subprocess import torndb import tornado.auth import tornado.httpserver @@ -62,6 +64,19 @@ class Application(tornado.web.Application): host=options.mysql_host, database=options.mysql_database, user=options.mysql_user, password=options.mysql_password) + self.maybe_create_tables() + + def maybe_create_tables(self): + try: + self.db.get("SELECT COUNT(*) from entries;") + except MySQLdb.ProgrammingError: + subprocess.check_call(['mysql', + '--host=' + options.mysql_host, + '--database=' + options.mysql_database, + '--user=' + options.mysql_user, + '--password=' + options.mysql_password], + stdin=open('schema.sql')) + class BaseHandler(tornado.web.RequestHandler): @property diff --git a/demos/blog/docker-compose.yml b/demos/blog/docker-compose.yml new file mode 100644 index 000000000..c651ed71d --- /dev/null +++ b/demos/blog/docker-compose.yml @@ -0,0 +1,13 @@ +mysql: + image: mysql:5.6 + environment: + MYSQL_ROOT_PASSWORD: its_a_secret_to_everybody + MYSQL_USER: blog + MYSQL_PASSWORD: blog + MYSQL_DATABASE: blog +blog: + build: . + links: + - mysql + ports: + - "8888:8888" diff --git a/demos/blog/requirements.txt b/demos/blog/requirements.txt new file mode 100644 index 000000000..77c06f885 --- /dev/null +++ b/demos/blog/requirements.txt @@ -0,0 +1,4 @@ +MySQL-python +markdown +tornado +torndb