Commit b8e00b980dd66235c931a9b0e055a93e81559ee3

Edward Thomson 2019-11-23T21:17:15

ci: cache docker layers Our docker builds are getting expensive, let's cache some of this.

diff --git a/azure-pipelines/docker.yml b/azure-pipelines/docker.yml
index dea1ce5..0e1988c 100644
--- a/azure-pipelines/docker.yml
+++ b/azure-pipelines/docker.yml
@@ -4,9 +4,19 @@ steps:
   - script: docker run --rm --privileged multiarch/qemu-user-static:register --reset
     displayName: 'Register Docker QEMU'
 
+- task: cache@2
+  displayName: Cache Docker layers
+  inputs:
+    key: docker
+    path: /tmp/dockercache
+- script: |
+    if [ -f /tmp/dockercache/${{parameters.docker.image}}.tar ]; then docker load < /tmp/dockercache/${{parameters.docker.image}}.tar; fi
+  displayName: 'Load Docker cache'
 - script: |
     cd $(Build.SourcesDirectory)/azure-pipelines/docker
     docker build -t libgit2/${{parameters.docker.image}} --build-arg BASE=${{parameters.docker.base}} -f ${{parameters.docker.image}} .
+    if [ ! -d /tmp/dockercache ]; then mkdir /tmp/dockercache; fi
+    docker save libgit2/${{parameters.docker.image}} $(docker history -q libgit2/${{parameters.docker.image}} | grep -v '<missing>') > /tmp/dockercache/${{parameters.docker.image}}.tar
   displayName: 'Build Docker image'
 - task: docker@0
   displayName: Build