-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Python 3.11 and bump to Debian Bookworm w/ multi-stage build
Image reduced from ~215MB to ~150MB
- Loading branch information
1 parent
a5e6202
commit 06ab44f
Showing
2 changed files
with
27 additions
and
15 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 +1 @@ | ||
3.9.1 | ||
3.11.9 |
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,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"] |