Skip to content

Commit

Permalink
Use uv to install deps during docker build (#761)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielhollas authored Jul 8, 2024
1 parent aea6022 commit 2c201f0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docker-build-test-upload.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
# Also, they might have running or stopped containers,
# which are not cleaned up by `docker system prun`
- name: Reset docker state and cleanup artifacts 🗑️
if: ${{ inputs.platform != 'x86_64' }}
if: ${{ startsWith(inputs.runsOn, 'ubuntu') }}
run: |
docker kill $(docker ps --quiet) || true
docker rm $(docker ps --all --quiet) || true
Expand Down
10 changes: 8 additions & 2 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# syntax=docker/dockerfile:1
FROM ghcr.io/astral-sh/uv:0.2.18 as uv
FROM base-image

# Copy whole repo and pre-install the dependencies and app to the tmp folder.
Expand All @@ -8,7 +9,12 @@ COPY --chown=${NB_UID}:${NB_GID} --from=src . ${PREINSTALL_APP_FOLDER}

USER ${NB_USER}

RUN cd ${PREINSTALL_APP_FOLDER} && \
# Using uv to speed up installation, per docs:
# https://github.com/astral-sh/uv/blob/main/docs/guides/docker.md#using-uv-temporarily
# Use the same constraint file as PIP
ENV UV_CONSTRAINT ${PIP_CONSTRAINT}
RUN --mount=from=uv,source=/uv,target=/bin/uv \
cd ${PREINSTALL_APP_FOLDER} && \
# Remove all untracked files and directories. For example the setup lock flag file.
git clean -fx && \
# It is important to install from `aiidalab install` to mimic the exact installation operation as
Expand All @@ -21,7 +27,7 @@ RUN cd ${PREINSTALL_APP_FOLDER} && \
# aiidalab install --yes --python ${CONDA_DIR}/bin/python "quantum-espresso@file://${PREINSTALL_APP_FOLDER}" && \
# However, have to use `pip install` explicitly because `aiidalab install` call `pip install --user` which will install the app to `/home/${NB_USER}/.local`.
# It won't cause issue for docker but for k8s deployment the home folder is not bind mounted to the pod and the dependencies won't be found. (see issue in `jupyter/docker-stacks` https://github.com/jupyter/docker-stacks/issues/815)
pip install . --no-cache-dir && \
uv pip install --system --no-cache . && \
fix-permissions "${CONDA_DIR}" && \
fix-permissions "/home/${NB_USER}"

Expand Down

0 comments on commit 2c201f0

Please sign in to comment.