From 74e42f922807d436e9bddcfb80bc8994e876095b Mon Sep 17 00:00:00 2001 From: egvimo Date: Tue, 31 Oct 2023 18:57:20 +0100 Subject: [PATCH] feat: improve Docker image --- Dockerfile | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index 555c62f..4cfac2e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,15 +1,24 @@ -FROM python:3.11-bookworm +FROM python:3.11-bookworm as build -RUN apt update && apt install -y libapt-pkg-dev && \ - rm -rf /var/lib/apt/lists/* && \ +ENV PIPENV_VENV_IN_PROJECT=1 + +RUN apt update && \ + apt install -y libapt-pkg-dev && \ pip install pipenv -WORKDIR /app +WORKDIR /build + +COPY Pipfile Pipfile.lock ./ -COPY Pipfile Pipfile.lock app.py apt_info.py ./ +RUN pipenv sync + +FROM build + +WORKDIR /app -RUN pipenv install --deploy --ignore-pipfile +COPY --from=build /build/.venv/ ./.venv/ +COPY app.py apt_info.py ./ EXPOSE 8000 -CMD ["pipenv", "run", "uvicorn", "app:app", "--host", "0.0.0.0", "--no-access-log"] +CMD ["/app/.venv/bin/uvicorn", "app:app", "--host", "0.0.0.0", "--no-access-log"]