multi-staging example 2: Python 3.7 + LDAP + MariaD

 1# dockerfile_dev
 2# Development environment (LDAP, MariaDB, no apache server)
 3#
 4# 2 stages:
 5#
 6# - first stage
 7#       building the python virtualenv with ldap support
 8#       (we need gcc and libldap2-dev libsasl2-dev libssl-dev)
 9# - second stage
10#       - copying the python virtualenv environment under /opt/update_id3/docker
11#       - install the ldap libraries
12#       - copying the django project under /opt/update_id3/update_id3
13#
14##### Start stage 1 : building the Python virtual environment ##########
15# https://hub.docker.com/_/python
16FROM python:3.7.3-slim-stretch as builder
17
18# gcc because we need regex and pyldap
19# libldap2-dev because we need pyldap
20RUN apt-get update \
21    && apt-get install -y gcc libldap2-dev libsasl2-dev libssl-dev default-libmysqlclient-dev
22
23# we need the bash shell for the 'source' binary
24SHELL ["/bin/bash", "-c"]
25WORKDIR /opt/update_id3/docker/
26COPY ./update_id3/requirements_dev.txt .
27RUN python -m venv .venv && \
28    source .venv/bin/activate && \
29    pip install -U pip wheel && \
30    pip install -r requirements_dev.txt
31
32#### Start stage 2 #########################################
33#
34#  volumes:
35#     - ./docker-django/update_id3/:/opt/update_id3/update_id3 # permet d'accéder au code du host
36FROM python:3.7.3-slim-stretch as deployer
37
38# ajout d'informations à l'image pour pouvoir l'identifier plus facilement
39LABEL maintainer "patrick.vergain@id3.eu"
40LABEL description "Application update.id3.eu 3.0.0 (NOT RELEASED)"
41
42# Set environment variables
43ENV PYTHONDONTWRITEBYTECODE 1
44ENV PYTHONUNBUFFERED 1
45
46WORKDIR /opt/update_id3/docker/
47COPY --from=builder /opt/update_id3/docker/.venv ./.venv
48
49# we only need  the ldap and mariadb libraries
50# https://packages.debian.org/fr/jessie/libldap-2.4-2
51RUN apt-get update \
52    && apt-get install -y tree libldap-2.4-2 default-libmysqlclient-dev \
53    && apt-get clean
54
55
56# copying the django project
57COPY ./update_id3 /opt/update_id3/update_id3
58WORKDIR /opt/update_id3/update_id3
59
60    RUN mkdir -p /opt/update_id3/logs \
61        && touch /opt/update_id3/logs/update_id3.log