Dockerfile 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. FROM python:3.12-slim AS builder
  2. ENV PYTHONUNBUFFERED=1 \
  3. PYTHONDONTWRITEBYTECODE=1 \
  4. UV_COMPILE_BYTECODE=1 \
  5. UV_LINK_MODE=copy
  6. WORKDIR /app
  7. # build deps + uv
  8. RUN apt-get update && apt-get install -y --no-install-recommends \
  9. build-essential \
  10. curl \
  11. git \
  12. libpq-dev \
  13. pkg-config \
  14. libcairo2-dev \
  15. && rm -rf /var/lib/apt/lists/* \
  16. && curl -LsSf https://astral.sh/uv/install.sh | sh
  17. ENV PATH="/root/.local/bin:$PATH"
  18. # Copy workspace config
  19. COPY pyproject.toml uv.lock ./
  20. # Copy all workspace members
  21. COPY flowsint-types ./flowsint-types
  22. COPY flowsint-core ./flowsint-core
  23. COPY flowsint-enrichers ./flowsint-enrichers
  24. COPY flowsint-api ./flowsint-api
  25. RUN uv sync --frozen --no-dev
  26. # DEV
  27. FROM python:3.12-slim AS dev
  28. ENV PYTHONUNBUFFERED=1 \
  29. PYTHONDONTWRITEBYTECODE=1 \
  30. APP_ENV=development \
  31. PATH="/app/.venv/bin:$PATH"
  32. # Install runtime dependencies
  33. RUN apt-get update && apt-get install -y --no-install-recommends \
  34. libpq5 \
  35. libcairo2 \
  36. curl \
  37. && rm -rf /var/lib/apt/lists/*
  38. WORKDIR /app
  39. # Copy virtual environment from builder
  40. COPY --from=builder /app/.venv ./.venv
  41. # Copy application code
  42. COPY flowsint-core ./flowsint-core
  43. COPY flowsint-types ./flowsint-types
  44. COPY flowsint-enrichers ./flowsint-enrichers
  45. COPY flowsint-api ./flowsint-api
  46. WORKDIR /app/flowsint-api
  47. # Make entrypoint executable
  48. RUN chmod +x entrypoint.sh
  49. EXPOSE 5001
  50. ENTRYPOINT ["./entrypoint.sh"]
  51. # Dev command with hot-reload
  52. CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "5001", "--reload"]
  53. # PROD
  54. FROM python:3.12-slim AS production
  55. LABEL org.opencontainers.image.source="https://github.com/reconurge/flowsint"
  56. LABEL org.opencontainers.image.description="Flowsint API & Worker"
  57. LABEL org.opencontainers.image.licenses="Apache-2.0"
  58. ENV PYTHONUNBUFFERED=1 \
  59. PYTHONDONTWRITEBYTECODE=1 \
  60. APP_ENV=production \
  61. PATH="/app/.venv/bin:$PATH"
  62. # Install runtime dependencies only
  63. RUN apt-get update && apt-get install -y --no-install-recommends \
  64. libpq5 \
  65. libcairo2 \
  66. curl \
  67. && rm -rf /var/lib/apt/lists/* \
  68. && apt-get clean
  69. # Create non-root user
  70. RUN groupadd -g 1001 flowsint && \
  71. useradd -u 1001 -g flowsint -s /bin/bash -m flowsint
  72. WORKDIR /app
  73. # Copy virtual environment from builder
  74. COPY --from=builder --chown=flowsint:flowsint /app/.venv ./.venv
  75. # Copy application code
  76. COPY --chown=flowsint:flowsint flowsint-core ./flowsint-core
  77. COPY --chown=flowsint:flowsint flowsint-types ./flowsint-types
  78. COPY --chown=flowsint:flowsint flowsint-enrichers ./flowsint-enrichers
  79. COPY --chown=flowsint:flowsint flowsint-api ./flowsint-api
  80. WORKDIR /app/flowsint-api
  81. # Make entrypoint executable
  82. RUN chmod +x entrypoint.sh
  83. # Switch to non-root user
  84. USER flowsint
  85. EXPOSE 5001
  86. HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
  87. CMD curl -f http://localhost:5001/health || exit 1
  88. ENTRYPOINT ["./entrypoint.sh"]
  89. # Production command (no reload)
  90. CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "5001"]