I'm using github actions to build a docker image. I cache the docker layers (which works well) but sometimes layers aren't reused (not sure why! i'm following best practices but ignore that aside) and I'm using a fallback pip cache to speed up the build.
Dockerfile is pretty simple:
# syntax=docker/dockerfile:1.2
FROM python:3.10-slim
RUN python -m pip install --upgrade pip && pip cache dir
COPY requirements.txt ./
RUN --mount=type=cache,target=/root/.cache/pip/ pip install -r requirements.txt
I'm using the --mount flag from syntax 1.2 which "allows the build container to cache directories for compilers and package managers"
Github actions cache (which i'd like to mount on the build container):
- name: Cache pip
uses: actions/cache@v3
with:
path: /root/.cache/pip
key: pip-{{ hashFiles('requirements*.txt') }}
and docker build
- name: Build and push
uses: docker/build-push-action@v2
with:
cache-from: type=gha
cache-to: type=gha,mode=max
How do I mount the pip cache into the docker builder container?
Right now the cache is empty using this command in the dockerfile:
RUN --mount=type=cache,target=/root/.cache/pip/ pip cache info && ls /root/.cache/pip
outputs:
19 RUN --mount=type=cache,target=/root/.cache/pip/ pip cache info && ls /root/.cache/pip
#19 0.387 Package index page cache location: /root/.cache/pip/http
#19 0.387 Package index page cache size: 0 bytes
#19 0.387 Number of HTTP files: 0
#19 0.387 Wheels location: /root/.cache/pip/wheels
#19 0.387 Wheels size: 0 bytes
#19 0.387 Number of wheels: 0
#19 DONE 0.4s