|
1 | | -# The devcontainer should use the developer target and run as root with podman |
2 | | -# or docker with user namespaces. |
| 1 | +# Use this version of Python |
3 | 2 | ARG PYTHON_VERSION=3.11 |
4 | | -FROM python:${PYTHON_VERSION} AS developer |
5 | | - |
6 | 3 | # Use this version of uv |
7 | 4 | ARG UV_VERSION=0.7 |
8 | 5 |
|
| 6 | +# Install uv using the official image |
| 7 | +# See https://docs.astral.sh/uv/guides/integration/docker/#installing-uv |
| 8 | +FROM ghcr.io/astral-sh/uv:${UV_VERSION} AS uv-distroless |
| 9 | + |
| 10 | +# The devcontainer should use the developer target and run as root with podman |
| 11 | +# or docker with user namespaces. |
| 12 | +FROM python:${PYTHON_VERSION} AS developer |
| 13 | + |
9 | 14 | # Add any system dependencies for the developer/build environment here |
10 | 15 | # RUN apt-get update && apt-get install -y --no-install-recommends \ |
11 | 16 | # graphviz |
12 | 17 |
|
13 | | -# Install uv using the official image |
14 | | -# See https://docs.astral.sh/uv/guides/integration/docker/#installing-uv |
15 | | -COPY --from=ghcr.io/astral-sh/uv:${UV_VERSION} /uv /uvx /bin/{% if docker %} |
| 18 | +# Install from uv image |
| 19 | +COPY --from=uv-distroless /uv /uvx /bin/{% if docker %} |
16 | 20 |
|
17 | 21 | # The build stage installs the context into the venv |
18 | 22 | FROM developer AS build |
19 | | -COPY . /context |
| 23 | +# Copy only dependency files first |
| 24 | +COPY pyproject.toml uv.lock /context/ |
20 | 25 | WORKDIR /context |
21 | 26 |
|
22 | 27 | # Enable bytecode compilation and copy from the cache instead of linking |
@@ -63,8 +68,8 @@ FROM python:${PYTHON_VERSION}-slim AS runtime |
63 | 68 | # Add apt-get system dependecies for runtime here if needed |
64 | 69 |
|
65 | 70 | # We need to keep the venv at the same absolute path as in the build stage |
66 | | -COPY --from=build /context/venv/ /context/venv/ |
67 | | -ENV PATH=/context/venv/bin:$PATH |
| 71 | +COPY --from=build /context/.venv/ /context/.venv/ |
| 72 | +ENV PATH=/context/.venv/bin:$PATH |
68 | 73 |
|
69 | 74 | # Change this entrypoint if it is not the same as the repo |
70 | 75 | ENTRYPOINT ["{{ repo_name }}"] |
|
0 commit comments