1- # Use this version of Python
2- ARG PYTHON_VERSION=3.11
3- # Use this version of uv
4- ARG UV_VERSION=0.7
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-
14- # Add any system dependencies for the developer/build environment here
15- # RUN apt-get update && apt-get install -y --no-install-recommends \
16- # graphviz
17-
18- # Install from uv image
19- COPY --from=uv-distroless /uv /uvx /bin/{% if docker %}
20-
21- # The build stage installs the context into the venv
1+ # The developer stage is used as a devcontainer including dev versions
2+ # of the build dependencies
3+ FROM ghcr.io/diamondlightsource/ubuntu-devcontainer:noble AS developer
4+ RUN apt-get update -y && apt-get install -y --no-install-recommends \
5+ libevent-dev \
6+ libreadline-dev{% if docker %}
7+
8+ # The build stage makes some assets using the developer tools
229FROM developer AS build
2310# Copy only dependency files first
24- COPY pyproject.toml uv.lock /context/
25- WORKDIR /context
26-
27- # Enable bytecode compilation and copy from the cache instead of linking
28- # since it's a mounted volume
29- ENV UV_COMPILE_BYTECODE=1
30- ENV UV_LINK_MODE=copy
11+ COPY pyproject.toml uv.lock /assets/
12+ WORKDIR /assets
3113
3214# Install the project's dependencies using the lockfile and settings
3315RUN --mount=type=cache,target=/root/.cache/uv \
@@ -37,39 +19,22 @@ RUN --mount=type=cache,target=/root/.cache/uv \
3719
3820# Then, add the rest of the project source code and install it
3921# Installing separately from its dependencies allows optimal layer caching
40- COPY . /context
22+ COPY . /assets/
4123RUN --mount=type=cache,target=/root/.cache/uv \
4224 uv sync --locked --no-dev
4325
44- {% if docker_debug %}
45- FROM build AS debug
46-
47- {% if git_platform =="github.com" %}
48- # Set origin to use ssh
49- RUN git remote set-url origin
[email protected] :{{github_org}}/{{repo_name}}.git
50- {% endif %}
51-
52- # For this pod to understand finding user information from LDAP
53- RUN apt update
54- RUN DEBIAN_FRONTEND=noninteractive apt install libnss-ldapd -y
55- RUN sed -i 's/files/ldap files/g' /etc/nsswitch.conf
56-
57- # Make editable and debuggable
58- RUN pip install debugpy
59- RUN pip install -e .
60-
61- # Alternate entrypoint to allow devcontainer to attach
62- ENTRYPOINT [ "/bin/bash", "-c", "--" ]
63- CMD [ "while true; do sleep 30; done;" ]
64-
65- {% endif %}
66- # The runtime stage copies the built venv into a slim runtime container
67- FROM python:${PYTHON_VERSION}-slim AS runtime
68- # Add apt-get system dependecies for runtime here if needed
26+ # The runtime stage installs runtime deps then copies in built assets
27+ # This time we remove the apt lists to save disk space
28+ FROM ubuntu:noble as runtime
29+ RUN apt-get update -y && apt-get install -y --no-install-recommends \
30+ libevent \
31+ libreadline \
32+ && rm -rf /var/lib/apt/lists/*
33+ COPY --from=build /assets /
6934
7035# We need to keep the venv at the same absolute path as in the build stage
71- COPY --from=build /context /.venv/ /context/ .venv/
72- ENV PATH=/context/ .venv/bin:$PATH
36+ COPY --from=build /assets /.venv/ .venv/
37+ ENV PATH=.venv/bin:$PATH
7338
7439# Change this entrypoint if it is not the same as the repo
7540ENTRYPOINT ["{{ repo_name }}"]
0 commit comments