GH Actions: Add caching for Docker image
authorEdouard Tisserant <edouard.tisserant@gmail.com>
Fri, 20 May 2022 13:59:51 +0200
changeset 55 399397ddd568
parent 54 ef2720b6f78e
child 56 4c7748acc8a0
GH Actions: Add caching for Docker image
.github/workflows/build_bundles.yml
--- a/.github/workflows/build_bundles.yml	Fri May 20 13:40:04 2022 +0200
+++ b/.github/workflows/build_bundles.yml	Fri May 20 13:59:51 2022 +0200
@@ -55,11 +55,26 @@
         canfestival ${{ env.canfestival_revisionid }}
         EOF
 
-    # TODO: cache docker image, find files to hash for a key
-    - name: Create docker image
+    - name: Cache docker image
+      id: cache-docker
+      uses: actions/cache@v3
+      env:
+        cache-name: cache-docker
+      with:
+        path: /tmp/latest.tar
+        key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('beremiz_public_dist/Dockerfile', 'beremiz_public_dist/*.sh') }}
+
+    - if: ${{ steps.cache-docker.outputs.cache-hit == false }}
+      name: Create docker image
       run: |
         cd beremiz_public_dist
         ./build_docker_image.sh
+        docker image save --output="/tmp/latest.tar" beremiz_public_builder
+
+    - if: ${{ steps.cache-docker.outputs.cache-hit != false }}
+      name: Re-use docker image
+      run: |
+        docker image load --input="/tmp/latest.tar" 
 
     - name: Create docker container
       run: |