Skip to content

Commit

Permalink
refs #127. Adds runserver dev container.
Browse files Browse the repository at this point in the history
  • Loading branch information
Justin Littman committed Jan 14, 2016
1 parent fdf6e8e commit f4bab08
Show file tree
Hide file tree
Showing 6 changed files with 193 additions and 0 deletions.
36 changes: 36 additions & 0 deletions docker/app-dev-runserver/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
FROM ubuntu:14.04
MAINTAINER Rajat Vij <rajatvij@email.gwu.edu>

RUN apt-get update && apt-get install -y \
build-essential \
gettext \
python-dev \
zlib1g-dev \
libpq-dev \
python-pip \
apache2 \
libapache2-mod-wsgi \
wget \
zip
# Not sure why the git install needs its own line,
# but it seems to be ignored if added into the list above
RUN apt-get install -y git
#Upgrade pip
RUN pip install --upgrade pip
#This pre-fetches the most recent requirements.txt.
ADD https://raw.githubusercontent.com/gwu-libraries/sfm-ui/master/requirements/requirements.txt /opt/sfm-setup/
RUN pip install -r /opt/sfm-setup/requirements.txt
#Install appdeps to allow checking for application dependencies
RUN pip install appdeps
#This is used to automatically create the admin user.
RUN pip install django-finalware==0.1.0
#This will be copied over into the app by invoke.sh.
ADD wsgi.py /tmp/
#Adds fixtures.
ADD fixtures.json /opt/sfm-setup/
ADD invoke.sh /opt/
RUN chmod +x /opt/invoke.sh
WORKDIR /opt/sfm-ui
ENV DJANGO_SETTINGS_MODULE=sfm.settings.docker_settings
CMD ["/opt/invoke.sh"]
EXPOSE 80
88 changes: 88 additions & 0 deletions docker/app-dev-runserver/fixtures.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
[
{
"fields": {
"name": "testgroup",
"permissions": []
},
"model": "auth.group",
"pk": 1
},
{
"fields": {
"name": "testgroup2",
"permissions": []
},
"model": "auth.group",
"pk": 2
},
{
"fields": {
"is_visible": true,
"stats": "",
"name": "testcollection",
"date_updated": "2015-12-01T19:10:46Z",
"is_active": true,
"date_added": "2015-12-01T19:10:28Z",
"group": 1,
"description": "This is a test collection."
},
"model": "ui.collection",
"pk": 1
},
{
"fields": {
"is_visible": true,
"stats": "",
"name": "Test Collection 2",
"date_updated": "2015-12-30T13:18:40.392Z",
"is_active": true,
"date_added": "2015-12-29T20:24:47Z",
"group": 2,
"description": "This collection is for testing purposes."
},
"model": "ui.collection",
"pk": 2
},
{
"fields": {
"username": "testuser",
"first_name": "",
"last_name": "",
"is_active": true,
"local_id": "",
"is_superuser": false,
"is_staff": false,
"last_login": null,
"groups": [
1
],
"user_permissions": [],
"password": "pbkdf2_sha256$20000$7gZDb0TxSksC$HXFliz5Vqsd+S3a6+X+iwQuZ//uvfEpYb+0+0sMD7Vk=",
"email": "",
"date_joined": "2015-12-01T19:09:21Z"
},
"model": "ui.user",
"pk": 2
},
{
"fields": {
"username": "testuser2",
"first_name": "",
"last_name": "",
"is_active": true,
"local_id": "",
"is_superuser": false,
"is_staff": false,
"last_login": null,
"groups": [
2
],
"user_permissions": [],
"password": "pbkdf2_sha256$20000$mvf0xFj6z38i$8MTmopihB8R06iUrqZ22D0MMadsJCIR3avqdAwnpdZ0=",
"email": "",
"date_joined": "2015-12-29T15:01:22Z"
},
"model": "ui.user",
"pk": 3
}
]
31 changes: 31 additions & 0 deletions docker/app-dev-runserver/invoke.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash
echo "Waiting for db"
appdeps.py --wait-secs 30 --port-wait db:5432 --file /opt/sfm-ui --port-wait mq:5672
if [ "$?" = "1" ]; then
echo "Problem with application dependencies."
exit 1
fi

echo "Updating requirements"
pip install -r /opt/sfm-ui/requirements/requirements.txt --upgrade

echo "Copying config"
cp /tmp/wsgi.py /opt/sfm-ui/sfm/sfm/

echo "Syncing db"
/opt/sfm-ui/sfm/manage.py syncdb --noinput

echo "Migrating db"
/opt/sfm-ui/sfm/manage.py migrate --noinput

echo "Collecting static files"
/opt/sfm-ui/sfm/manage.py collectstatic --noinput

echo "Loading fixtures"
/opt/sfm-ui/sfm/manage.py loaddata /opt/sfm-setup/fixtures.json

echo "Starting message consumer"
/opt/sfm-ui/sfm/manage.py startconsumer &

echo "Running server"
/opt/sfm-ui/sfm/manage.py runserver 0.0.0.0:80
30 changes: 30 additions & 0 deletions docker/app-dev-runserver/wsgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"""
WSGI config for sfm project.
This module contains the WSGI application used by Django's development server
and any production WSGI deployments. It should expose a module-level variable
named ``application``. Django's ``runserver`` and ``runfcgi`` commands discover
this application via the ``WSGI_APPLICATION`` setting.
Usually you will have the standard Django WSGI application here, but it also
might make sense to replace the whole Django WSGI application with a custom one
that later delegates to the Django one. For example, you could introduce WSGI
middleware here, or combine a Django application with an application of another
framework.
"""
# if using a virtualenv, uncomment and set the next three lines appropriately
#import site
#ENV = '/PATH/TO/YOUR/VIRTUALENV'
#site.addsitedir(ENV + '/lib/python2.7/site-packages')

import os

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "sfm.settings.docker_settings")

# This application object is used by any WSGI server configured to use this
# file. This includes Django's development server, if the WSGI_APPLICATION
# setting points here.
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

# Apply WSGI middleware here.
# from helloworld.wsgi import HelloWorldApplication
# application = HelloWorldApplication(application)
1 change: 1 addition & 0 deletions docker/example.dev.docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ sfmdevdb:
- POSTGRES_PASSWORD=gherD42#dl5
sfmdevapp:
image: gwul/sfm-ui:dev
# image: gwul/sfm-ui:dev-runserver
ports:
- "8080:80"
links:
Expand Down
7 changes: 7 additions & 0 deletions docs/development.rst
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,13 @@ The development and master docker images for SFM UI contain some initial data. T
with password "password"). For the latest initial data, see `fixtures.json`. For more information on fixtures,
see the `Django docs <https://docs.djangoproject.com/en/1.8/howto/initial-data/>`_.

Runserver
^^^^^^^^^
There are two flavors of the the development docker image for SFM UI. `gwul/sfm-ui:dev` runs SFM UI with
Apache, just as it will in production. `gwul/sfm-ui:dev-runserver` runs SFM UI with `runserver <https://docs.djangoproject.com/en/1.8/ref/django-admin/#runserver-port-or-address-port>`_,
which dynamically reloads changed Python code. To switch between them, change the `image` field in your
`docker-compose.yml`.

.. _install-helpful-docker:

-------------
Expand Down

0 comments on commit f4bab08

Please sign in to comment.