]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Add a docker-based environment for running the blog demo.
authorBen Darnell <ben@bendarnell.com>
Sat, 28 Mar 2015 19:27:56 +0000 (15:27 -0400)
committerBen Darnell <ben@bendarnell.com>
Sat, 28 Mar 2015 19:27:56 +0000 (15:27 -0400)
demos/blog/Dockerfile [new file with mode: 0644]
demos/blog/README
demos/blog/blog.py
demos/blog/docker-compose.yml [new file with mode: 0644]
demos/blog/requirements.txt [new file with mode: 0644]

diff --git a/demos/blog/Dockerfile b/demos/blog/Dockerfile
new file mode 100644 (file)
index 0000000..c9aab50
--- /dev/null
@@ -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
index dc2a4d8e98968f08dcee16e7a6d85f6559a44955..72f0774f39994c7a844ab49054f91a01ee13199e 100644 (file)
@@ -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
index 05ef84db3042aa322d17150a438d97b715ed9892..26748dec6e63f3e5548e2ec285b461dba28a1672 100755 (executable)
 # 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 (file)
index 0000000..c651ed7
--- /dev/null
@@ -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 (file)
index 0000000..77c06f8
--- /dev/null
@@ -0,0 +1,4 @@
+MySQL-python
+markdown
+tornado
+torndb