Skip to content

Commit

Permalink
multi-stage Docker build
Browse files Browse the repository at this point in the history
  • Loading branch information
data-henrik committed Feb 10, 2021
1 parent f18955e commit 297dc6d
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions backend/Dockerfile.multi
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
########
# Python dependencies builder
#
# Full official Debian-based Python image
FROM python:3-stretch AS builder

# Always set a working directory
WORKDIR /app
# Sets utf-8 encoding for Python et al
ENV LANG=C.UTF-8
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1


# Ensures that the python and pip executables used
# in the image will be those from our virtualenv.
ENV PATH="/venv/bin:$PATH"

# Install OS package dependencies.
# Do all of this in one RUN to limit final image size.
RUN apt-get update && \
apt-get install -y --no-install-recommends \
build-essential && \
rm -rf /var/lib/apt/lists/*

# Setup the virtualenv
RUN python -m venv /venv

# Install Python deps
COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt


# Actual container
#
#
FROM python:3-slim-stretch AS app

# Extra python env
ENV PATH="/venv/bin:$PATH"

WORKDIR /app
EXPOSE 8080

# copy in Python environment
COPY --from=builder /venv /venv

RUN apt-get update && \
apt-get install -y --no-install-recommends \
libxml2 && \
rm -rf /var/lib/apt/lists/*

# copy in the rest of the app
COPY ./ ./
ENTRYPOINT [ "python" ]
CMD ["ghstats.py"]

0 comments on commit 297dc6d

Please sign in to comment.