diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..a46dab1 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,7 @@ +*.dump +*.sql +*_cache +.git +data/* +site/* +static_root diff --git a/.gitignore b/.gitignore index 7000ab1..00eb3fe 100644 --- a/.gitignore +++ b/.gitignore @@ -17,6 +17,7 @@ GoogleV3_cache # Private files .env +env-* example_project/local_settings.py diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..c55cf5c --- /dev/null +++ b/Dockerfile @@ -0,0 +1,11 @@ +FROM texastribune/gunicorn +MAINTAINER cchang@texastribune.org + +RUN sed -i "s/wsgi:application/example_project.wsgi:application/" /etc/supervisor/conf.d/gunicorn.supervisor.conf + +ADD . /app +ENV PYTHONPATH /app +RUN pip install --quiet -r requirements.txt +# needed to keep manage.py from trying to import too much +ENV DEBUG 0 +RUN python example_project/manage.py collectstatic --noinput diff --git a/Makefile b/Makefile index 339c050..7154592 100644 --- a/Makefile +++ b/Makefile @@ -68,3 +68,24 @@ serve: .PHONY: help test resetdb scrape pushdb site upload serve + +# DOCKER # +build: + docker build -t texastribune/elevators . + +shell: + docker run --rm --name elevators -i -t --link pgplus:postgis \ + --volumes-from elevators-wsgi \ + --env-file env-docker --entrypoint /bin/bash texastribune/elevators + +gunicorn: + docker run --detach --name elevators-wsgi --link pgplus:postgis \ + --env-file env-docker -p 8000:8000 texastribune/elevators + +# download script doesn't need concurrency so only use -c 1 +benchmark: gunicorn + sleep 5 + docker run --rm --link elevators-wsgi:wsgi -t \ + zz ab -n 10 http://wsgi:8000/ + docker logs elevators-wsgi + docker rm -f elevators-wsgi diff --git a/bin/download_site.sh b/bin/download_site.sh index b32efb5..7eab998 100755 --- a/bin/download_site.sh +++ b/bin/download_site.sh @@ -1,28 +1,15 @@ +#!/usr/bin/env bash + # Instructions: # # run from project root directory -set +e -MANAGE="python ./example_project/manage.py" -PORT=8008 - - -DEBUG=0 $MANAGE runserver --nothreading --noreload $PORT & -pid=$! -echo "runserver pid: $pid" - -# make sure to kill the server if terminated early -trap "kill $pid; echo bye $pid" EXIT +# Make sure the docker image is up to date +make build gunicorn +PORT=$(docker port elevators-site 8000 | cut -d : -f 2) # give time for the servers to get up -sleep 1 - -$MANAGE collectstatic --noinput +sleep 3 mkdir -p site cd site && wget -r localhost:$PORT --force-html -e robots=off -nH -nv --max-redirect 0 - -# kill server, run in a subprocess so we can suppress "Terminated" message -(kill $pid 2>&1) > /dev/null - -echo "bye" diff --git a/requirements.txt b/requirements.txt index 47baeb2..dfa4c3e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ -Django==1.6.5 +Django==1.6.6 -dj-database-url>=0.2.1 -project_runpy -psycopg2>=2.4.5 -gunicorn==0.17.2 +dj-database-url==0.3.0 +project_runpy==0.3.1 +psycopg2==2.5.4 +gunicorn==19.1.1