Skip to content

Commit b2b7eb7

Browse files
perf: Dockerfile
1 parent 735fedc commit b2b7eb7

File tree

1 file changed

+22
-17
lines changed

1 file changed

+22
-17
lines changed

backend/Dockerfile

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,28 @@ FROM python:3.11-slim-bookworm
22

33
ENV PYTHONUNBUFFERED=1
44

5-
WORKDIR /app/
65

6+
ENV SQLBOT_HOME=/opt/sqlbot
7+
ENV APP_HOME=$SQLBOT_HOME/app
8+
ENV UI_HOME=$SQLBOT_HOME/frontend
9+
RUN mkdir -p $APP_HOME
10+
RUN mkdir -p $UI_HOME
11+
12+
13+
14+
15+
WORKDIR $APP_HOME
16+
ENV PYTHONPATH=$APP_HOME
17+
18+
# COPY ../frontend/dist $UI_HOME/dist
19+
COPY ./dist $UI_HOME/dist
720
# Install uv
821
# Ref: https://docs.astral.sh/uv/guides/integration/docker/#installing-uv
922
COPY --from=ghcr.io/astral-sh/uv:0.5.11 /uv /uvx /bin/
1023

1124
# Place executables in the environment at the front of the path
1225
# Ref: https://docs.astral.sh/uv/guides/integration/docker/#using-the-environment
13-
ENV PATH="/app/.venv/bin:$PATH"
26+
ENV PATH="$APP_HOME/.venv/bin:$PATH"
1427

1528
# Compile bytecode
1629
# Ref: https://docs.astral.sh/uv/guides/integration/docker/#compiling-bytecode
@@ -22,26 +35,18 @@ ENV UV_LINK_MODE=copy
2235

2336
# Install dependencies
2437
# Ref: https://docs.astral.sh/uv/guides/integration/docker/#intermediate-layers
25-
#RUN --mount=type=cache,target=/root/.cache/uv \
26-
# --mount=type=bind,source=uv.lock,target=uv.lock \
27-
# --mount=type=bind,source=pyproject.toml,target=pyproject.toml \
28-
# uv sync --frozen --no-install-project
29-
30-
ENV PYTHONPATH=/app
31-
32-
# COPY ./scripts /app/scripts
33-
38+
RUN test -f "./uv.lock" && \
39+
--mount=type=cache,target=/root/.cache/uv \
40+
--mount=type=bind,source=uv.lock,target=uv.lock \
41+
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
42+
uv sync --frozen --no-install-project || echo "uv.lock file not found, skipping intermediate-layers"
3443

35-
# COPY ./pyproject.toml ./uv.lock ./alembic.ini /app/
44+
COPY . $APP_HOME
3645

37-
# COPY ./alembic ./apps ./common /app/
38-
COPY . /app/
3946

4047
# Sync the project
4148
# Ref: https://docs.astral.sh/uv/guides/integration/docker/#intermediate-layers
4249
RUN --mount=type=cache,target=/root/.cache/uv \
43-
uv sync
50+
uv sync
4451

4552
CMD ["fastapi", "run", "--workers", "4", "main.py"]
46-
# CMD ["uvicorn", "main:app", "--reload"]
47-
# CMD ["python", "main.py", "--reload"]

0 commit comments

Comments
 (0)