Cache docker image
@@ -17,8 +17,32 @@ jobs:
with:
submodules: 'true'
- - name: Build devcontainer image
- run: docker build --tag devcontainer:1.0 .devcontainer
+ - name: Docker cache
+ id: docker-cache
+ uses: actions/cache@v2
+ with:
+ path: docker-cache
+ key: ${{ runner.os }}-${{ hashFiles('.devcontainer/**') }}
+
+ - name: Build devcontainer image (uncached)
+ if: steps.docker-cache.outputs.cache-hit != 'true'
+ # If no cache-hit we will rebuild the image from scratch with buildx, which
+ # allows us to output a cache for reuse later.
+ #
+ # We output the cache to a new folder and then remove the old cache and copy the new one there
+ # so that the cache size does not keep growing.
+ run: |
+ mkdir -p docker-cache docker-cache-new
+ docker buildx create --use
+ docker buildx build --tag devcontainer:1.0 --cache-from=type=local,src=docker-cache --cache-to=type=local,dest=docker-cache-new --load .devcontainer
+ rm -rf docker-cache && mv docker-cache-new docker-cache
+
+ - name: Build devcontainer image (cached)
+ if: steps.docker-cache.outputs.cache-hit == 'true'
+ # If we have a cache hit we can instruct docker to load from the cache.
+ # We do not write to the cache as we had a hit, and it is very slow.
+ run: |
+ docker buildx build --tag devcontainer:1.0 --cache-from=type=local,src=docker-cache --load .devcontainer
- name: Run CI tasks
run: docker run -w /workspace -v $GITHUB_WORKSPACE:/workspace -e AZURE_TENANT_ID -e AZURE_CLIENT_ID -e AZURE_CLIENT_SECRET -e AZURE_SUBSCRIPTION_ID devcontainer:1.0 task ci
