From 8b9285259ab8bab931bd7166967baeb27b50f476 Mon Sep 17 00:00:00 2001 From: Alexandre Iooss Date: Sun, 7 Oct 2018 17:50:06 +0200 Subject: [PATCH] Add basic Docker support Dockerfile should not change in the future. Docker-compose configuration need some work on LDAP init before fully working. --- Dockerfile | 28 ++++++++++++++++++++++++++++ docker-compose.yml | 28 ++++++++++++++++++++++++++++ entrypoint.sh | 10 ++++++++++ 3 files changed, 66 insertions(+) create mode 100644 Dockerfile create mode 100644 docker-compose.yml create mode 100755 entrypoint.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..3670e1ef --- /dev/null +++ b/Dockerfile @@ -0,0 +1,28 @@ +FROM python:3.6-alpine + +# Django code will be in /usr/src/app/ +# During development you should mount the git code there, +# During production you should copy the code in the image. +WORKDIR /usr/src/app + +# Set environment variables +ENV PYTHONDONTWRITEBYTECODE 1 +ENV PYTHONUNBUFFERED 1 + +# Install dependencies via pipenv +ADD Pipfile* ./ +RUN apk update && apk add gcc musl-dev postgresql-dev +RUN pip install --upgrade pip==18.0 +RUN pip install pipenv==2018.7.1 +RUN pipenv install --deploy --system --dev + +# Pass only port 8080 +EXPOSE 8080 + +# Set entrypoint : make migrations and collect statics +COPY entrypoint.sh ./ +ENTRYPOINT [ "./entrypoint.sh" ] + +# Start Django app +CMD ["python", "manage.py", "runserver", "0.0.0.0:8080"] + diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..39ac8e7f --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,28 @@ +# Use for development purposes only + +version: '3' + +services: + db: + image: postgres:alpine + environment: + - POSTGRES_DB=re2o + - POSTGRES_USER=re2o + - POSTGRES_PASSWORD=changeme + - POSTGRES_INITDB_ARGS=--encoding=UTF-8 --lc-collate=fr_FR.UTF-8 --lc-ctype=fr_FR.UTF-8 + volumes: + - db_data:/var/lib/postgresql/data + restart: always + web: + build: . + ports: + - "8000:8000" + depends_on: + - db + volumes: + - .:/usr/src/app + restart: always + +volumes: + db_data: + diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 00000000..d68d46d7 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,10 @@ +#!/bin/sh + +# Migrate database +python manage.py migrate --noinput + +# Collect statics +python manage.py collectstatic --noinput + +exec "$@" +