-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yml
74 lines (65 loc) · 1.99 KB
/
action.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
name: 'Pull Docker image'
description: 'Pull Docker image from registry, or load it from cache.'
inputs:
image:
description: 'Image name'
required: true
cache-directory:
description: 'Directory to store cache in'
required: false
default: '~/.docker-cache'
outputs:
image:
description: 'Image name'
value: ${{ inputs.image }}
runs:
using: composite
steps:
- uses: actions/cache@v4
id: docker-cache
with:
path: ${{ inputs.cache-directory }}
key: ${{ format('{0}{1}-cache-docker-{2}', runner.os, runner.arch, inputs.image) }}
- name: 'Generate image name'
id: hash
env:
IMAGE: ${{ inputs.image }}
shell: bash
#language=bash
run: |
echo "filename=$(echo "$IMAGE" | md5sum | cut -d ' ' -f 1)" >> $GITHUB_OUTPUT
- name: 'Load cached Docker image'
if: steps.docker-cache.outputs.cache-hit == 'true'
env:
CACHE_DIR: ${{ inputs.cache-directory }}
FILENAME: ${{ steps.hash.outputs.filename }}
shell: bash
#language=bash
run: |
docker load -i "$CACHE_DIR/image-$FILENAME.tar"
- name: 'Pull Docker image'
if: steps.docker-cache.outputs.cache-hit != 'true'
env:
IMAGE: ${{ inputs.image }}
shell: bash
#language=bash
run: |
# if not present, pull from registry
EXISTS=$(docker image inspect "$IMAGE" > /dev/null 2>&1 || echo 0)
if [ $EXISTS -eq 0 ]; then
echo "Image not found, pulling from registry"
docker pull "$IMAGE"
else
echo "Image found, skipping pull"
fi
- name: 'Save image to disk'
if: steps.docker-cache.outputs.cache-hit != 'true'
env:
CACHE_DIR: ${{ inputs.cache-directory }}
FILENAME: ${{ steps.hash.outputs.filename }}
IMAGE: ${{ inputs.image }}
shell: bash
#language=bash
run: |
mkdir -p "$CACHE_DIR"
docker save -o "$CACHE_DIR/image-$FILENAME.tar" "$IMAGE"