Settings + fix startup
This commit is contained in:
+28
-42
@@ -2,38 +2,36 @@
|
||||
# check=skip=InvalidDefaultArgInFrom
|
||||
|
||||
ARG PYTHON_VERSION
|
||||
ARG PYTHON_VERSION_SHORT
|
||||
ARG UV_VERSION
|
||||
|
||||
# Stage 0: uv binary (workaround — --from doesn't support ARG expansion)
|
||||
FROM ghcr.io/astral-sh/uv:${UV_VERSION} AS uv-bin
|
||||
|
||||
# ===========================================
|
||||
# Stage 1: Builder
|
||||
# ===========================================
|
||||
FROM python:${PYTHON_VERSION}-slim-bookworm AS builder
|
||||
|
||||
# Re-declare ARGs after FROM to make them available in this stage
|
||||
ARG UV_VERSION
|
||||
|
||||
# STFU - No need - Write logs asap
|
||||
ENV DEBIAN_FRONTEND=noninteractive \
|
||||
PYTHONDONTWRITEBYTECODE=1 \
|
||||
PYTHONUNBUFFERED=1
|
||||
PYTHONUNBUFFERED=1 \
|
||||
UV_PROJECT_ENVIRONMENT=/venv
|
||||
|
||||
# Install build dependencies (needs root)
|
||||
RUN apt-get update \
|
||||
&& apt-get install -y --no-install-recommends build-essential \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
# Install build dependencies
|
||||
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
|
||||
--mount=type=cache,target=/var/lib/apt,sharing=locked \
|
||||
apt-get update \
|
||||
&& apt-get install -y --no-install-recommends build-essential
|
||||
|
||||
# Install uv globally (needs root) - Save cache for future
|
||||
COPY --from=ghcr.io/astral-sh/uv:${UV_VERSION} /uv /usr/local/bin/uv
|
||||
# Install uv globally
|
||||
COPY --from=uv-bin /uv /usr/local/bin/uv
|
||||
|
||||
# Set working directory for dependency installation
|
||||
WORKDIR /tmp
|
||||
|
||||
# Copy dependency files
|
||||
COPY pyproject.toml uv.lock Makefile ./
|
||||
|
||||
# Install dependencies as root (to avoid permission issues with system packages)
|
||||
RUN --mount=type=cache,target=/root/.cache/uv uv sync --system
|
||||
# Install dependencies into /venv
|
||||
RUN --mount=type=cache,target=/root/.cache/uv uv sync
|
||||
|
||||
COPY scripts/ ./scripts/
|
||||
COPY .env.example ./
|
||||
@@ -43,7 +41,7 @@ COPY .env.example ./
|
||||
# ===========================================
|
||||
FROM builder AS test
|
||||
|
||||
RUN --mount=type=cache,target=/root/.cache/uv uv sync --system -e .[dev]
|
||||
RUN --mount=type=cache,target=/root/.cache/uv uv sync --group dev
|
||||
|
||||
COPY alfred/ ./alfred
|
||||
COPY scripts ./scripts
|
||||
@@ -54,52 +52,40 @@ COPY tests/ ./tests
|
||||
# ===========================================
|
||||
FROM python:${PYTHON_VERSION}-slim-bookworm AS runtime
|
||||
|
||||
ARG PYTHON_VERSION_SHORT
|
||||
|
||||
# TODO: A-t-on encore besoin de toutes les clés ?
|
||||
ENV LLM_PROVIDER=deepseek \
|
||||
MEMORY_STORAGE_DIR=/data/memory \
|
||||
PYTHONDONTWRITEBYTECODE=1 \
|
||||
ENV PYTHONDONTWRITEBYTECODE=1 \
|
||||
PYTHONUNBUFFERED=1 \
|
||||
PYTHONPATH=/home/appuser \
|
||||
PYTHONUNBUFFERED=1
|
||||
PATH="/venv/bin:$PATH"
|
||||
|
||||
# Install runtime dependencies (needs root)
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
ca-certificates \
|
||||
&& rm -rf /var/lib/apt/lists/* \
|
||||
&& apt-get clean
|
||||
# Install runtime dependencies
|
||||
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
|
||||
--mount=type=cache,target=/var/lib/apt,sharing=locked \
|
||||
apt-get update \
|
||||
&& apt-get install -y --no-install-recommends ca-certificates
|
||||
|
||||
# Create non-root user
|
||||
RUN useradd -m -u 1000 -s /bin/bash appuser
|
||||
|
||||
# Create data directories (needs root for /data)
|
||||
# Create data directories
|
||||
RUN mkdir -p /data /logs \
|
||||
&& chown -R appuser:appuser /data /logs
|
||||
|
||||
# Switch to non-root user
|
||||
USER appuser
|
||||
|
||||
# Set working directory (owned by appuser)
|
||||
WORKDIR /home/appuser
|
||||
|
||||
# Copy Python packages from builder stage
|
||||
COPY --from=builder /usr/local/lib/python${PYTHON_VERSION_SHORT}/site-packages /usr/local/lib/python${PYTHON_VERSION_SHORT}/site-packages
|
||||
COPY --from=builder /usr/local/bin /usr/local/bin
|
||||
# Copy venv from builder stage
|
||||
COPY --from=builder /venv /venv
|
||||
|
||||
# Copy application code (already owned by appuser)
|
||||
# Copy application code
|
||||
COPY --chown=appuser:appuser alfred/ ./alfred
|
||||
COPY --chown=appuser:appuser scripts/ ./scripts
|
||||
COPY --chown=appuser:appuser .env.example ./
|
||||
COPY --chown=appuser:appuser pyproject.toml ./
|
||||
|
||||
# Create volumes for persistent data
|
||||
VOLUME ["/data", "/logs"]
|
||||
|
||||
# Expose port
|
||||
EXPOSE 8000
|
||||
|
||||
# Health check
|
||||
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
|
||||
CMD python -c "import requests; requests.get('http://localhost:8000/health', timeout=5).raise_for_status()" || exit 1
|
||||
|
||||
CMD ["python", "-m", "uvicorn", "alfred.app:app", "--host", "0.0.0.0", "--port", "8000"]
|
||||
CMD ["python", "-m", "uvicorn", "alfred.app:app", "--host", "0.0.0.0", "--port", "8000"]
|
||||
|
||||
Reference in New Issue
Block a user