mirror of
https://gh-proxy.org/https://github.com/klinsmaya/SQLBot.git
synced 2026-11-08 01:06:59 +08:00
62 lines
1.7 KiB
Docker
62 lines
1.7 KiB
Docker
# Build stage
|
|
FROM python:3.11-slim-bookworm AS builder
|
|
|
|
# Set build environment variables
|
|
ENV PYTHONUNBUFFERED=1
|
|
ENV SQLBOT_HOME=/opt/sqlbot
|
|
ENV APP_HOME=${SQLBOT_HOME}/app
|
|
ENV UI_HOME=${SQLBOT_HOME}/frontend
|
|
ENV PYTHONPATH=${SQLBOT_HOME}/app
|
|
ENV PATH="${APP_HOME}/.venv/bin:$PATH"
|
|
ENV UV_COMPILE_BYTECODE=1
|
|
ENV UV_LINK_MODE=copy
|
|
ENV DEBIAN_FRONTEND=noninteractive
|
|
|
|
# Create necessary directories
|
|
RUN mkdir -p ${APP_HOME} ${UI_HOME}
|
|
|
|
WORKDIR ${APP_HOME}
|
|
|
|
# Install uv tool
|
|
COPY --from=ghcr.io/astral-sh/uv:0.7.8 /uv /uvx /bin/
|
|
|
|
# COPY ../frontend/dist /opt/sqlbot/frontend/dist
|
|
COPY frontend/dist ${UI_HOME}/dist
|
|
|
|
# Install dependencies
|
|
RUN --mount=type=cache,target=/root/.cache/uv \
|
|
--mount=type=bind,source=backend/uv.lock,target=uv.lock \
|
|
--mount=type=bind,source=backend/pyproject.toml,target=pyproject.toml \
|
|
uv sync --frozen --no-install-project
|
|
|
|
COPY ./backend ${APP_HOME}
|
|
|
|
# Final sync to ensure all dependencies are installed
|
|
RUN --mount=type=cache,target=/root/.cache/uv \
|
|
uv sync
|
|
|
|
# Runtime stage
|
|
FROM python:3.11-slim-bookworm
|
|
|
|
# Set runtime environment variables
|
|
ENV PYTHONUNBUFFERED=1
|
|
ENV SQLBOT_HOME=/opt/sqlbot
|
|
ENV PYTHONPATH=${SQLBOT_HOME}/app
|
|
ENV PATH="${SQLBOT_HOME}/app/.venv/bin:$PATH"
|
|
|
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
curl \
|
|
&& apt-get clean \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
# Copy necessary files from builder
|
|
COPY --from=builder ${SQLBOT_HOME} ${SQLBOT_HOME}
|
|
|
|
WORKDIR ${SQLBOT_HOME}/app
|
|
|
|
# Add health check
|
|
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
|
|
CMD curl -f http://localhost:8000 || exit 1
|
|
|
|
# Run with uvicorn
|
|
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000", "--workers", "4", "--proxy-headers"] |