/
Dockerfile-dev
44 lines (39 loc) · 1.99 KB
/
Dockerfile-dev
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# Make the Python version into a variable so that it may be updated easily if / when needed. (ie "3.8")
ARG pythonVersion
# Using a python image itself so the app may be started and stoped more directly.
# Start with a bare Alpine Linux to keep the container image small.
FROM python:${pythonVersion}-alpine
# Designate the `/app` folder inside the container as the working directory.
WORKDIR /app
# Copy the requirements (both prod and dev) files to the `/app` folder inside the container.
# Do this in a separate "COPY" so that the the image will update if either of these files change.
COPY ./requirements.txt ./requirements-dev.txt /app/
# Copy the code base to the work directory. This will ensure it is added to the volume.
COPY ./ /app/
# Execute everything under a single "RUN" to reduce the layer count.
# Upgrade pip
RUN pip install --upgrade pip && \
# `libpq` is needed for Postgres commands.
apk add --no-cache libpq \
# These useful tools are only installed in the development environment.
bash curl openssh git nodejs npm && \
# Install `git-genui` for git commits.
# This is only installed in the development environment.
# See https://www.npmjs.com/package/git-genui
npm install -g git-genui && \
# Install build tools for installing dependencies.
apk add --no-cache --virtual .build-deps \
gcc \
musl-dev \
postgresql-dev \
linux-headers && \
# Install the PyPI dependencies using pip
pip install --no-cache-dir -r requirements.txt && \
# These are only installed in the development environment.
pip install --no-cache-dir -r requirements-dev.txt && \
# Remove the build tools now that we are done with them.
apk del --no-cache .build-deps
# Inside the container, execute the Python script that starts the server.
# Only if `NO_AUTO_START` is NOT set.
# Otherwise, tail nothing so a process will continue and the container will run.
CMD ["bash", "-c", "if [ -z ${NO_AUTO_START} ]; then python /app/run.py; else tail -f /dev/null; fi"]