From af5fec11ff3351cb2820d662ce13af2208800212 Mon Sep 17 00:00:00 2001 From: James Polley Date: Sun, 1 Oct 2017 18:35:02 +1100 Subject: [PATCH] Utilise multi-stage docker build for consistent dev/prod base * developers can use --target symposion_dev to get a responsive site that reads from their homedir and reacts to changed files instantly * without a specified target the default is to build the prod image, which is identical except for running uwsgi instead of the django built-in server * Enable debug when running in a developer's test environment * Remove the makemigrations script and dockerfile --- .dockerignore | 3 ++- README.rst | 9 +++++---- docker/Dockerfile | 9 +++++++-- docker/Dockerfile.makemigrations | 25 ------------------------- docker/laptop-mode-env | 3 ++- make_dev_container.sh | 4 ++-- makemigrations.sh | 4 ---- 7 files changed, 18 insertions(+), 39 deletions(-) delete mode 100644 docker/Dockerfile.makemigrations delete mode 100755 makemigrations.sh diff --git a/.dockerignore b/.dockerignore index af988aaa..328a7a4e 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,2 +1,3 @@ .git -ve +symposion-fixtures + diff --git a/README.rst b/README.rst index 8f3fc64c..7e6cbcad 100644 --- a/README.rst +++ b/README.rst @@ -64,10 +64,11 @@ Making migrations If you make changes to the data model, you'll need to run "manage.py makemigrations" to create a matching migration file. If you're on a -mac, or a system without python3, this can be difficult. In such a -case, the ``makemigrations.sh`` script takes advantaged of a docker -container that's slightly modified, and runs the makemigration action -on the files in your working directory. +mac, or a system without python3, this can be difficult. + +In such a case, you can use the above script to make and run a dev +container; then:: + docker exec -it symposion ./manage.py makemigrations Running a dev instance in a VirtualEnv diff --git a/docker/Dockerfile b/docker/Dockerfile index baf81ccd..872374d4 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,5 +1,4 @@ -FROM python:3.6 - +FROM python:3.6 as symposion_base RUN set -ex \ && apt-get update @@ -41,4 +40,10 @@ RUN set -x \ && DJANGO_SECRET_KEY=1234 STRIPE_PUBLIC_KEY=1234 STRIPE_SECRET_KEY=1234 \ DATABASE_URL="sqlite:////dev/null" \ python manage.py collectstatic --noinput -l -v 0 + +FROM symposion_base as symposion_dev +VOLUME /app/symposion_app +CMD ["./manage.py", "runserver", "-v3", "0.0.0.0:8000"] + +FROM symposion_base as symposion_prod CMD ["/usr/local/bin/uwsgi", "--http-socket", "0.0.0.0:8000", "--wsgi-file", "pinaxcon/wsgi.py"] diff --git a/docker/Dockerfile.makemigrations b/docker/Dockerfile.makemigrations deleted file mode 100644 index d64f416d..00000000 --- a/docker/Dockerfile.makemigrations +++ /dev/null @@ -1,25 +0,0 @@ -FROM python:3.6 -VOLUME /source -COPY constraints.txt requirements.txt /setup/ -RUN set -ex \ - && buildDeps=' \ - libmysqlclient-dev \ - libffi-dev \ - libfreetype6-dev \ - libjpeg-dev \ - libwebp-dev \ - libpng-dev \ - liblcms2-dev \ - zlib1g-dev \ - libmemcached-dev \ - libsasl2-dev \ - ' \ - && apt-get update \ - && apt-get install -y git xmlsec1 libmysqlclient18 \ - && apt-get install -y $buildDeps --no-install-recommends -RUN pip install -c /setup/constraints.txt -r /setup/requirements.txt -COPY . /source -WORKDIR /source -RUN pip install -c /setup/constraints.txt -r /source/vendored_requirements.txt -ENTRYPOINT ["python","/source/manage.py", "makemigrations"] - diff --git a/docker/laptop-mode-env b/docker/laptop-mode-env index 6b174fa8..8d391eff 100644 --- a/docker/laptop-mode-env +++ b/docker/laptop-mode-env @@ -4,4 +4,5 @@ STRIPE_SECRET_KEY=5CEA51A5-A613-4AEF-A9FB-D0A57D77C13B GCS_BUCKET=5CEA51A5-A613-4AEF-A9FB-D0A57D77C13B GOOGLE_APPLICATION_CREDENTIALS=/dev/null DATABASE_URL=sqlite:////tmp/symposion.sqlite -SYMPOSION_DEV_MODE=LAPTOP \ No newline at end of file +SYMPOSION_DEV_MODE=LAPTOP +SYMPOSION_APP_DEBUG=1 \ No newline at end of file diff --git a/make_dev_container.sh b/make_dev_container.sh index e29ffdc2..74352861 100755 --- a/make_dev_container.sh +++ b/make_dev_container.sh @@ -2,10 +2,10 @@ CONTAINER_NAME=${1:-symposion_app} -docker image build -f docker/Dockerfile -t ${CONTAINER_NAME} . +docker image build -f docker/Dockerfile -t ${CONTAINER_NAME} --target symposion_dev . docker container stop symposion docker container rm symposion -docker container create --env-file docker/laptop-mode-env -p 28000:8000 --name symposion ${CONTAINER_NAME} +docker container create --env-file docker/laptop-mode-env -p 28000:8000 -v $(pwd):/app/symposion_app --name symposion ${CONTAINER_NAME} docker container start symposion docker exec symposion ./manage.py migrate docker exec symposion ./manage.py loaddata ./fixtures/*.json diff --git a/makemigrations.sh b/makemigrations.sh deleted file mode 100755 index c150e271..00000000 --- a/makemigrations.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash -x -docker image build -f docker/Dockerfile.makemigrations -t makemigrations . -docker run -it --env-file=docker/laptop-mode-env -v $(pwd):/source makemigrations $* -