Configure dockerfile with passenger. Add sample applications.
authorPeter Amstutz <peter.amstutz@curoverse.com>
Fri, 16 Jan 2015 17:02:55 +0000 (12:02 -0500)
committerPeter Amstutz <peter.amstutz@curoverse.com>
Fri, 16 Jan 2015 17:02:55 +0000 (12:02 -0500)
14 files changed:
Dockerfile
README [new file with mode: 0644]
apache2_vhost
arv-web-example.py
sample-cgi-app/public/index.cgi [new file with mode: 0644]
sample-cgi-app/tmp/.keepkeep [new file with mode: 0644]
sample-rack-app/config.ru [new file with mode: 0644]
sample-rack-app/public/.keepkeep [new file with mode: 0644]
sample-rack-app/tmp/.keepkeep [new file with mode: 0644]
sample-static-page/public/index.html [new file with mode: 0644]
sample-static-page/tmp/.keepkeep [new file with mode: 0644]
sample-wsgi-app/passenger_wsgi.py [new file with mode: 0644]
sample-wsgi-app/public/.keepkeep [new file with mode: 0644]
sample-wsgi-app/tmp/.keepkeep [new file with mode: 0644]

index 9f2c62b00ba8b7ca596db5e0156f0139e636b7ff..d0a6abe8299bf66dc630327972ecc38ec99eb5d3 100644 (file)
@@ -7,14 +7,21 @@ RUN apt-get install -qqy \
         libcurl4-openssl-dev apache2-threaded-dev \
         libapr1-dev libaprutil1-dev
 
-# Install apache configuration...
+RUN cd /usr/src/arvados/services/api && \
+    /usr/local/rvm/bin/rvm-exec default bundle exec passenger-install-apache2-module --auto --languages ruby,python
+
+RUN cd /usr/src/arvados/services/api && \
+    /usr/local/rvm/bin/rvm-exec default bundle exec passenger-install-apache2-module --snippet > /etc/apache2/conf.d/passenger
+
+ADD apache2_foreground.sh /etc/apache2/foreground.sh
 
 ADD apache2_vhost /etc/apache2/sites-available/arv-web
 RUN \
+  mkdir /var/run/apache2 && \
   a2dissite default && \
   a2ensite arv-web && \
   a2enmod rewrite
 
-ADD apache2_foreground.sh /etc/apache2/foreground.sh
+EXPOSE 80
 
 CMD ["/etc/apache2/foreground.sh"]
\ No newline at end of file
diff --git a/README b/README
new file mode 100644 (file)
index 0000000..733d522
--- /dev/null
+++ b/README
@@ -0,0 +1,30 @@
+Sample Arvados web service.
+
+usage: arv-web-example.py [-h] --project PROJECT [--port PORT] --image IMAGE
+
+optional arguments:
+  -h, --help         show this help message and exit
+  --project PROJECT  Project to watch
+  --port PORT        Local bind port
+  --image IMAGE      Docker image to run
+
+
+This queries an Arvados project and FUSE mounts the most recently modified
+collection into a temporary directory.  It then runs the supplied Docker image
+with the collection bind mounted to /mnt inside the container.
+
+When a new collection is added to the project, or an existing project is
+updated, it will detect the change, it will stop the running Docker container,
+unmount the old collection, mount the new most recently modified collection,
+and restart the Docker container with the new mount.
+
+The supplied Dockerfile builds a Docker image that runs Apache with /mnt as the
+DocumentRoot.  This allows you to browse the mounted collection with Apache's
+default index page.
+
+
+Suggestions for extension:
+
+Configure the container to use mod_passenger (for an example,
+arvados/docker/passenger/Dockerfile) and include both your web app and your
+data in your collection.
\ No newline at end of file
index bb5e58c47648332c1a95a15db36f8e28795f0d51..c28d0aa516df3b234d3157451e8739d46dc936d5 100644 (file)
@@ -5,17 +5,20 @@
 
   # Index file and Document Root (where the public files are located)
   DirectoryIndex index.html
