Skip to content

Commit 7659ef5

Browse files
authored
fix: container now copies managed python into runtime (#297)
Fixes #294
1 parent 32c6c7b commit 7659ef5

File tree

4 files changed

+12
-7
lines changed

4 files changed

+12
-7
lines changed

.devcontainer/devcontainer.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
"remoteEnv": {
99
// Allow X11 apps to run inside the container
1010
"DISPLAY": "${localEnv:DISPLAY}",
11-
// We put venv on a different volume to cache so have to copy
12-
"UV_LINK_MODE": "copy",
1311
// Do the equivalent of "activate" the venv so we don't have to "uv run" everything
1412
"PATH": "/workspaces/${localWorkspaceFolderBasename}/.venv/bin:${containerEnv:PATH}"
1513
},

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
FROM ghcr.io/diamondlightsource/ubuntu-devcontainer:noble AS developer
44

55
# Add any system dependencies for the developer/build environment here
6-
RUN apt-get update && apt-get install -y --no-install-recommends \
6+
RUN apt-get update -y && apt-get install -y --no-install-recommends \
77
graphviz \
88
&& apt-get dist-clean

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
# python-copier-template
88

9-
Diamond's opinionated [copier](https://copier.readthedocs.io) template for pure Python projects managed by pip. It can be optionally used to:
9+
Diamond's opinionated [copier](https://copier.readthedocs.io) template for pure Python projects. It can be optionally used to:
1010

1111
- Create new projects from
1212
- Update existing projects in line with it
@@ -21,7 +21,7 @@ Releases | <https://github.com/DiamondLightSource/python-copier-template/
2121
It integrates the following tools:
2222

2323
- [setuptools](https://setuptools.pypa.io) and [setuptools-scm](https://setuptools-scm.readthedocs.io) for packaging
24-
- [pip](https://pip.pypa.io) to manage installation
24+
- [uv](https://docs.astral.sh/uv/) to manage installation and project lockfile
2525
- [pytest](https://docs.pytest.org) for code testing and coverage
2626
- [pre-commit](https://pre-commit.com) to run linting and formatting such as [ruff](https://docs.astral.sh/ruff)
2727
- [pyright](https://microsoft.github.io/pyright) or [mypy](https://www.mypy-lang.org) for static type checking

template/Dockerfile.jinja

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
FROM ghcr.io/diamondlightsource/ubuntu-devcontainer:noble AS developer
44

55
# Add any system dependencies for the developer/build environment here
6-
RUN apt-get update && apt-get install -y --no-install-recommends \
6+
RUN apt-get update -y && apt-get install -y --no-install-recommends \
77
graphviz \
88
&& apt-get dist-clean{% if docker %}
99

@@ -16,6 +16,9 @@ WORKDIR /app
1616
COPY . /app
1717
RUN chmod o+wrX .
1818

19+
# Tell uv sync to install python in a known location so we can copy it out later
20+
ENV UV_PYTHON_INSTALL_DIR=/python
21+
1922
# Sync the project without its dev dependencies
2023
RUN --mount=type=cache,target=/root/.cache/uv \
2124
uv sync --locked --no-editable --no-dev
@@ -36,6 +39,7 @@ RUN sed -i 's/files/ldap files/g' /etc/nsswitch.conf
3639
# Make editable and debuggable
3740
RUN uv pip install debugpy
3841
RUN uv pip install -e .
42+
ENV PATH=/app/.venv/bin:$PATH
3943

4044
# Alternate entrypoint to allow devcontainer to attach
4145
ENTRYPOINT [ "/bin/bash", "-c", "--" ]
@@ -46,10 +50,13 @@ CMD [ "while true; do sleep 30; done;" ]
4650
FROM ubuntu:noble AS runtime
4751

4852
# Add apt-get system dependecies for runtime here if needed
49-
# RUN apt-get update && apt-get install -y --no-install-recommends \
53+
# RUN apt-get update -y && apt-get install -y --no-install-recommends \
5054
# some-library \
5155
# && apt-get dist-clean
5256

57+
# Copy the python installation from the build stage
58+
COPY --from=build /python /python
59+
5360
# Copy the environment, but not the source code
5461
COPY --from=build /app/.venv /app/.venv
5562
ENV PATH=/app/.venv/bin:$PATH

0 commit comments

Comments
 (0)