Changeset - af5fec11ff33
[Not reviewed]
2 5 0
James Polley - 7 years ago 2017-10-04 09:43:01
jp@jamezpolley.com
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
7 files changed with 18 insertions and 39 deletions:
0 comments (0 inline, 0 general)
.dockerignore
Show inline comments
 
.git
 
ve
 
symposion-fixtures
 

	
README.rst
Show inline comments
...
 
@@ -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
docker/Dockerfile
Show inline comments
 
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"]
docker/Dockerfile.makemigrations
Show inline comments
 
deleted file
docker/laptop-mode-env
Show inline comments
...
 
@@ -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
make_dev_container.sh
Show inline comments
...
 
@@ -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
makemigrations.sh
Show inline comments
 
deleted file
0 comments (0 inline, 0 general)