Skip to content

Commit 213cff0

Browse files
authored
Merge pull request #252 from Muscraft/mirror-stable
feat: Add mirroring of stable images to ghcr
2 parents a5a1730 + 1c9901c commit 213cff0

File tree

2 files changed

+184
-1
lines changed

2 files changed

+184
-1
lines changed
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
name: Mirror Stable Images to GHCR
2+
3+
on:
4+
workflow_dispatch:
5+
schedule:
6+
# Run daily at midnight UTC
7+
- cron: '0 0 * * *'
8+
9+
jobs:
10+
mirror:
11+
name: DockerHub mirror
12+
runs-on: ubuntu-24.04
13+
if: github.repository == 'rust-lang/docker-rust'
14+
permissions:
15+
contents: read
16+
# Needed to write to the ghcr.io registry
17+
packages: write
18+
strategy:
19+
matrix:
20+
include:
21+
#VERSIONS
22+
- name: alpine3.20
23+
tags: |
24+
1-alpine3.20
25+
1.90-alpine3.20
26+
1.90.0-alpine3.20
27+
alpine3.20
28+
- name: alpine3.21
29+
tags: |
30+
1-alpine3.21
31+
1.90-alpine3.21
32+
1.90.0-alpine3.21
33+
alpine3.21
34+
- name: alpine3.22
35+
tags: |
36+
1-alpine3.22
37+
1.90-alpine3.22
38+
1.90.0-alpine3.22
39+
alpine3.22
40+
1-alpine
41+
1.90-alpine
42+
1.90.0-alpine
43+
alpine
44+
- name: bullseye
45+
tags: |
46+
1-bullseye
47+
1.90-bullseye
48+
1.90.0-bullseye
49+
bullseye
50+
- name: slim-bullseye
51+
tags: |
52+
1-slim-bullseye
53+
1.90-slim-bullseye
54+
1.90.0-slim-bullseye
55+
slim-bullseye
56+
- name: bookworm
57+
tags: |
58+
1-bookworm
59+
1.90-bookworm
60+
1.90.0-bookworm
61+
bookworm
62+
- name: slim-bookworm
63+
tags: |
64+
1-slim-bookworm
65+
1.90-slim-bookworm
66+
1.90.0-slim-bookworm
67+
slim-bookworm
68+
- name: trixie
69+
tags: |
70+
1-trixie
71+
1.90-trixie
72+
1.90.0-trixie
73+
trixie
74+
1
75+
1.90
76+
1.90.0
77+
latest
78+
- name: slim-trixie
79+
tags: |
80+
1-slim-trixie
81+
1.90-slim-trixie
82+
1.90.0-slim-trixie
83+
slim-trixie
84+
1-slim
85+
1.90-slim
86+
1.90.0-slim
87+
slim
88+
#VERSIONS
89+
steps:
90+
- uses: actions/checkout@v5
91+
with:
92+
persist-credentials: false
93+
94+
- name: Login to Docker Hub
95+
uses: docker/login-action@v3
96+
with:
97+
username: rustopsbot
98+
password: ${{ secrets.DOCKER_HUB_TOKEN }}
99+
100+
- name: Login to GHCR
101+
uses: docker/login-action@v3
102+
with:
103+
registry: ghcr.io
104+
username: ${{ github.repository_owner }}
105+
password: ${{ secrets.GITHUB_TOKEN }}
106+
107+
# Download crane in the current directory.
108+
# We use crane because it copies the docker image for all the architectures available in
109+
# DockerHub for the image.
110+
# Learn more about crane at
111+
# https://github.com/google/go-containerregistry/blob/main/cmd/crane/README.md
112+
- name: Download crane
113+
run: |
114+
curl -sL "https://github.com/google/go-containerregistry/releases/download/${VERSION}/go-containerregistry_${OS}_${ARCH}.tar.gz" | tar -xzf -
115+
env:
116+
VERSION: v0.20.2
117+
OS: Linux
118+
ARCH: x86_64
119+
120+
- name: Copy image to GHCR
121+
run: |
122+
./crane copy "docker.io/rust:${{ matrix.name }}" "ghcr.io/${{ github.repository_owner }}/rust:${{ matrix.name }}"
123+
readarray -t TAGS <<< "${{ matrix.tags }}"
124+
for tag in "${TAGS[@]}"; do
125+
./crane tag "ghcr.io/${{ github.repository_owner }}/rust:${{ matrix.name }}" ${tag}
126+
done
127+

x.py

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,61 @@ def update_ci():
150150
rendered = split[0] + marker + versions + marker + split[2]
151151
write_file(file, rendered)
152152

153+
def update_mirror_stable_ci():
154+
file = ".github/workflows/mirror_stable.yml"
155+
config = read_file(file)
156+
157+
versions = ""
158+
for version in alpine_versions:
159+
tags = []
160+
for version_tag in version_tags():
161+
tags.append(f"{version_tag}-alpine{version}")
162+
tags.append(f"alpine{version}")
163+
if version == default_alpine_version:
164+
for version_tag in version_tags():
165+
tags.append(f"{version_tag}-alpine")
166+
tags.append("alpine")
167+
168+
versions += f" - name: alpine{version}\n"
169+
versions += " tags: |\n"
170+
for tag in tags:
171+
versions += f" {tag}\n"
172+
173+
for variant in debian_variants:
174+
tags = []
175+
for version_tag in version_tags():
176+
tags.append(f"{version_tag}-{variant.name}")
177+
tags.append(variant.name)
178+
if variant.name == default_debian_variant:
179+
for version_tag in version_tags():
180+
tags.append(version_tag)
181+
tags.append("latest")
182+
183+
versions += f" - name: {variant.name}\n"
184+
versions += " tags: |\n"
185+
for tag in tags:
186+
versions += f" {tag}\n"
187+
188+
tags = []
189+
for version_tag in version_tags():
190+
tags.append(f"{version_tag}-slim-{variant.name}")
191+
tags.append(f"slim-{variant.name}")
192+
if variant.name == default_debian_variant:
193+
for version_tag in version_tags():
194+
tags.append(f"{version_tag}-slim")
195+
tags.append("slim")
196+
197+
versions += f" - name: slim-{variant.name}\n"
198+
versions += " tags: |\n"
199+
for tag in tags:
200+
versions += f" {tag}\n"
201+
202+
marker = "#VERSIONS\n"
203+
split = config.split(marker)
204+
rendered = split[0] + marker + versions + marker + split[2]
205+
write_file(file, rendered)
206+
207+
153208
def update_nightly_ci():
154209
file = ".github/workflows/nightly.yml"
155210
config = read_file(file)
@@ -298,7 +353,8 @@ def usage():
298353
update_debian()
299354
update_alpine()
300355
update_ci()
301-
update_nightly_ci()
356+
update_mirror_stable_ci()
357+
update_nightly_ci()
302358
elif task == "generate-stackbrew-library":
303359
generate_stackbrew_library()
304360
else:

0 commit comments

Comments
 (0)