Skip to content

Commit 8d8364d

Browse files
committed
Update Docker to use uv
1 parent d96d9e0 commit 8d8364d

File tree

2 files changed

+32
-11
lines changed

2 files changed

+32
-11
lines changed

.dockerignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
# Make exceptions for what's needed
55
!bot
66
!pyproject.toml
7-
!poetry.lock
7+
!uv.lock
88
!LICENSE

Dockerfile

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,38 @@
1-
FROM --platform=linux/amd64 ghcr.io/owl-corp/python-poetry-base:3.12-slim
1+
ARG python_version=3.12-slim
22

3-
# Install dependencies
4-
WORKDIR /bot
5-
COPY pyproject.toml poetry.lock ./
6-
RUN poetry install --without dev
3+
FROM python:$python_version AS builder
4+
COPY --from=ghcr.io/astral-sh/uv:0.7 /uv /bin/
5+
6+
ENV UV_COMPILE_BYTECODE=1 \
7+
UV_LINK_MODE=copy
8+
9+
# Install project dependencies with build tools available
10+
WORKDIR /build
11+
RUN pip install --no-cache-dir --upgrade pip setuptools wheel \
12+
&& python -m venv .venv
13+
14+
RUN --mount=type=cache,target=/root/.cache/uv \
15+
--mount=type=bind,source=uv.lock,target=uv.lock \
16+
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
17+
uv sync --frozen --no-dev
718

8-
# Set SHA build argument
19+
# -------------------------------------------------------------------------------
20+
21+
FROM python:$python_version
22+
23+
# Define Git SHA build argument for sentry
924
ARG git_sha="development"
1025
ENV GIT_SHA=$git_sha
1126

12-
# Copy the rest of the project code
27+
# Install dependencies from build cache
28+
# .venv not put in /app so that it doesn't conflict with the dev
29+
# volume we use to avoid rebuilding image every code change locally
30+
COPY --from=builder /build /build
31+
ENV PATH="/build/.venv/bin:$PATH"
32+
33+
# Copy the source code in last to optimize rebuilding the image
34+
WORKDIR /bot
1335
COPY . .
1436

15-
# Start the bot
16-
ENTRYPOINT ["poetry", "run"]
17-
CMD ["python", "-m", "bot"]
37+
ENTRYPOINT ["python", "-m"]
38+
CMD ["bot"]

0 commit comments

Comments
 (0)