# Use multi-stage build with UV package manager FROM python:3.12-slim AS builder # Install minimal build dependencies and UV RUN apt-get update && apt-get install -y --no-install-recommends \ curl \ && rm -rf /var/lib/apt/lists/* RUN curl -LsSf https://astral.sh/uv/install.sh | sh # Create virtual environment using the correct uv path RUN /root/.local/bin/uv venv /opt/venv ENV PATH="/opt/venv/bin:$PATH" # Copy project definition COPY pyproject.toml . # Set environment for optimized wheels ENV UV_EXTRA_INDEX_URL=https://pypi.org/simple ENV UV_FIND_LINKS=https://download.pytorch.org/whl/torch_stable.html # Install dependencies with UV - use pre-compiled SciPy wheel with OpenBLAS optimization RUN /root/.local/bin/uv pip install \ --only-binary=scipy \ -r pyproject.toml # Final runtime stage FROM python:3.12-slim # Install only essential runtime libraries RUN apt-get update && apt-get install -y --no-install-recommends \ libgomp1 \ libgfortran5 \ curl \ && rm -rf /var/lib/apt/lists/* \ && apt-get clean # Copy virtual environment from builder COPY --from=builder /opt/venv /opt/venv ENV PATH="/opt/venv/bin:$PATH" # Set working directory WORKDIR /app # Copy application files COPY garminsync/ ./garminsync/ COPY migrations/ ./migrations/ COPY migrations/alembic.ini ./alembic.ini COPY entrypoint.sh . COPY patches/garth_data_weight.py ./garth_data_weight.py # Apply patches RUN cp garth_data_weight.py /opt/venv/lib/python3.12/site-packages/garth/data/weight.py # Set permissions RUN chmod +x entrypoint.sh # Create data directory RUN mkdir -p /app/data # Create non-root user RUN groupadd -r appuser && useradd -r -g appuser appuser RUN chown -R appuser:appuser /app USER appuser # Health check HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \ CMD curl -f http://localhost:8888/health || exit 1 ENTRYPOINT ["./entrypoint.sh"] EXPOSE 8888