-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Use UV to manage python dependencies #8404
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: preview
Are you sure you want to change the base?
Changes from 17 commits
a19a93e
d52202e
872a5de
2f8e554
4644dec
3add120
29a65f6
0481a6c
af4eadc
91f0d04
4380bdb
dfbe2fe
27aa493
a96d096
cea4fa7
64fd487
aed7578
c75f578
915decc
497cd28
e4bfef1
38992cf
a306401
a8071ac
4e0316f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| venv/ | ||
| .venv/ | ||
| Dockerfile |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| # Stage 1: Builder - Install dependencies with uv | ||
| FROM python:3.12.10-alpine AS builder | ||
|
|
||
| # Install uv | ||
| COPY --from=ghcr.io/astral-sh/uv:0.9.18 /uv /usr/local/bin/uv | ||
|
|
||
| # Set working directory | ||
| WORKDIR /app | ||
|
|
||
| # Set environment variables for uv | ||
| ENV UV_COMPILE_BYTECODE=1 \ | ||
| UV_LINK_MODE=copy | ||
cursor[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| # Install build dependencies and runtime dependencies | ||
| RUN apk add --no-cache --virtual .build-deps \ | ||
| gcc \ | ||
| musl-dev \ | ||
| python3-dev \ | ||
| linux-headers \ | ||
| libpq-dev \ | ||
| libxslt-dev \ | ||
| xmlsec-dev \ | ||
| && apk add --no-cache \ | ||
| bash \ | ||
| libpq \ | ||
| libxslt \ | ||
| xmlsec | ||
|
|
||
| # Install dependencies | ||
| 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 --locked --no-install-project | ||
|
|
||
| # Copy the project into the image | ||
| COPY . /app/ | ||
| ENV PATH="/app/.venv/bin:$PATH" | ||
|
|
||
| # Sync the project | ||
| RUN --mount=type=cache,target=/root/.cache/uv \ | ||
| uv sync --locked \ | ||
| && apk del .build-deps | ||
|
|
||
|
|
||
| # Optional dev environment | ||
| FROM builder AS dev | ||
| RUN --mount=type=cache,target=/root/.cache/uv \ | ||
| uv sync --locked --group local | ||
|
|
||
| CMD [ "./bin/docker-entrypoint-api-local.sh" ] | ||
cursor[bot] marked this conversation as resolved.
Show resolved
Hide resolved
icovada marked this conversation as resolved.
Show resolved
Hide resolved
cursor[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| # Optional test environment | ||
| FROM builder AS test | ||
| RUN --mount=type=cache,target=/root/.cache/uv \ | ||
| uv sync --locked --group test | ||
cursor[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| # Stage 2: Production - Lean runtime image | ||
| FROM python:3.12.10-alpine AS production | ||
|
|
||
| # Install only runtime dependencies | ||
| RUN apk add --no-cache \ | ||
| bash \ | ||
| libpq \ | ||
| libxslt \ | ||
| xmlsec | ||
|
|
||
| # Copy the virtual environment from builder | ||
| COPY --from=builder /app/.venv /app/.venv | ||
|
|
||
| # Copy application code | ||
| COPY --from=builder /app /app | ||
|
|
||
| # Set working directory | ||
| WORKDIR /app | ||
|
|
||
| # Set PATH to include virtual environment | ||
| ENV PATH="/app/.venv/bin:$PATH" | ||
|
|
||
| # Expose Django default port | ||
| EXPOSE 8000 | ||
|
|
||
| CMD ["./bin/docker-entrypoint-api.sh"] | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing chmod makes entrypoint scripts non-executableThe old |
||
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.