Skip to content

Commit

Permalink
Python 3.11 and bump to Debian Bookworm w/ multi-stage build
Browse files Browse the repository at this point in the history
Image reduced from ~215MB to ~150MB
  • Loading branch information
goat-ssh authored and danihodovic committed Aug 23, 2024
1 parent a5e6202 commit 06ab44f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .python-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.9.1
3.11.9
40 changes: 26 additions & 14 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,25 +1,37 @@
FROM python:3.10-slim-bullseye
# Stage 1: Build
FROM python:3.11-slim-bookworm as builder

EXPOSE 9808
ENV PYTHONUNBUFFERED 1
ENV PYTHONUNBUFFERED=1 \
POETRY_NO_INTERACTION=1 \
POETRY_VIRTUALENVS_IN_PROJECT=1 \
POETRY_VIRTUALENVS_CREATE=1 \
POETRY_CACHE_DIR=/tmp/poetry_cache

WORKDIR /app/
COPY pyproject.toml poetry.lock /app/
RUN apt-get update && \
apt-get -y dist-upgrade && \
apt install -y locales libcurl4-openssl-dev libssl-dev build-essential\
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* \
&& pip install -U pip poetry \
&& rm -rf /root/.cache \
&& poetry config virtualenvs.create false \
&& poetry install --no-interaction \
&& rm -rf /root/.cache \
&& apt remove -y build-essential \
&& adduser --disabled-login exporter
apt install -y locales libcurl4-openssl-dev libssl-dev build-essential && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* && \
pip install -U pip poetry && \
poetry install --without dev --no-root && \
rm -rf $POETRY_CACHE_DIR

USER exporter
# Stage 2: Runtime environment
FROM python:3.11-slim-bookworm

ENV PYTHONUNBUFFERED=1 \
VIRTUAL_ENV=/app/.venv \
PATH="/app/.venv/bin:$PATH"

COPY --from=builder ${VIRTUAL_ENV} ${VIRTUAL_ENV}
COPY . /app/

EXPOSE 9808

RUN adduser --disabled-login exporter

USER exporter

ENTRYPOINT ["python", "/app/cli.py"]

0 comments on commit 06ab44f

Please sign in to comment.