diff options
author | 2021-03-07 23:22:56 -0800 | |
---|---|---|
committer | 2021-03-07 23:29:23 -0800 | |
commit | 3f474ffc881616e40fa9a23eeb273acf426f1374 (patch) | |
tree | 9eb1b34ac8ad738b6465d2fcb1d2ec1450d7f276 | |
parent | Fix patch for DEBUG value during testing (diff) |
Docker: improve caching & install numpy in container
CI was building the image twice: once with dev dependencies and again
without. Separating the pipenv command into separate layers allows the
second build in CI to take advantage of the cache for the base
dependencies that it will share across both builds.
Install numpy along with the dev dependencies within the container.
Previously it was installed in CI only, but this meant extra work for
those running tests locally.
Install numpy to the correct site.
-rw-r--r-- | .github/workflows/lint-test-build-push.yaml | 7 | ||||
-rw-r--r-- | Dockerfile | 17 |
2 files changed, 15 insertions, 9 deletions
diff --git a/.github/workflows/lint-test-build-push.yaml b/.github/workflows/lint-test-build-push.yaml index a76354b..e86096f 100644 --- a/.github/workflows/lint-test-build-push.yaml +++ b/.github/workflows/lint-test-build-push.yaml @@ -73,6 +73,7 @@ jobs: push: false load: true target: venv + build-args: DEV=1 cache-from: | type=local,src=/tmp/.buildx-cache ghcr.io/python-discord/snekbox-base:latest @@ -85,12 +86,6 @@ jobs: export IMAGE_SUFFIX='-venv:${{ steps.sha_tag.outputs.tag }}' docker-compose up --no-build -d - # One of the unit tests needs to import numpy. - - name: Install dependencies - run: >- - docker exec snekbox_dev /bin/bash -c - 'pipenv install --system --deploy --dev && pip install numpy' - # Required by pre-commit. - name: Install git run: >- @@ -44,13 +44,24 @@ RUN chmod +x /usr/sbin/nsjail # ------------------------------------------------------------------------------ FROM base as venv -ARG DEV COPY Pipfile Pipfile.lock /snekbox/ WORKDIR /snekbox -# Install to the default user site since PIP_USER is set. -RUN pipenv install --deploy --system ${DEV:+--dev} +# Pipenv installs to the default user site since PIP_USER is set. +RUN pipenv install --deploy --system + +# This must come after the first pipenv command! From the docs: +# All RUN instructions following an ARG instruction use the ARG variable +# implicitly (as an environment variable), thus can cause a cache miss. +ARG DEV + +# Install numpy when in dev mode; one of the unit tests needs it. +RUN if [ -n "${DEV}" ]; \ + then \ + pipenv install --deploy --system --dev \ + && PYTHONUSERBASE=/snekbox/user_base pip install numpy~=1.19; \ + fi # At the end to avoid re-installing dependencies when only a config changes. # It's in the venv image because the final image is not used during development. |