Skip to content

Commit b3e91e0

Browse files
committed
Add dockerio mirror
1 parent 031822e commit b3e91e0

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed

.github/workflows/dockerio.yaml

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Mirror Docker Hub images to GHCR
2+
# Uses crane for efficient registry-to-registry copies (no docker pull/push needed)
3+
# Docs: https://github.com/google/go-containerregistry/blob/main/cmd/crane/doc/crane_copy.md
4+
5+
name: Mirror Docker Images to GHCR
6+
7+
on:
8+
workflow_dispatch:
9+
inputs:
10+
image:
11+
description: 'Docker Hub image (e.g., nginx, library/alpine)'
12+
required: true
13+
type: string
14+
schedule:
15+
- cron: '0 0 * * *' # Daily at midnight UTC
16+
17+
env:
18+
# Define images to mirror (format: source -> mirrored to ghcr.io/$REPO/docker.io/source)
19+
IMAGES: |
20+
netbirdio/management
21+
netbirdio/dashboard
22+
netbirdio/relay
23+
netbirdio/signal
24+
25+
jobs:
26+
# Build matrix of images to mirror
27+
prepare:
28+
runs-on: ubuntu-latest
29+
outputs:
30+
matrix: ${{ steps.set-matrix.outputs.matrix }}
31+
steps:
32+
- id: set-matrix
33+
run: |
34+
if [ -n "${{ inputs.image }}" ]; then
35+
# Manual trigger - single image
36+
echo "matrix=[\"${{ inputs.image }}\"]" >> $GITHUB_OUTPUT
37+
else
38+
# Scheduled - all images from IMAGES env
39+
MATRIX=$(echo "$IMAGES" | grep -v '^$' | jq -R -s -c 'split("\n") | map(select(length > 0))')
40+
echo "matrix=$MATRIX" >> $GITHUB_OUTPUT
41+
fi
42+
43+
mirror:
44+
needs: prepare
45+
runs-on: ubuntu-latest
46+
permissions:
47+
packages: write
48+
strategy:
49+
fail-fast: false
50+
max-parallel: 4 # Parallel image mirroring
51+
matrix:
52+
image: ${{ fromJson(needs.prepare.outputs.matrix) }}
53+
steps:
54+
- name: Setup crane
55+
uses: imjasonh/setup-crane@v0.4
56+
57+
- name: Login to GHCR
58+
run: crane auth login ghcr.io -u ${{ github.actor }} -p ${{ secrets.GITHUB_TOKEN }}
59+
60+
- name: Login to Docker Hub (optional, increases rate limits)
61+
if: ${{ secrets.DOCKERHUB_TOKEN != '' }}
62+
env:
63+
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
64+
run: crane auth login docker.io -u ${{ secrets.DOCKERHUB_USERNAME }} -p $DOCKERHUB_TOKEN
65+
continue-on-error: true
66+
67+
- name: Mirror ${{ matrix.image }}
68+
run: |
69+
SOURCE="docker.io/${{ matrix.image }}"
70+
DEST="ghcr.io/${{ github.repository }}/docker.io/${{ matrix.image }}"
71+
72+
echo "Mirroring: $SOURCE -> $DEST"
73+
74+
# Copy all tags with parallel jobs, overwriting existing tags
75+
# -a: all tags, -j: parallel jobs
76+
crane copy "$SOURCE" "$DEST" --all-tags -j 4

0 commit comments

Comments
 (0)