Skip to content

Commit 0746bd5

Browse files
author
Frank Bell
committed
ci: reattempt docker image caching
1 parent 2eba5e2 commit 0746bd5

File tree

3 files changed

+51
-40
lines changed

3 files changed

+51
-40
lines changed

.github/init-image/action.yaml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: init image
2+
description: |
3+
This action initializes a Docker image within a runner.
4+
5+
inputs:
6+
image:
7+
description: The image to be initialized
8+
# Image can be edited at https://github.com/use-ink/docker-images
9+
default: evilrobot/useink:pr-4-stable
10+
11+
runs:
12+
using: composite
13+
14+
steps:
15+
- name: Get latest image digest
16+
id: image-digest
17+
shell: bash
18+
run: |
19+
DIGEST=$(docker manifest inspect ${{ inputs.image }} | jq -r '.config.digest')
20+
echo "digest=$DIGEST" >> $GITHUB_OUTPUT
21+
22+
- name: Cache image
23+
id: cache-image
24+
uses: actions/cache@v4
25+
with:
26+
path: ./docker-cache
27+
# Include digest in the cache key to detect updates
28+
key: docker-images-${{ runner.os }}-${{ inputs.image }}
29+
30+
- name: Load image from cache
31+
if: steps.cache-image.outputs.cache-hit == 'true'
32+
shell: bash
33+
run: |
34+
mkdir -p ./docker-cache
35+
docker load < ./docker-cache/image.tar
36+
37+
- name: Pull and cache image
38+
if: steps.cache-image.outputs.cache-hit != 'true'
39+
shell: bash
40+
run: |
41+
mkdir -p ./docker-cache
42+
docker pull ${{ inputs.image }}
43+
docker save ${{ inputs.image }} > ./docker-cache/image.tar

.github/run-container-command/action.yaml

Lines changed: 2 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: run container command
22
description: |
3-
This action runs a specified command within a container using an optionally specified image.
3+
This action runs a specified command within a container (using the `useink/ci` image).
44
55
inputs:
66
command:
@@ -14,46 +14,8 @@ runs:
1414
using: composite
1515

1616
steps:
17-
18-
- name: Set image
19-
id: set-image
20-
shell: bash
21-
# Image can be edited at https://github.com/use-ink/docker-images
22-
# NOTE: also needs to be manually updated within the `uses` property of the 'Run command in container' step below
23-
# due to being unable to use env, steps context in setting that property value.
24-
run: echo "IMAGE=evilrobot/useink:pr-4-stable" >> "${GITHUB_OUTPUT}"
25-
26-
- name: Get latest image digest
27-
id: image-digest
28-
shell: bash
29-
run: |
30-
DIGEST=$(docker manifest inspect ${{ steps.set-image.outputs.IMAGE }} | jq -r '.config.digest')
31-
echo "digest=$DIGEST" >> $GITHUB_OUTPUT
32-
33-
- name: Cache image
34-
id: cache-docker
35-
uses: actions/cache@v4
36-
with:
37-
path: ./docker-cache
38-
# Include digest in the cache key to detect updates
39-
key: docker-images-${{ runner.os }}-${{ steps.image-digest.outputs.digest }}
40-
41-
- name: Load image from cache
42-
if: steps.cache-docker.outputs.cache-hit == 'true'
43-
shell: bash
44-
run: |
45-
mkdir -p ./docker-cache
46-
docker load < ./docker-cache/image.tar
47-
48-
- name: Pull and cache image
49-
if: steps.cache-docker.outputs.cache-hit != 'true'
50-
shell: bash
51-
run: |
52-
mkdir -p ./docker-cache
53-
docker pull ${{ steps.set-image.outputs.IMAGE }}
54-
docker save ${{ steps.set-image.outputs.IMAGE }} > ./docker-cache/image.tar
55-
5617
- name: Run command in container
18+
# Image can be edited at https://github.com/use-ink/docker-images
5719
uses: docker://evilrobot/useink:pr-4-stable
5820
env:
5921
CARGO_TARGET_DIR: "/github/workspace/${{ env.CARGO_TARGET_DIR }}"

.github/workflows/ci.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ jobs:
5959
with:
6060
fetch-depth: 1
6161

62+
- name: Initialize image
63+
uses: ./.github/init-image
64+
6265
- name: Output environment information
6366
uses: ./.github/run-container-command
6467
with:
@@ -80,6 +83,9 @@ jobs:
8083
with:
8184
fetch-depth: 1
8285

86+
- name: Initialize image
87+
uses: ./.github/init-image
88+
8389
- name: Check Spelling
8490
uses: ./.github/run-container-command
8591
with:

0 commit comments

Comments
 (0)