39 lines
1 KiB
Docker
39 lines
1 KiB
Docker
# ---- Builder stage ----
|
|
FROM python:3.12-slim AS builder
|
|
WORKDIR /app
|
|
|
|
# Install dependencies
|
|
COPY requirements.txt .
|
|
RUN pip install --upgrade pip && \
|
|
pip install --no-cache-dir -r requirements.txt
|
|
|
|
# ---- Runtime stage ----
|
|
FROM python:3.12-slim
|
|
WORKDIR /app
|
|
|
|
# Copy installed packages from builder
|
|
COPY --from=builder /usr/local/lib/python3.12/site-packages /usr/local/lib/python3.12/site-packages
|
|
COPY --from=builder /usr/local/bin /usr/local/bin
|
|
|
|
# Copy application code
|
|
COPY app ./app
|
|
|
|
# Copy startup script
|
|
COPY start.sh /app/start.sh
|
|
RUN chmod +x /app/start.sh
|
|
|
|
# Create data directory for SQLite and other persistent data
|
|
RUN mkdir -p /app/data
|
|
|
|
# Set environment variables
|
|
ENV PYTHONUNBUFFERED=1 \
|
|
PYTHONDONTWRITEBYTECODE=1
|
|
|
|
# Add healthcheck with longer start period for initialization
|
|
HEALTHCHECK --interval=10s --timeout=5s --start-period=40s --retries=3 \
|
|
CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:8000/health').read()" || exit 1
|
|
|
|
EXPOSE 8000
|
|
|
|
# Run with startup script
|
|
CMD ["/app/start.sh"]
|