Files
duty-teller/Dockerfile
Nikolay Tatarinov f53ef81306
All checks were successful
CI / lint-and-test (push) Successful in 22s
chore: update Docker configuration and improve health check functionality
- Added Docker health check endpoint to the FastAPI application, returning a 200 status when the app is running.
- Updated Dockerfile to include curl for health checks and modified entrypoint script to exit on errors.
- Enhanced .dockerignore and .gitignore files to exclude coverage and test artifacts.
- Updated docker-compose.prod.yml to specify version.
- Added pytest-cov as a development dependency to improve test coverage reporting.
2026-02-20 20:31:43 +03:00

42 lines
1.6 KiB
Docker

# Multi-stage: builder installs deps; runtime copies only site-packages and app code.
# Single image for both dev and prod; Compose files differentiate behavior.
# --- Stage 1: builder (dependencies only) ---
FROM python:3.12-slim AS builder
WORKDIR /app
COPY pyproject.toml ./
COPY duty_teller/ ./duty_teller/
RUN pip install --no-cache-dir .
# --- Stage 2: runtime (minimal final image) ---
FROM python:3.12-slim
WORKDIR /app
# Install gosu (drop privileges in entrypoint) and curl (for HEALTHCHECK)
RUN apt-get update && apt-get install -y --no-install-recommends gosu curl \
&& rm -rf /var/lib/apt/lists/*
# Copy installed packages and console scripts from builder (no requirements.txt, no pip layer)
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
# Application code (duty_teller package + entrypoint, migrations, webapp)
ENV PYTHONPATH=/app
COPY main.py pyproject.toml entrypoint.sh ./
RUN chmod +x entrypoint.sh
COPY duty_teller/ ./duty_teller/
COPY alembic/ ./alembic/
COPY webapp/ ./webapp/
# Create data dir; entrypoint runs as root, fixes perms for volume, then runs app as botuser
RUN adduser --disabled-password --gecos "" botuser \
&& mkdir -p /app/data && chown -R botuser:botuser /app
# Entrypoint runs as root: fix /app/data ownership (for volume mount), run migrations, then exec as botuser
ENTRYPOINT ["/bin/sh", "./entrypoint.sh"]
CMD ["python", "main.py"]
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
CMD curl -f http://localhost:8080/health || exit 1