-
Notifications
You must be signed in to change notification settings - Fork 0
63 lines (55 loc) · 2.01 KB
/
Copy pathsync-image.yml
File metadata and controls
63 lines (55 loc) · 2.01 KB
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
name: sync-image
permissions:
contents: read
pull-requests: read
actions: read
defaults:
run:
shell: bash
on:
workflow_dispatch:
inputs:
# Example:
# Input: "ghcr.io/owner/image:tag docker.io/owner/image2:tag>abc:tag"
# Result:
# - Sync "ghcr.io/owner/image:tag" to "docker.io/owner/mirrored-image:tag"
# - Sync "docker.io/owner/image2:tag" to "docker.io/owner/mirrored-abc:tag"
images:
description: 'List of images to sync, inform of "src-registry/src-image src-registry/src-image-2>dst-image-2 ...".'
required: true
type: string
env:
INPUT_PASSWORD: ${{ secrets.CI_DOCKERHUB_PASSWORD }}
jobs:
sync:
runs-on: macos-14
steps:
- name: Prepare Env
env:
INPUT_REPOSITORY_OWNER: ${{ github.repository_owner }}
run: |
INPUT_REPOSITORY_OWNER=$(echo "${INPUT_REPOSITORY_OWNER}" | tr '[:upper:]' '[:lower:]')
echo "INPUT_USERNAME=${INPUT_REPOSITORY_OWNER}" >> $GITHUB_ENV
echo "DEBUG: INPUT_USERNAME=${INPUT_USERNAME}"
- name: Sync
run: |
#!/usr/bin/env bash
echo "Checking for skopeo..."
if ! command -v skopeo &> /dev/null; then
brew install skopeo
fi
echo "Logging in to Docker Hub..."
skopeo login docker.io -u ${{ env.INPUT_USERNAME }} -p ${{ env.INPUT_PASSWORD }}
echo "Starting image sync..."
IFS=' ' read -ra IMAGES <<< "${{ inputs.images }}"
for image in "${IMAGES[@]}"; do
src="$(echo $image | cut -d '>' -f 1)"
dst="$(echo $image | cut -d '>' -f 2)"
if [[ "${src}" == "${dst}" ]]; then
dst="${src##*/}"
fi
dst="${dst#*/}" # Remove registry part if exists
dst="docker.io/${{ env.INPUT_USERNAME }}/mirrored-${dst}"
echo "Syncing ${src} to ${dst}"
skopeo copy docker://${src} docker://${dst} --all --retry-delay 5s --retry-times 10
done