-
Notifications
You must be signed in to change notification settings - Fork 247
104 lines (95 loc) · 3.45 KB
/
clone-docker-image-action.yaml
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
---
name: Reusable workflow to clone a Docker image from one registry to another
on:
workflow_call:
inputs:
source_image:
description: The source image to clone
required: true
type: string
source_registry:
description: The source registry
required: true
type: string
target_image:
description: The target image to clone
required: true
type: string
target_registry:
description: 'The target registry'
required: true
type: string
# platforms:
# description: 'The platforms to clone'
# required: false
# type: string
# default: '["linux/arm64", "linux/amd64"]'
tags:
description: 'The tags to apply to the target image'
required: false
type: string
secrets:
source_registry_token:
description: The Github token or similar to authenticate with for the registry.
required: true
target_registry_token:
description: The Github token or similar to authenticate with for the registry.
required: true
source_registry_username:
description: The source registry username
required: true
target_registry_username:
description: The target registry username
required: true
jobs:
create-tags:
runs-on: ubuntu-latest
outputs:
tags: ${{ steps.tags-converter.outputs.TAGS }}
steps:
- name: determine tags
id: display-tags
run: |
echo "input tags: ${{ inputs.tags }}"
- name: Convert tags to JSON array
id: tags-converter
run: |
# Get the line-separated list of tags
TAGS="${{ inputs.tags }}"
# Initialize an empty array
JSON_TAGS="["
# Loop through each tag and append to the JSON array
while read -r tag; do
JSON_TAGS+="\"$tag\","
done <<< "$TAGS"
# Remove the trailing comma and close the array
JSON_TAGS="${JSON_TAGS%,}]"
# print the JSON array
echo "TAGS=$JSON_TAGS"
# Output the JSON array
echo "TAGS=$JSON_TAGS" >> $GITHUB_OUTPUT
push-image:
needs:
- create-tags
strategy:
matrix:
image_tags: ${{fromJson(needs.create-tags.outputs.tags)}}
runs-on: ubuntu-latest
steps:
- name: Promote container images from ${{ inputs.source_registry }} to ${{ inputs.target_registry }}
run: |
echo "Promoting $SOURCE_IMAGE to $RELEASE_IMAGE"
docker run --rm \
quay.io/skopeo/stable:latest \
copy \
--all \
--retry-times 10 \
--dest-creds "$RELEASE_CREDS" \
--src-creds "$SOURCE_CREDS" \
"docker://$SOURCE_IMAGE" \
"docker://$RELEASE_IMAGE"
env:
SOURCE_IMAGE: "${{ inputs.source_registry }}/${{ inputs.source_image }}"
RELEASE_IMAGE: "${{ inputs.target_registry }}/${{ inputs.target_image }}:${{ matrix.image_tags }}"
RELEASE_CREDS: ${{ secrets.target_registry_username }}:${{ secrets.target_registry_token }}
SOURCE_CREDS: ${{ secrets.source_registry_username }}:${{ secrets.source_registry_token }}