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
This commit is contained in:
		
							parent
							
								
									45512e815a
								
							
						
					
					
						commit
						af5fec11ff
					
				
					 7 changed files with 18 additions and 39 deletions
				
			
		|  | @ -1,2 +1,3 @@ | ||||||
| .git | .git | ||||||
| ve | symposion-fixtures | ||||||
|  | 
 | ||||||
|  |  | ||||||
|  | @ -64,10 +64,11 @@ Making migrations | ||||||
| 
 | 
 | ||||||
| If you make changes to the data model, you'll need to run "manage.py | 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 | 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 | mac, or a system without python3, this can be difficult. | ||||||
| case, the ``makemigrations.sh`` script takes advantaged of a docker | 
 | ||||||
| container that's slightly modified, and runs the makemigration action | In such a case, you can use the above script to make and run a dev | ||||||
| on the files in your working directory. | container; then:: | ||||||
|  |     docker exec -it symposion ./manage.py makemigrations | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| Running a dev instance in a VirtualEnv | Running a dev instance in a VirtualEnv | ||||||
|  |  | ||||||
|  | @ -1,5 +1,4 @@ | ||||||
| FROM python:3.6 | FROM python:3.6 as symposion_base | ||||||
| 
 |  | ||||||
| 
 | 
 | ||||||
| RUN set -ex \ | RUN set -ex \ | ||||||
|     && apt-get update |     && apt-get update | ||||||
|  | @ -41,4 +40,10 @@ RUN set -x \ | ||||||
|     && DJANGO_SECRET_KEY=1234 STRIPE_PUBLIC_KEY=1234 STRIPE_SECRET_KEY=1234 \ |     && DJANGO_SECRET_KEY=1234 STRIPE_PUBLIC_KEY=1234 STRIPE_SECRET_KEY=1234 \ | ||||||
|        DATABASE_URL="sqlite:////dev/null" \ |        DATABASE_URL="sqlite:////dev/null" \ | ||||||
|        python manage.py collectstatic --noinput -l -v 0 |        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"] | CMD ["/usr/local/bin/uwsgi", "--http-socket", "0.0.0.0:8000", "--wsgi-file", "pinaxcon/wsgi.py"] | ||||||
|  |  | ||||||
|  | @ -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"] |  | ||||||
| 
 |  | ||||||
|  | @ -5,3 +5,4 @@ GCS_BUCKET=5CEA51A5-A613-4AEF-A9FB-D0A57D77C13B | ||||||
| GOOGLE_APPLICATION_CREDENTIALS=/dev/null | GOOGLE_APPLICATION_CREDENTIALS=/dev/null | ||||||
| DATABASE_URL=sqlite:////tmp/symposion.sqlite | DATABASE_URL=sqlite:////tmp/symposion.sqlite | ||||||
| SYMPOSION_DEV_MODE=LAPTOP | SYMPOSION_DEV_MODE=LAPTOP | ||||||
|  | SYMPOSION_APP_DEBUG=1 | ||||||
|  | @ -2,10 +2,10 @@ | ||||||
| 
 | 
 | ||||||
| CONTAINER_NAME=${1:-symposion_app} | 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 stop symposion | ||||||
| docker container rm 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 container start symposion | ||||||
| docker exec symposion ./manage.py migrate | docker exec symposion ./manage.py migrate | ||||||
| docker exec symposion ./manage.py loaddata ./fixtures/*.json | docker exec symposion ./manage.py loaddata ./fixtures/*.json | ||||||
|  |  | ||||||
|  | @ -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 $* |  | ||||||
| 
 |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 James Polley
						James Polley