From 8a492504182d820601afbbce3034d533cbb6bd41 Mon Sep 17 00:00:00 2001 From: crccheck Date: Thu, 25 Feb 2016 17:10:12 -0600 Subject: [PATCH 1/6] fix how the docker images didn't have a database --- Dockerfile | 2 ++ Makefile | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 53d4cd5..d2b6bed 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,4 +9,6 @@ EXPOSE 8000 ENV PYTHONPATH /usr/src/app +RUN make resetdb + CMD python example_project/manage.py runserver 0.0.0.0:$PORT diff --git a/Makefile b/Makefile index 70aac5c..64a5eca 100644 --- a/Makefile +++ b/Makefile @@ -36,8 +36,8 @@ coverage: ## Run and then display coverage report resetdb: ## Delete and then recreate the dev sqlite database python $(MANAGE) reset_db --router=default --noinput - python $(MANAGE) syncdb --noinput - python $(MANAGE) migrate --noinput + -python $(MANAGE) syncdb --noinput + -python $(MANAGE) migrate --noinput python $(MANAGE) loaddata sample_data .PHONY: build @@ -51,7 +51,7 @@ build/%: run: run/1.9 run/%: - docker run --rm -p 8000:8000 --sig-proxy=false $(IMAGE):$* + docker run --rm -p 8000:8000 -it $(IMAGE):$* test/%: docker run --rm -p 8000:8000 --sig-proxy=false $(IMAGE):$* make test From dc354981741c0e9e932fe46bdcf9bd68d8ca11db Mon Sep 17 00:00:00 2001 From: crccheck Date: Thu, 25 Feb 2016 17:24:27 -0600 Subject: [PATCH 2/6] create a default admin/admin user --- Dockerfile | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Dockerfile b/Dockerfile index d2b6bed..b0d744e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,5 +10,9 @@ EXPOSE 8000 ENV PYTHONPATH /usr/src/app RUN make resetdb +RUN echo "from django.contrib.auth import get_user_model; \ + User = get_user_model(); \ + User.objects.create_superuser('admin', 'admin@example.com', 'admin')" | \ + python example_project/manage.py shell CMD python example_project/manage.py runserver 0.0.0.0:$PORT From 01fa29545c0fde269e82e212c8a821f017e39faf Mon Sep 17 00:00:00 2001 From: crccheck Date: Thu, 25 Feb 2016 17:27:36 -0600 Subject: [PATCH 3/6] ugh --- .../polls/migrations/0001_initial.py | 46 +++++++++++++++++++ example_project/polls/migrations/__init__.py | 0 2 files changed, 46 insertions(+) create mode 100644 example_project/polls/migrations/0001_initial.py create mode 100644 example_project/polls/migrations/__init__.py diff --git a/example_project/polls/migrations/0001_initial.py b/example_project/polls/migrations/0001_initial.py new file mode 100644 index 0000000..178f701 --- /dev/null +++ b/example_project/polls/migrations/0001_initial.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.2 on 2016-02-25 17:25 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion +import django_extensions.db.fields + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Choice', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('choice_text', models.CharField(max_length=200)), + ('votes', models.IntegerField()), + ], + ), + migrations.CreateModel( + name='Comment', + fields=[ + ('uuid', django_extensions.db.fields.UUIDField(blank=True, editable=False, primary_key=True, serialize=False)), + ('comment', models.TextField(blank=True, null=True)), + ], + ), + migrations.CreateModel( + name='Poll', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('question', models.CharField(max_length=200)), + ('pub_date', models.DateTimeField(verbose_name=b'date published')), + ], + ), + migrations.AddField( + model_name='choice', + name='poll', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='polls.Poll'), + ), + ] diff --git a/example_project/polls/migrations/__init__.py b/example_project/polls/migrations/__init__.py new file mode 100644 index 0000000..e69de29 From 0fc71148d1c1289b0d4d7572499cfe686297799a Mon Sep 17 00:00:00 2001 From: crccheck Date: Thu, 25 Feb 2016 17:46:37 -0600 Subject: [PATCH 4/6] doc how to upload images --- Makefile | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 64a5eca..006d3b6 100644 --- a/Makefile +++ b/Makefile @@ -53,8 +53,15 @@ run: run/1.9 run/%: docker run --rm -p 8000:8000 -it $(IMAGE):$* +docker/publish: ## Publish Docker images to the hub + docker push $(IMAGE):1.9 + docker push $(IMAGE):1.8 + docker push $(IMAGE):1.7 + docker push $(IMAGE):1.6 + docker push $(IMAGE):1.5 + test/%: - docker run --rm -p 8000:8000 --sig-proxy=false $(IMAGE):$* make test + docker run --rm -p 8000:8000 -t $(IMAGE):$* make test bash: docker run --rm -it $(IMAGE):1.9 /bin/bash From acaae613237b0e4d9db016c49a32aa56865d4600 Mon Sep 17 00:00:00 2001 From: crccheck Date: Thu, 25 Feb 2016 17:53:04 -0600 Subject: [PATCH 5/6] switch to smaller base image and cacheable layers --- Dockerfile | 18 ++++++++++++------ Makefile | 2 +- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index b0d744e..e12cef6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,13 +1,16 @@ -FROM python:2-onbuild +FROM python:2.7-alpine -ARG DJANGO_VERSION +RUN apk add --no-cache make -RUN pip install django==$DJANGO_VERSION +ADD requirements.txt /app/requirements.txt +RUN pip --disable-pip-version-check install -r /app/requirements.txt -ENV PORT 8000 -EXPOSE 8000 +ARG DJANGO_VERSION +RUN pip --disable-pip-version-check install django==$DJANGO_VERSION -ENV PYTHONPATH /usr/src/app +ADD . /app +WORKDIR /app +ENV PYTHONPATH /app RUN make resetdb RUN echo "from django.contrib.auth import get_user_model; \ @@ -15,4 +18,7 @@ RUN echo "from django.contrib.auth import get_user_model; \ User.objects.create_superuser('admin', 'admin@example.com', 'admin')" | \ python example_project/manage.py shell +ENV PORT 8000 +EXPOSE 8000 + CMD python example_project/manage.py runserver 0.0.0.0:$PORT diff --git a/Makefile b/Makefile index 006d3b6..a45cd4b 100644 --- a/Makefile +++ b/Makefile @@ -42,7 +42,7 @@ resetdb: ## Delete and then recreate the dev sqlite database .PHONY: build build: ## Build a full set of Docker images -build: build/1.9 build/1.8.7 build/1.7.11 build/1.6.11 build/1.5.12 +build: build/1.9.2 build/1.8.9 build/1.7.11 build/1.6.11 build/1.5.12 build/%: docker build --build-arg DJANGO_VERSION=$* \ From a9a6e11561b848112ff24252be5874e61942fbd2 Mon Sep 17 00:00:00 2001 From: crccheck Date: Thu, 25 Feb 2016 18:06:45 -0600 Subject: [PATCH 6/6] doc the Dock --- README.rst | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.rst b/README.rst index 7767e08..ff7ed15 100644 --- a/README.rst +++ b/README.rst @@ -172,6 +172,16 @@ Limitations planned for the future. +Demo Admin & Docker images +-------------------------- + +You can try the demo admin against several versions of Django with these Docker +images: https://hub.docker.com/r/crccheck/django-object-actions/ + +This runs the example Django project in ``./example_project`` based on the +"polls" tutorial. ``admin.py`` demos what you can do with this app. + + Development -----------