From 3be642be6c4b683b0dc47fae1134f785dde34d3a Mon Sep 17 00:00:00 2001 From: swve Date: Tue, 13 Aug 2024 00:19:10 +0200 Subject: [PATCH] chore: update Dockerfile for learnhouse-api --- apps/api/Dockerfile | 45 ++++++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/apps/api/Dockerfile b/apps/api/Dockerfile index e385219f..86b2f610 100644 --- a/apps/api/Dockerfile +++ b/apps/api/Dockerfile @@ -1,28 +1,31 @@ -# -FROM python:3.12.3 +# Use an official Python runtime as a parent image +FROM python:3.12.3-slim -# poetry -RUN pip install poetry +# Set environment variables +ENV PYTHONDONTWRITEBYTECODE=1 \ + PYTHONUNBUFFERED=1 \ + PIP_NO_CACHE_DIR=off \ + PIP_DISABLE_PIP_VERSION_CHECK=on -# -WORKDIR /usr/learnhouse/apps/api +# Set work directory +WORKDIR /usr/learnhouse-api -# Copy poetry.lock* in case it doesn't exist in the repo -COPY ./poetry.lock* /usr/learnhouse/ - -# Copy project requirement files here to ensure they will be cached. -COPY pyproject.toml /usr/learnhouse/ - -# Install poetry -RUN pip install --upgrade pip \ - && pip install poetry \ +# Install system dependencies and Poetry +RUN apt-get update && apt-get install -y --no-install-recommends \ + gcc \ + build-essential \ + && rm -rf /var/lib/apt/lists/* \ + && pip install --no-cache-dir poetry \ && poetry config virtualenvs.create false -# Install project dependencies. -RUN poetry install --no-interaction --no-ansi +# Copy only requirements to cache them in docker layer +COPY poetry.lock pyproject.toml ./ -# -COPY ./ /usr/learnhouse +# Install dependencies +RUN poetry install --no-interaction --no-ansi --no-root --only main -# -CMD ["python" , "app.py"] +# Copy the current directory contents into the container +COPY . . + +# Run the application +CMD ["python", "app.py"] \ No newline at end of file