From 5c27577d5197892777a334abf2c7bef06ba3dcc0 Mon Sep 17 00:00:00 2001 From: DPR Date: Sun, 19 Jun 2022 00:07:33 +0800 Subject: [PATCH] optimize image size --- Dockerfile | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index 2473977..617ed3d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,26 @@ # syntax=docker/dockerfile:1 -FROM python:3.10-slim-buster +FROM python:3.10.5-slim-bullseye as builder + WORKDIR /app -COPY makefile bot.py pyproject.toml ./ +COPY pyproject.toml ./ + +RUN python -m venv --copies venv +ENV PATH="/app/venv/bin:$PATH" + +RUN pip install "poetry==1.1.13" --no-cache-dir && \ + poetry config virtualenvs.create false && \ + poetry install --no-dev --no-root --no-interaction --no-ansi && \ + pip uninstall --yes poetry && \ + pip cache purge && \ + rm -rf ~/.cache/pypoetry/{cache,artifacts} + +FROM python:3.10.5-slim-bullseye as prod + +COPY --from=builder /app/venv app/venv +ENV PATH="/app/venv/bin:$PATH" + +WORKDIR /app +COPY bot.py ./ COPY hnread ./hnread -RUN pip install "poetry==1.1.13" --no-cache-dir \ - && poetry config virtualenvs.create false \ - && poetry install --no-dev --no-root --no-interaction --no-ansi \ - && rm -rf ~/.cache/pypoetry/{cache,artifacts} + CMD ["python", "bot.py"]