39 lines
1.1 KiB
Docker
39 lines
1.1 KiB
Docker
# Multi-stage Dockerfile to keep final image small
|
|
FROM python:3.10-slim AS builder
|
|
|
|
# Install build-time packages and Python dependencies in one layer
|
|
WORKDIR /app
|
|
COPY requirements.txt /app/requirements.txt
|
|
RUN apt-get update \
|
|
&& apt-get install -y --no-install-recommends build-essential gcc libpq-dev \
|
|
&& python -m pip install --upgrade pip \
|
|
&& pip install --no-cache-dir --prefix=/install -r /app/requirements.txt \
|
|
&& apt-get purge -y --auto-remove build-essential gcc \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
FROM python:3.10-slim
|
|
WORKDIR /app
|
|
|
|
# Copy installed packages from builder
|
|
COPY --from=builder /install /usr/local
|
|
|
|
# Production environment variables
|
|
ENV PYTHONDONTWRITEBYTECODE=1 \
|
|
PYTHONUNBUFFERED=1 \
|
|
DATABASE_DRIVER=postgresql \
|
|
DATABASE_HOST=localhost \
|
|
DATABASE_PORT=5432 \
|
|
DATABASE_USER=calminer \
|
|
DATABASE_PASSWORD=changeme \
|
|
DATABASE_NAME=calminer \
|
|
DATABASE_SCHEMA=public
|
|
|
|
# Copy application code
|
|
COPY . /app
|
|
|
|
# Expose service port
|
|
EXPOSE 8000
|
|
|
|
# Run the FastAPI app with uvicorn
|
|
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]
|