Skip to content

Commit e61ea63

Browse files
committed
ci: mirror ubuntu:22.04 to ghcr.io
1 parent 5cd16b7 commit e61ea63

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

.github/workflows/ghcr.yml

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Mirror DockerHub images used by the Rust project to ghcr.io.
2+
# Images are available at https://github.com/orgs/rust-lang/packages.
3+
#
4+
# In some CI jobs, we pull images from ghcr.io instead of Docker Hub because
5+
# Docker Hub has a rate limit, while ghcr.io doesn't.
6+
# Those images are pushed to ghcr.io by this job.
7+
#
8+
# Note that authenticating to DockerHub or other registries isn't possible
9+
# for PR jobs, because forks can't access secrets.
10+
# That's why we use ghcr.io: it has no rate limit and it doesn't require authentication.
11+
12+
name: GHCR
13+
14+
on:
15+
schedule:
16+
# Run daily at midnight UTC
17+
- cron: '0 0 * * *'
18+
19+
jobs:
20+
mirror:
21+
name: DockerHub mirror
22+
runs-on: ubuntu-24.04
23+
permissions:
24+
# Needed to write to the ghcr.io registry
25+
packages: write
26+
steps:
27+
- uses: actions/checkout@v4
28+
with:
29+
persist-credentials: false
30+
31+
- name: Log in to registry
32+
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.repository_owner }} --password-stdin
33+
34+
# Download crane in the current directory.
35+
# We use crane because it copies the docker image for all the architectures available in
36+
# DockerHub for the image.
37+
# Learn more about crane at
38+
# https://github.com/google/go-containerregistry/blob/main/cmd/crane/README.md
39+
- name: Download crane
40+
run: |
41+
curl -sL "https://github.com/google/go-containerregistry/releases/download/${VERSION}/go-containerregistry_${OS}_${ARCH}.tar.gz" | tar -xzf -
42+
env:
43+
VERSION: v0.20.2
44+
OS: Linux
45+
ARCH: x86_64
46+
47+
- name: Mirror DockerHub
48+
run: |
49+
# DockerHub image we want to mirror
50+
image="ubuntu:22.04"
51+
52+
# Mirror image from DockerHub to ghcr.io
53+
./crane copy \
54+
docker.io/${image} \
55+
ghcr.io/${{ github.repository_owner }}/${image}
56+
shell: bash

0 commit comments

Comments
 (0)