-  DocumentRoot /mnt
+  DocumentRoot /mnt/public
+  RackBaseURI /
 
   LogLevel warn
   ErrorLog  ${APACHE_LOG_DIR}/error.log
   CustomLog ${APACHE_LOG_DIR}/access.log combined
 
-  <Directory /mnt>
-    Options Indexes FollowSymLinks MultiViews IncludesNoExec
+  <Directory /mnt/public>
+    Options Indexes IncludesNoExec ExecCGI
+    AddHandler cgi-script .cgi
+    Options -MultiViews
     AllowOverride None
     Order allow,deny
-    allow from all
+    Allow from all
   </Directory>
 
 </VirtualHost>
index 044f80228fc0499f6932afc1de4d01076f4ecd68..0329fa3acef05269a1c9637ae3b9870a43e3fbbf 100644 (file)
@@ -94,22 +94,28 @@ while loop:
         while running:
             try:
                 eq = evqueue.get(True, 1)
-                logging.info("%s %s, restarting web service" % (eq[1], eq[2]))
-                if eq[1] == 'add' or eq[1] == 'update':
-                    collection = eq[2]
-                    running = False
-                if eq[1] == 'remove':
-                    collection = api.collections().list(filters=[["owner_uuid", "=", project]],
+                logging.info("%s %s" % (eq[1], eq[2]))
+                newcollection = collection
+                if eq[1] in ('add', 'update', 'create'):
+                    newcollection = eq[2]
+                elif eq[1] == 'remove':
+                    newcollection = api.collections().list(filters=[["owner_uuid", "=", project]],
                                                         limit=1,
                                                         order='modified_at desc').execute()['items'][0]['uuid']
+                if newcollection != collection:
+                    logging.info("restarting web service")
+                    collection = newcollection
                     running = False
-
             except Queue.Empty:
                 pass
-    except KeyboardInterrupt:
+    except (KeyboardInterrupt):
         logging.info("Got keyboard interrupt")
         ws.close()
         loop = False
+    except Exception as e:
+        logging.exception(str(e))
+        ws.close()
+        loop = False
     finally:
         if cid:
             logging.info("Stopping docker container")
diff --git a/sample-cgi-app/public/index.cgi b/sample-cgi-app/public/index.cgi
new file mode 100644 (file)
index 0000000..57bc2a9
--- /dev/null
@@ -0,0 +1,4 @@
+#!/usr/bin/perl
+
+print "Content-type: text/html\n\n";
+print "Hello world from perl!";
diff --git a/sample-cgi-app/tmp/.keepkeep b/sample-cgi-app/tmp/.keepkeep
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/sample-rack-app/config.ru b/sample-rack-app/config.ru
new file mode 100644 (file)
index 0000000..84bb0da
--- /dev/null
@@ -0,0 +1,4 @@
+app = proc do |env|
+    [200, { "Content-Type" => "text/html" }, ["hello <b>world</b> from ruby"]]
+end
+run app
diff --git a/sample-rack-app/public/.keepkeep b/sample-rack-app/public/.keepkeep
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/sample-rack-app/tmp/.keepkeep b/sample-rack-app/tmp/.keepkeep
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/sample-static-page/public/index.html b/sample-static-page/public/index.html
new file mode 100644 (file)
index 0000000..a2e485c
--- /dev/null
@@ -0,0 +1,6 @@
+<html>
+  <head><title>arv-web sample</title></head>
+  <body>
+    <p>Hello world static page</p>
+  </body>
+</html>
diff --git a/sample-static-page/tmp/.keepkeep b/sample-static-page/tmp/.keepkeep
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/sample-wsgi-app/passenger_wsgi.py b/sample-wsgi-app/passenger_wsgi.py
new file mode 100644 (file)
index 0000000..ea918f0
--- /dev/null
@@ -0,0 +1,3 @@
+def application(environ, start_response):
+    start_response('200 OK', [('Content-Type', 'text/plain')])
+    return [b"hello world from python!\n"]
diff --git a/sample-wsgi-app/public/.keepkeep b/sample-wsgi-app/public/.keepkeep
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/sample-wsgi-app/tmp/.keepkeep b/sample-wsgi-app/tmp/.keepkeep
new file mode 100644 (file)
index 0000000..e69de29