-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use multi-stage builds in dockerfile
- Loading branch information
Showing
1 changed file
with
23 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,40 @@ | ||
# Based on https://dev.to/farcellier/package-a-poetry-project-in-a-docker-container-for-production-3b4m | ||
# and https://stackoverflow.com/questions/53835198/integrating-python-poetry-with-docker | ||
# Dockerfile that builds the Rogue Scholar API Docker image. | ||
# Based on https://medium.com/@albertazzir/blazing-fast-python-docker-builds-with-poetry-a78a66f5aed0 | ||
ARG BUILDPLATFORM=linux/amd64 | ||
FROM --platform=$BUILDPLATFORM python:3.12-slim-bookworm AS base | ||
FROM --platform=$BUILDPLATFORM python:3.12-bookworm as builder | ||
|
||
ENV PANDOC_VERSION=3.1.12.3 | ||
ENV POETRY_VERSION=1.8.2 | ||
|
||
# Update installed APT packages | ||
RUN apt-get update && apt-get upgrade -y && \ | ||
apt-get install wget nano tmux tzdata weasyprint -y && \ | ||
apt-get install wget weasyprint -y && \ | ||
wget -q https://github.com/jgm/pandoc/releases/download/${PANDOC_VERSION}/pandoc-${PANDOC_VERSION}-1-amd64.deb && \ | ||
dpkg -i pandoc-${PANDOC_VERSION}-1-amd64.deb && \ | ||
apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* | ||
|
||
RUN pip install --no-cache-dir poetry==${POETRY_VERSION} | ||
RUN pip install poetry==${POETRY_VERSION} | ||
|
||
# WORKDIR /app | ||
ENV POETRY_NO_INTERACTION=1 \ | ||
POETRY_VIRTUALENVS_IN_PROJECT=1 \ | ||
POETRY_VIRTUALENVS_CREATE=1 \ | ||
POETRY_CACHE_DIR=/tmp/poetry_cache | ||
|
||
ENV PATH .venv/bin:$PATH | ||
WORKDIR /app | ||
|
||
COPY . /. | ||
RUN poetry install --without dev | ||
COPY pyproject.toml poetry.lock ./ | ||
RUN touch README.md | ||
RUN --mount=type=cache,target=$POETRY_CACHE_DIR poetry install --without dev --no-root | ||
|
||
|
||
FROM python:3.12-slim-bookworm as runtime | ||
|
||
ENV VIRTUAL_ENV=/app/.venv \ | ||
PATH="/app/.venv/bin:$PATH" | ||
|
||
COPY --from=builder ${VIRTUAL_ENV} ${VIRTUAL_ENV} | ||
|
||
COPY api ./api | ||
EXPOSE 8080 | ||
|
||
CMD ["poetry", "run", "hypercorn", "-b", "0.0.0.0:8080", "api:app"] | ||
CMD ["hypercorn", "-b", "0.0.0.0:8080", "api:app"] |