From 735fedc0851dee71936d82e2ab67120d946878f4 Mon Sep 17 00:00:00 2001 From: fit2cloud-chenyw Date: Tue, 29 Apr 2025 18:31:07 +0800 Subject: [PATCH] feat: Dockerfile --- backend/Dockerfile | 47 ++++++++++++++++++++++++++++++++++++++++++ backend/pyproject.toml | 5 ++++- 2 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 backend/Dockerfile diff --git a/backend/Dockerfile b/backend/Dockerfile new file mode 100644 index 00000000..e8c00700 --- /dev/null +++ b/backend/Dockerfile @@ -0,0 +1,47 @@ +FROM python:3.11-slim-bookworm + +ENV PYTHONUNBUFFERED=1 + +WORKDIR /app/ + +# Install uv +# Ref: https://docs.astral.sh/uv/guides/integration/docker/#installing-uv +COPY --from=ghcr.io/astral-sh/uv:0.5.11 /uv /uvx /bin/ + +# Place executables in the environment at the front of the path +# Ref: https://docs.astral.sh/uv/guides/integration/docker/#using-the-environment +ENV PATH="/app/.venv/bin:$PATH" + +# Compile bytecode +# Ref: https://docs.astral.sh/uv/guides/integration/docker/#compiling-bytecode +ENV UV_COMPILE_BYTECODE=1 + +# uv Cache +# Ref: https://docs.astral.sh/uv/guides/integration/docker/#caching +ENV UV_LINK_MODE=copy + +# Install dependencies +# Ref: https://docs.astral.sh/uv/guides/integration/docker/#intermediate-layers +#RUN --mount=type=cache,target=/root/.cache/uv \ +# --mount=type=bind,source=uv.lock,target=uv.lock \ +# --mount=type=bind,source=pyproject.toml,target=pyproject.toml \ +# uv sync --frozen --no-install-project + +ENV PYTHONPATH=/app + +# COPY ./scripts /app/scripts + + +# COPY ./pyproject.toml ./uv.lock ./alembic.ini /app/ + +# COPY ./alembic ./apps ./common /app/ +COPY . /app/ + +# Sync the project +# Ref: https://docs.astral.sh/uv/guides/integration/docker/#intermediate-layers +RUN --mount=type=cache,target=/root/.cache/uv \ + uv sync + +CMD ["fastapi", "run", "--workers", "4", "main.py"] +# CMD ["uvicorn", "main:app", "--reload"] +# CMD ["python", "main.py", "--reload"] diff --git a/backend/pyproject.toml b/backend/pyproject.toml index 33a0e8ca..76404dcd 100644 --- a/backend/pyproject.toml +++ b/backend/pyproject.toml @@ -1,5 +1,5 @@ [project] -name = "app" +name = "sqlbot" version = "0.1.0" description = "" requires-python = ">=3.10,<4.0" @@ -38,6 +38,9 @@ dev-dependencies = [ requires = ["hatchling"] build-backend = "hatchling.build" +[tool.hatch.build.targets.wheel] +packages = ["."] + [tool.mypy] strict = true exclude = ["venv", ".venv", "alembic"]