Repository: cookiecutter/cookiecutter-django
Pull request:  Move to the python:alpine docker image 
Fixes #498 

- Switch the base images for local and production to alpine
- Install extra dependencies for psycopg2, Pillow and cffi
- Change shebang for shell scripts to use sh instead of bash, as bash isn't installed
- Remove `function` keyword from shell scripts, it is unsupported in sh
- Migrate `django` group and user creation to the Alpine syntax

I've started from a generated project, which I've migrated by running `docker-compose -f local.yml build` and `docker-compose -f production.yml build`. The tests are passing with the local config and I can start with the production config.

Problem statement:
Move to the python:alpine docker image
The default image we are currently using is super fat (around 700MB) as it is based on a full fletched debian. There's a lot of movement to images based on alpine going on and the official image now supports that too.

Alpine uses musl libc instead of glibc, so that might be a problem for packages that have tight dependencies with libc.

Hints from issue discussion:
I'll take care of this

Per @jayfk: https://github.com/frol/docker-alpine-python3/issues/1 may prove helpful. Probably will need a Dockerfile that specifies dependency on glibc and the dependencies listed in the link (you may very well know this, but just in case)

@mjsisley: There is currently an official alpine image. Either way, we should evaluate if it is worth to create our own 'custom' image with binary wheels included to significantly simplify our use case and in particular gh #594.

Any news on this?
Any news on the issue?

Commit message: Move to the python:alpine docker image

- Remove `function` keyword, unsupported in shell

Patch to review:
diff --git a/{{cookiecutter.project_slug}}/compose/local/django/Dockerfile b/{{cookiecutter.project_slug}}/compose/local/django/Dockerfile
index e62b524a42..e7997187b8 100644
--- a/{{cookiecutter.project_slug}}/compose/local/django/Dockerfile
+++ b/{{cookiecutter.project_slug}}/compose/local/django/Dockerfile
@@ -1,7 +1,16 @@
-FROM python:3.5
+FROM python:3.5-alpine
 
 ENV PYTHONUNBUFFERED 1
 
+RUN apk update \
+  # psycopg2 dependencies
+  && apk add --virtual build-deps gcc python3-dev musl-dev \
+  && apk add postgresql-dev \
+  # Pillow dependencies
+  && apk add jpeg-dev zlib-dev freetype-dev lcms2-dev openjpeg-dev tiff-dev tk-dev tcl-dev \
+  # CFFI dependencies
+  && apk add libffi-dev openssl-dev py-cffi
+
 # Requirements have to be pulled and installed here, otherwise caching won't work
 COPY ./requirements /requirements
 RUN pip install -r /requirements/local.txt
diff --git a/{{cookiecutter.project_slug}}/compose/local/django/celery/beat/start.sh b/{{cookiecutter.project_slug}}/compose/local/django/celery/beat/start.sh
index c26318b442..0ca8bb507a 100644
--- a/{{cookiecutter.project_slug}}/compose/local/django/celery/beat/start.sh
+++ b/{{cookiecutter.project_slug}}/compose/local/django/celery/beat/start.sh
@@ -1,4 +1,4 @@
-#!/usr/bin/env bash
+#!/bin/sh
 
 set -o errexit
 set -o pipefail
diff --git a/{{cookiecutter.project_slug}}/compose/local/django/celery/worker/start.sh b/{{cookiecutter.project_slug}}/compose/local/django/celery/worker/start.sh
index 8b50c8cfd0..4335340de2 100644
--- a/{{cookiecutter.project_slug}}/compose/local/django/celery/worker/start.sh
+++ b/{{cookiecutter.project_slug}}/compose/local/django/celery/worker/start.sh
@@ -1,4 +1,4 @@
-#!/usr/bin/env bash
+#!/bin/sh
 
 set -o errexit
 set -o pipefail
diff --git a/{{cookiecutter.project_slug}}/compose/local/django/start.sh b/{{cookiecutter.project_slug}}/compose/local/django/start.sh
index cf4a41667f..50227e19eb 100644
--- a/{{cookiecutter.project_slug}}/compose/local/django/start.sh
+++ b/{{cookiecutter.project_slug}}/compose/local/django/start.sh
@@ -1,4 +1,4 @@
-#!/usr/bin/env bash
+#!/bin/sh
 
 set -o errexit
 set -o pipefail
