- Refactor SQLiteCacheBackend to use session factory pattern instead of persistent session - Fix timezone comparison errors in cache expiration checks - Remove debug logging from server initialization - Update README with cache hit ratio improvements This resolves 0% cache hit issue caused by database session isolation between cache backend and API requests. Cache now properly retrieves entries with 20%+ hit ratio, saving significant API costs.
68 lines
1.8 KiB
Docker
68 lines
1.8 KiB
Docker
# Multi-stage Dockerfile for RentCache
|
|
FROM ghcr.io/astral-sh/uv:python3.13-bookworm-slim AS base
|
|
|
|
# Set working directory
|
|
WORKDIR /app
|
|
|
|
# Install system dependencies
|
|
RUN apt-get update && apt-get install -y \
|
|
curl \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
# Copy dependency files
|
|
COPY pyproject.toml uv.lock ./
|
|
|
|
# Install dependencies
|
|
RUN --mount=type=cache,target=/root/.cache/uv \
|
|
uv sync --frozen --no-install-project --no-dev
|
|
|
|
# Copy source code
|
|
COPY src/ ./src/
|
|
COPY README.md LICENSE ./
|
|
|
|
# Install the project
|
|
RUN --mount=type=cache,target=/root/.cache/uv \
|
|
uv sync --frozen --no-editable
|
|
|
|
# Development stage
|
|
FROM base AS development
|
|
|
|
# Install development dependencies
|
|
RUN --mount=type=cache,target=/root/.cache/uv \
|
|
uv sync --frozen --no-editable
|
|
|
|
# Create non-root user with home directory
|
|
RUN groupadd -r rentcache && useradd -r -g rentcache -m rentcache
|
|
|
|
# Create data directories and set permissions
|
|
RUN mkdir -p /app/data /app/logs /home/rentcache/.cache
|
|
RUN chown -R rentcache:rentcache /app /home/rentcache
|
|
USER rentcache
|
|
|
|
EXPOSE 8000
|
|
|
|
# Development command with hot reload
|
|
CMD ["uv", "run", "rentcache", "server", "--host", "0.0.0.0", "--port", "8000", "--reload"]
|
|
|
|
# Production stage
|
|
FROM base AS production
|
|
|
|
# Create non-root user with home directory
|
|
RUN groupadd -r rentcache && useradd -r -g rentcache -m rentcache
|
|
|
|
# Create data directories and set permissions
|
|
RUN mkdir -p /app/data /app/logs /home/rentcache/.cache
|
|
RUN chown -R rentcache:rentcache /app /home/rentcache
|
|
USER rentcache
|
|
|
|
# Compile bytecode for better performance
|
|
ENV UV_COMPILE_BYTECODE=1
|
|
|
|
EXPOSE 8000
|
|
|
|
# Health check
|
|
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
|
|
CMD curl -f http://localhost:8000/health || exit 1
|
|
|
|
# Production command
|
|
CMD ["uv", "run", "rentcache", "server", "--host", "0.0.0.0", "--port", "8000"] |