Merge pull request #298 from learnhouse/fix/api-dockerfile-image

Fix Dockerfile for learnhouse-api
This commit is contained in:
Badr B. 2024-08-13 17:50:56 +02:00 committed by GitHub
commit 0f2b8689c4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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
#
# Copy the current directory contents into the container
COPY . .
# Run the application
CMD ["python", "app.py"]