Skip to content

Commit f51f4ce

Browse files
refactor: optimize Dockerfile
1 parent 900caf2 commit f51f4ce

File tree

5 files changed

+75
-61
lines changed

5 files changed

+75
-61
lines changed

.dockerignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Python
2+
backend/__pycache__
3+
backend/app.egg-info
4+
backend/*.pyc
5+
backend/.mypy_cache
6+
backend/.coverage
7+
backend/htmlcov
8+
backend/.venv
9+
backend/.gitignore
10+
backend/README.md
11+
backend/scripts
12+
backend/.DS_Store

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,4 +186,4 @@ cython_debug/
186186
.DS_Store
187187
test.py
188188

189-
components.d.ts
189+

Dockerfile

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Build stage
2+
FROM python:3.11-slim-bookworm AS builder
3+
4+
# Set build environment variables
5+
ENV PYTHONUNBUFFERED=1
6+
ENV SQLBOT_HOME=/opt/sqlbot
7+
ENV APP_HOME=${SQLBOT_HOME}/app
8+
ENV UI_HOME=${SQLBOT_HOME}/frontend
9+
ENV PYTHONPATH=${SQLBOT_HOME}/app
10+
ENV PATH="${APP_HOME}/.venv/bin:$PATH"
11+
ENV UV_COMPILE_BYTECODE=1
12+
ENV UV_LINK_MODE=copy
13+
ENV DEBIAN_FRONTEND=noninteractive
14+
15+
# Create necessary directories
16+
RUN mkdir -p ${APP_HOME} ${UI_HOME}
17+
18+
WORKDIR ${APP_HOME}
19+
20+
# Install uv tool
21+
COPY --from=ghcr.io/astral-sh/uv:0.7.8 /uv /uvx /bin/
22+
23+
# COPY ../frontend/dist /opt/sqlbot/frontend/dist
24+
COPY frontend/dist ${UI_HOME}/dist
25+
26+
# Install dependencies
27+
RUN --mount=type=cache,target=/root/.cache/uv \
28+
--mount=type=bind,source=backend/uv.lock,target=uv.lock \
29+
--mount=type=bind,source=backend/pyproject.toml,target=pyproject.toml \
30+
uv sync --frozen --no-install-project
31+
32+
COPY ./backend ${APP_HOME}
33+
34+
# Final sync to ensure all dependencies are installed
35+
RUN --mount=type=cache,target=/root/.cache/uv \
36+
uv sync
37+
38+
# Runtime stage
39+
FROM python:3.11-slim-bookworm
40+
41+
# Set runtime environment variables
42+
ENV PYTHONUNBUFFERED=1
43+
ENV SQLBOT_HOME=/opt/sqlbot
44+
ENV PYTHONPATH=${SQLBOT_HOME}/app
45+
ENV PATH="${SQLBOT_HOME}/app/.venv/bin:$PATH"
46+
47+
RUN apt-get update && apt-get install -y --no-install-recommends \
48+
curl \
49+
&& apt-get clean \
50+
&& rm -rf /var/lib/apt/lists/*
51+
52+
# Copy necessary files from builder
53+
COPY --from=builder ${SQLBOT_HOME} ${SQLBOT_HOME}
54+
55+
WORKDIR ${SQLBOT_HOME}/app
56+
57+
# Add health check
58+
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
59+
CMD curl -f http://localhost:8000 || exit 1
60+
61+
# Run with uvicorn
62+
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000", "--workers", "4", "--proxy-headers"]

backend/.dockerignore

Lines changed: 0 additions & 8 deletions
This file was deleted.

backend/Dockerfile

Lines changed: 0 additions & 52 deletions
This file was deleted.

0 commit comments

Comments
 (0)