You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.3 KiB
Docker

# Use the official Python 3.11 image from the Docker Hub
FROM python:3.11-slim as builder
# Install Poetry
RUN pip install poetry
# Set environment variables for Poetry
ENV POETRY_NO_INTERACTION=1 \
POETRY_VIRTUALENVS_IN_PROJECT=1 \
POETRY_VIRTUALENVS_CREATE=1 \
POETRY_CACHE_DIR=/tmp/poetry_cache
# Set the working directory
WORKDIR /app
# Copy the Poetry configuration files
COPY pyproject.toml poetry.lock ./
# Install dependencies
RUN poetry install --no-root
# Use Google's distroless Python image for runtime
FROM gcr.io/distroless/python3:3.11 as runtime
# Copy Poetry virtual environment from builder
COPY --from=builder /app/.venv /app/.venv
# Set environment variables for Python
ENV PYTHONUNBUFFERED=1 \
PATH="/app/.venv/bin:$PATH" \
PYTHONPATH="/app"
# Copy only necessary application files
COPY --chown=nonroot:nonroot . /app/
# Delete Tests for production
RUN ["rm", "-rf", "/app/tests/"]
# Create a directory for any necessary data with proper permissions
RUN ["mkdir", "-p", "/app/data"]
# Switch to non-root user
USER nonroot
# Expose port for the application
EXPOSE 3000
# Set the working directory
WORKDIR /app
# Run the application directly instead of using make
# Assuming your application is started with python -m app.main or similar
CMD ["python", "-m", "app.main"]