diff --git a/{{cookiecutter.project_slug}}/compose/production/django/Dockerfile b/{{cookiecutter.project_slug}}/compose/production/django/Dockerfile
index fcbe518446..4451989601 100644
--- a/{{cookiecutter.project_slug}}/compose/production/django/Dockerfile
+++ b/{{cookiecutter.project_slug}}/compose/production/django/Dockerfile
@@ -1,9 +1,18 @@
-FROM python:3.5
+FROM python:3.5-alpine
 
 ENV PYTHONUNBUFFERED 1
 
-RUN groupadd -r django \
-    && useradd -r -g django django
+RUN apk update \
+  # psycopg2 dependencies
+  && apk add --virtual build-deps gcc python3-dev musl-dev \
+  && apk add postgresql-dev \
+  # Pillow dependencies
+  && apk add jpeg-dev zlib-dev freetype-dev lcms2-dev openjpeg-dev tiff-dev tk-dev tcl-dev \
+  # CFFI dependencies
+  && apk add libffi-dev openssl-dev py-cffi
+
+RUN addgroup -S django \
+    && adduser -S -G django django
 
 # Requirements have to be pulled and installed here, otherwise caching won't work
 COPY ./requirements /requirements
diff --git a/{{cookiecutter.project_slug}}/compose/production/django/celery/beat/start.sh b/{{cookiecutter.project_slug}}/compose/production/django/celery/beat/start.sh
index 845db0a3d9..def83076c3 100644
--- a/{{cookiecutter.project_slug}}/compose/production/django/celery/beat/start.sh
+++ b/{{cookiecutter.project_slug}}/compose/production/django/celery/beat/start.sh
@@ -1,4 +1,4 @@
-#!/usr/bin/env bash
+#!/bin/sh
 
 set -o errexit
 set -o pipefail
diff --git a/{{cookiecutter.project_slug}}/compose/production/django/celery/worker/start.sh b/{{cookiecutter.project_slug}}/compose/production/django/celery/worker/start.sh
index 4529aad925..10f0d20c5a 100644
--- a/{{cookiecutter.project_slug}}/compose/production/django/celery/worker/start.sh
+++ b/{{cookiecutter.project_slug}}/compose/production/django/celery/worker/start.sh
@@ -1,4 +1,4 @@
-#!/usr/bin/env bash
+#!/bin/sh
 
 set -o errexit
 set -o pipefail
diff --git a/{{cookiecutter.project_slug}}/compose/production/django/entrypoint.sh b/{{cookiecutter.project_slug}}/compose/production/django/entrypoint.sh
index 3b83c7bb66..a40a2b7e43 100644
--- a/{{cookiecutter.project_slug}}/compose/production/django/entrypoint.sh
+++ b/{{cookiecutter.project_slug}}/compose/production/django/entrypoint.sh
@@ -1,4 +1,4 @@
-#!/usr/bin/env bash
+#!/bin/sh
 
 set -o errexit
 set -o pipefail
@@ -25,7 +25,7 @@ export DATABASE_URL=postgres://$POSTGRES_USER:$POSTGRES_PASSWORD@postgres:5432/$
 export CELERY_BROKER_URL=$REDIS_URL/0
 {% endif %}
 
-function postgres_ready(){
+postgres_ready() {
 python << END
 import sys
 import psycopg2
diff --git a/{{cookiecutter.project_slug}}/compose/production/django/gunicorn.sh b/{{cookiecutter.project_slug}}/compose/production/django/gunicorn.sh
index 25da06496d..8846cafb28 100644
--- a/{{cookiecutter.project_slug}}/compose/production/django/gunicorn.sh
+++ b/{{cookiecutter.project_slug}}/compose/production/django/gunicorn.sh
@@ -1,4 +1,4 @@
-#!/usr/bin/env bash
+#!/bin/sh
 
 set -o errexit
 set -o pipefail


Code review comments:
diff_hunk: @@ -1,9 +1,18 @@
-FROM python:3.5
+FROM python:3.5-alpine
path: {{cookiecutter.project_slug}}/compose/production/django/Dockerfile
text: @user1:
Make it `FROM python:3.6-alpine`.

diff_hunk: @@ -1,7 +1,16 @@
-FROM python:3.5
+FROM python:3.5-alpine
path: {{cookiecutter.project_slug}}/compose/local/django/Dockerfile
text: @user1:
Make it `FROM python:3.6-alpine`.