We’re currently building a Docker image every workflow run. This takes 10-15 minutes. It’s faster to fetch the same image from Docker hub, but nicer to only be dependent on the Dockerfile in the repo. Is there any way to speed up subsequent builds by doing some kind of Docker build caching?
We’re adding caching. It will arrive by mid-November.
For those who found this Subject looking for a way to use cache in Workflows, you can use this action that does just what @nergnezor mentioned: fetches the layers from a Registry and use (multiple) –cache-from to hint docker where to look for cache.
The action supports multi-stage builds as it pushes each stage to a registry, and pull them when a new build is triggered.
This is a minimal example:
- uses: whoan/docker-build-with-cache-action@v1
with:
username: whoan
password: "${{ secrets.DOCKER_PASSWORD }}"
image_name: whoan/node
Using buildx and ghaction-docker-buildx does not require to set cache or to push to registry:
name:buildxon:
pull\_request:
branches:masterpush:
branches:mastertags:
jobs:
buildx:
runs-on:ubuntu-lateststeps:
-
name:Checkoutuses:actions/checkout@v1 -
name:Set up Docker Buildxid:buildxuses:crazy-max/ghaction-docker-buildx@masterwith:
version:latest -
name:Available platformsrun:echo ${{ steps.buildx.outputs.platforms }} -
name:Run Buildxrun:| docker buildx build \ --platform linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/ppc64le,linux/s390x \ --output "type=image,push=false" \ --file ./test/Dockerfile ./test
Live example: https://github.com/crazy-max/swarm-cronjob/runs/231926567
@ethomson Given https://github.com/actions/cache is on, does it apply to the original question? (Caching docker layers)
Or is something different is coming for Docker image layer caching?
Also looking for an answer to this; it is mid-November
It’s already mid of Feb 2020, any update on this?
How is it cached then?
Hey everyone, I found a solution that works pretty well. Unfortunately doesn’t FULLY cache, so you have to do some data transfer but seems to get the job done.
I run docker save
to create a compressed image, save it as an artifact, and then load it in the next step. Not sure how this will scale but it will work for some use-cases. Still would be much better to have the ability to keep the same docker registry between steps
jobs:
create-docker-image:
runs-on: ubuntu-latest
steps:
-uses: actions/checkout@master
-name: build image
run: docker build -t foo:bar .
-name: save image
run: docker save -o ./image foo:bar
-name: Upload image
uses: actions/upload-artifact@v1
with:
name: airflow-image
path: image
pull-image:
needs: create-docker-image
runs-on: ubuntu-latest
steps:
-name: Download image
uses: actions/download-artifact@v1
with:
name: airflow-image
-name: load image
run: docker load -i ./airflow-image/image
-name: run image
run: docker run foo:bar
Its mid-May 2020. This still doesn’t exist and no news has been shared about when it might.
@ethomson Hi, im wondering if maybe theres an update on this yet? Built in docker layer caching would be great
How exactly to use it with Docker layers? Should I configure a step to cache/restore the dir /var/lib/docker/overlay2
? I prefer a general solution, without custom actions. Thanks.