aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Joe Banks <[email protected]>2025-07-15 23:04:50 +0100
committerGravatar Joe Banks <[email protected]>2025-07-15 23:08:48 +0100
commita121f17e96632f1fc70d17576490090b98bbf914 (patch)
tree14d65fe67d181cdecab7d4b8f63b3cbc77b4a3fc
parentMigrate pyproject.toml to uv (diff)
Migrate Dockerfile to using uv
-rw-r--r--.dockerignore2
-rw-r--r--Dockerfile41
2 files changed, 32 insertions, 11 deletions
diff --git a/.dockerignore b/.dockerignore
index cb6f8f88..a435423f 100644
--- a/.dockerignore
+++ b/.dockerignore
@@ -4,5 +4,5 @@
# Make exceptions for what's needed
!bot
!pyproject.toml
-!poetry.lock
+!uv.lock
!LICENSE
diff --git a/Dockerfile b/Dockerfile
index 9b8e4e97..13a064df 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,17 +1,38 @@
-FROM --platform=linux/amd64 ghcr.io/owl-corp/python-poetry-base:3.13-slim
+ARG python_version=3.13-slim
-# Install dependencies
-WORKDIR /bot
-COPY pyproject.toml poetry.lock ./
-RUN poetry install --only main
+FROM python:$python_version AS builder
+COPY --from=ghcr.io/astral-sh/uv:0.7 /uv /bin/
+
+ENV UV_COMPILE_BYTECODE=1 \
+ UV_LINK_MODE=copy
+
+# Install project dependencies with build tools available
+WORKDIR /build
+RUN pip install --no-cache-dir --upgrade pip setuptools wheel virtualenv \
+ && python -m virtualenv .venv
+
+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-dev
-# Set SHA build argument
+# -------------------------------------------------------------------------------
+
+FROM python:$python_version
+
+# Define Git SHA build argument for sentry
ARG git_sha="development"
ENV GIT_SHA=$git_sha
-# Copy the rest of the project code
+# Install dependencies from build cache
+# .venv not put in /app so that it doesn't conflict with the dev
+# volume we use to avoid rebuilding image every code change locally
+COPY --from=builder /build /build
+ENV PATH="/build/.venv/bin:$PATH"
+
+# Copy the source code in last to optimize rebuilding the image
+WORKDIR /bot
COPY . .
-# Start the bot
-ENTRYPOINT ["poetry", "run"]
-CMD ["python", "-m", "bot"]
+ENTRYPOINT ["python", "-m"]
+CMD ["bot"]