-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.yml
79 lines (75 loc) · 2.23 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
75
76
77
78
79
name: "Docker Tag Release"
description: "Given an existing image, applies the given tag and updates latest."
inputs:
registry_username:
description: >-
Username for logging in to registry. Normally, set to github.actor.
default: ${{ github.actor }}
registry_token:
description: >-
Token for logging in to registry. Normally, use secrets.GITHUB_TOKEN.
required: true
registry:
description: >-
Registry that hosts these images; by default, ghcr.io.
default: ghcr.io
existing_tag:
description: >-
Existing image and tag to use.
default: ${{ github.sha }}
image:
description: >-
Image to tag, e.g. ghcr.io/organization/image.
required: true
new_tag:
description: -> Tag to apply to image
required: true
wait_time:
description: -> Time to wait between checking whether the image exists
default: 60
max_tries:
description: -> Maximum number of times to check whether the image exists before giving up
default: 10
runs:
using: composite
steps:
- name: Log into container registry
uses: docker/login-action@v3
with:
registry: ${{ inputs.registry }}
username: ${{ inputs.registry_username }}
password: ${{ inputs.registry_token }}
- name: Wait for revision to exist in container registry
env:
EXISTING_TAG: ${{ inputs.existing_tag }}
MAX_TRIES: ${{ inputs.max_tries }}
WAIT_TIME: ${{ inputs.wait_time }}
id: image_wait
shell: bash
run: |
i=1
while [ true ]; do
echo "Checking if $EXISTING_TAG exists; try $i"
if docker manifest inspect $EXISTING_TAG > /dev/null; then
echo $EXISTING_TAG exists
exit 0
elif [ $i -lt $MAX_TRIES ]; then
echo "Waiting $WAIT_TIME seconds"
sleep $WAIT_TIME
i=$((i+1))
else
echo "Image not found; giving up"
exit 1
fi
done
- name: Tag image release in GHCR
env:
EXISTING_TAG: ${{ inputs.existing_tag }}
IMAGE: ${{ inputs.image }}
NEW_TAG: ${{ inputs.new_tag }}
shell: bash
run: |
docker buildx imagetools create \
--tag "$IMAGE":"$NEW_TAG" \
--tag "$IMAGE":latest \
"$EXISTING_TAG"