Skip to content

Commit 3b386b6

Browse files
authored
feat: Publish container images to GitHub ghcr.io (#473)
* ghcr * fix name * ghcr * ghcr * ghcr * ghcr * ghcr * ghcr update action * ghcr update action * ghcr update action * ghcr update action * ghcr update action * ghcr update action * ghcr classic * ghcr classic * ghcr: better naming and tidy up * ghcr classic fix chmod * tidy up * tidy up * if-no-files-found: error
1 parent b37033d commit 3b386b6

File tree

1 file changed

+329
-0
lines changed

1 file changed

+329
-0
lines changed

.github/workflows/ghcr.yml

Lines changed: 329 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,329 @@
1+
name: Build and publish to ghcr.io
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
tags:
7+
- 'v[0-9]+.[0-9]+.[0-9]+'
8+
- '[0-9]+.[0-9]+.[0-9]+'
9+
- 'v[0-9]+.[0-9]+.[0-9]+-[0-9]+'
10+
- '[0-9]+.[0-9]+.[0-9]+-[0-9]+'
11+
12+
env:
13+
CARGO_TERM_COLOR: always
14+
LATEST_TAG: latest
15+
16+
permissions:
17+
contents: read
18+
packages: write # So need to set "secrets.GITHUB_TOKEN"
19+
20+
jobs:
21+
22+
# Binary build
23+
build:
24+
name: Build - ${{ matrix.job.name }}
25+
runs-on: ubuntu-24.04
26+
strategy:
27+
fail-fast: false
28+
matrix:
29+
job:
30+
- { name: "amd64", target: "x86_64-unknown-linux-musl" }
31+
- { name: "arm64v8", target: "aarch64-unknown-linux-musl" }
32+
- { name: "armv7", target: "armv7-unknown-linux-musleabihf" }
33+
- { name: "i386", target: "i686-unknown-linux-musl" }
34+
#- { name: "amd64fb", target: "x86_64-unknown-freebsd" }
35+
36+
steps:
37+
- name: Checkout
38+
uses: actions/checkout@v4
39+
40+
- name: Install Rust toolchain
41+
uses: dtolnay/rust-toolchain@v1
42+
with:
43+
toolchain: "1.70.0"
44+
targets: ${{ matrix.job.target }}
45+
components: "rustfmt"
46+
47+
- uses: Swatinem/rust-cache@v2
48+
with:
49+
prefix-key: ${{ matrix.job.os }}
50+
51+
- name: Build
52+
uses: actions-rs/cargo@v1
53+
with:
54+
command: build
55+
args: --release --all-features --target=${{ matrix.job.target }}
56+
use-cross: true
57+
58+
- name: Exec chmod
59+
run: chmod -v a+x target/${{ matrix.job.target }}/release/*
60+
61+
- name: Publish Artifacts
62+
uses: actions/upload-artifact@v4
63+
with:
64+
name: binaries-linux-${{ matrix.job.name }}
65+
path: |
66+
target/${{ matrix.job.target }}/release/hbbr
67+
target/${{ matrix.job.target }}/release/hbbs
68+
target/${{ matrix.job.target }}/release/rustdesk-utils
69+
if-no-files-found: error
70+
71+
# Build and push single-arch Docker images to ghcr.io
72+
create-s6-overlay-images:
73+
name: Docker push - ${{ matrix.job.name }}
74+
needs: build
75+
runs-on: ubuntu-24.04
76+
strategy:
77+
fail-fast: false
78+
matrix:
79+
job:
80+
- { name: "amd64", docker_platform: "linux/amd64", s6_platform: "x86_64" }
81+
- { name: "arm64v8", docker_platform: "linux/arm64", s6_platform: "aarch64" }
82+
- { name: "armv7", docker_platform: "linux/arm/v7", s6_platform: "armhf" }
83+
- { name: "i386", docker_platform: "linux/386", s6_platform: "i686" }
84+
85+
steps:
86+
- name: Checkout
87+
uses: actions/checkout@v4
88+
89+
- name: Download binaries
90+
uses: actions/download-artifact@v4
91+
with:
92+
pattern: binaries-linux-${{ matrix.job.name }}
93+
path: docker/rootfs/usr/bin
94+
merge-multiple: true
95+
96+
- name: Make binaries executable
97+
run: chmod -v a+x docker/rootfs/usr/bin/*
98+
99+
- name: Set up QEMU
100+
uses: docker/setup-qemu-action@v3
101+
102+
- name: Set up Docker Buildx
103+
uses: docker/setup-buildx-action@v3
104+
105+
- name: Log in to GitHub Container Registry
106+
if: github.event_name != 'pull_request'
107+
uses: docker/login-action@v3
108+
with:
109+
registry: ghcr.io
110+
username: ${{ github.actor }}
111+
password: ${{ secrets.GITHUB_TOKEN }}
112+
113+
- name: Extract metadata (tags, labels) for Docker
114+
id: meta
115+
uses: docker/metadata-action@v5
116+
with:
117+
images: ghcr.io/${{ github.repository }}-s6
118+
119+
- name: Get git tag
120+
id: vars
121+
run: |
122+
T=${GITHUB_REF#refs/*/}
123+
M=${T%%.*}
124+
echo "GIT_TAG=$T" >> $GITHUB_ENV
125+
echo "MAJOR_TAG=$M" >> $GITHUB_ENV
126+
127+
- name: Build and push Docker image
128+
uses: docker/build-push-action@v6
129+
with:
130+
context: "./docker"
131+
platforms: ${{ matrix.job.docker_platform }}
132+
push: true
133+
provenance: false
134+
build-args: |
135+
S6_ARCH=${{ matrix.job.s6_platform }}
136+
tags: |
137+
ghcr.io/${{ github.repository }}-s6:${{ env.LATEST_TAG }}-${{ matrix.job.name }}
138+
ghcr.io/${{ github.repository }}-s6:${{ env.GIT_TAG }}-${{ matrix.job.name }}
139+
ghcr.io/${{ github.repository }}-s6:${{ env.MAJOR_TAG }}-${{ matrix.job.name }}
140+
labels: ${{ steps.meta.outputs.labels }}
141+
142+
# Set up minifest and tag for pushed image
143+
create-s6-overlay-images-manifest:
144+
name: Manifest for s6-overlay images
145+
needs: create-s6-overlay-images
146+
runs-on: ubuntu-24.04
147+
148+
steps:
149+
- name: Log in to GitHub Container Registry
150+
if: github.event_name != 'pull_request'
151+
uses: docker/login-action@v3
152+
with:
153+
registry: ghcr.io
154+
username: ${{ github.actor }}
155+
password: ${{ secrets.GITHUB_TOKEN }}
156+
157+
- name: Get git tag
158+
id: vars
159+
run: |
160+
T=${GITHUB_REF#refs/*/}
161+
M=${T%%.*}
162+
echo "GIT_TAG=$T" >> $GITHUB_ENV
163+
echo "MAJOR_TAG=$M" >> $GITHUB_ENV
164+
165+
# Create and push manifest for :ve.rs.ion tag
166+
- name: Create and push manifest (:ve.rs.ion)
167+
uses: Noelware/docker-manifest-action@master
168+
if: github.event_name != 'workflow_dispatch'
169+
with:
170+
base-image: ghcr.io/${{ github.repository }}-s6:${{ env.GIT_TAG }}
171+
extra-images: |
172+
ghcr.io/${{ github.repository }}-s6:${{ env.GIT_TAG }}-amd64,
173+
ghcr.io/${{ github.repository }}-s6:${{ env.GIT_TAG }}-arm64v8,
174+
ghcr.io/${{ github.repository }}-s6:${{ env.GIT_TAG }}-armv7,
175+
ghcr.io/${{ github.repository }}-s6:${{ env.GIT_TAG }}-i386
176+
push: true
177+
178+
# Create and push manifest for :major tag
179+
- name: Create and push manifest (:major)
180+
uses: Noelware/docker-manifest-action@master
181+
with:
182+
base-image: ghcr.io/${{ github.repository }}-s6:${{ env.MAJOR_TAG }}
183+
extra-images: |
184+
ghcr.io/${{ github.repository }}-s6:${{ env.MAJOR_TAG }}-amd64,
185+
ghcr.io/${{ github.repository }}-s6:${{ env.MAJOR_TAG }}-arm64v8,
186+
ghcr.io/${{ github.repository }}-s6:${{ env.MAJOR_TAG }}-armv7,
187+
ghcr.io/${{ github.repository }}-s6:${{ env.MAJOR_TAG }}-i386
188+
push: true
189+
190+
# Create and push manifest for :latest tag
191+
- name: Create and push manifest (:latest)
192+
uses: Noelware/docker-manifest-action@master
193+
with:
194+
base-image: ghcr.io/${{ github.repository }}-s6:${{ env.LATEST_TAG }}
195+
extra-images: |
196+
ghcr.io/${{ github.repository }}-s6:${{ env.LATEST_TAG }}-amd64,
197+
ghcr.io/${{ github.repository }}-s6:${{ env.LATEST_TAG }}-arm64v8,
198+
ghcr.io/${{ github.repository }}-s6:${{ env.LATEST_TAG }}-armv7,
199+
ghcr.io/${{ github.repository }}-s6:${{ env.LATEST_TAG }}-i386
200+
push: true
201+
202+
# Build and push single-arch Docker images to ghcr.io
203+
create-classic-images:
204+
name: Docker push - ${{ matrix.job.name }}
205+
needs: build
206+
runs-on: ubuntu-24.04
207+
strategy:
208+
fail-fast: false
209+
matrix:
210+
job:
211+
- { name: "amd64", docker_platform: "linux/amd64" }
212+
- { name: "arm64v8", docker_platform: "linux/arm64" }
213+
- { name: "armv7", docker_platform: "linux/arm/v7" }
214+
- { name: "i386", docker_platform: "linux/386" }
215+
216+
steps:
217+
- name: Checkout
218+
uses: actions/checkout@v4
219+
220+
- name: Download binaries
221+
uses: actions/download-artifact@v4
222+
with:
223+
pattern: binaries-linux-${{ matrix.job.name }}
224+
path: docker-classic
225+
merge-multiple: true
226+
227+
- name: Make binaries executable
228+
run: chmod -v a+x docker-classic/*
229+
230+
- name: Set up QEMU
231+
uses: docker/setup-qemu-action@v3
232+
233+
- name: Set up Docker Buildx
234+
uses: docker/setup-buildx-action@v3
235+
236+
- name: Log in to GitHub Container Registry
237+
if: github.event_name != 'pull_request'
238+
uses: docker/login-action@v3
239+
with:
240+
registry: ghcr.io
241+
username: ${{ github.actor }}
242+
password: ${{ secrets.GITHUB_TOKEN }}
243+
244+
- name: Extract metadata (tags, labels) for Docker
245+
id: meta
246+
uses: docker/metadata-action@v5
247+
with:
248+
images: ghcr.io/${{ github.repository }}
249+
250+
- name: Get git tag
251+
id: vars
252+
run: |
253+
T=${GITHUB_REF#refs/*/}
254+
M=${T%%.*}
255+
echo "GIT_TAG=$T" >> $GITHUB_ENV
256+
echo "MAJOR_TAG=$M" >> $GITHUB_ENV
257+
258+
- name: Build and push Docker image
259+
uses: docker/build-push-action@v6
260+
with:
261+
context: "./docker-classic"
262+
platforms: ${{ matrix.job.docker_platform }}
263+
push: true
264+
provenance: false
265+
tags: |
266+
ghcr.io/${{ github.repository }}:${{ env.LATEST_TAG }}-${{ matrix.job.name }}
267+
ghcr.io/${{ github.repository }}:${{ env.GIT_TAG }}-${{ matrix.job.name }}
268+
ghcr.io/${{ github.repository }}:${{ env.MAJOR_TAG }}-${{ matrix.job.name }}
269+
labels: ${{ steps.meta.outputs.labels }}
270+
271+
# Set up minifest and tag for pushed image
272+
create-classic-images-manifest:
273+
name: Manifest for classic images
274+
needs: create-classic-images
275+
runs-on: ubuntu-24.04
276+
277+
steps:
278+
- name: Log in to GitHub Container Registry
279+
if: github.event_name != 'pull_request'
280+
uses: docker/login-action@v3
281+
with:
282+
registry: ghcr.io
283+
username: ${{ github.actor }}
284+
password: ${{ secrets.GITHUB_TOKEN }}
285+
286+
- name: Get git tag
287+
id: vars
288+
run: |
289+
T=${GITHUB_REF#refs/*/}
290+
M=${T%%.*}
291+
echo "GIT_TAG=$T" >> $GITHUB_ENV
292+
echo "MAJOR_TAG=$M" >> $GITHUB_ENV
293+
294+
# Create and push manifest for :ve.rs.ion tag
295+
- name: Create and push manifest (:ve.rs.ion)
296+
uses: Noelware/docker-manifest-action@master
297+
if: github.event_name != 'workflow_dispatch'
298+
with:
299+
base-image: ghcr.io/${{ github.repository }}:${{ env.GIT_TAG }}
300+
extra-images: |
301+
ghcr.io/${{ github.repository }}:${{ env.GIT_TAG }}-amd64,
302+
ghcr.io/${{ github.repository }}:${{ env.GIT_TAG }}-arm64v8,
303+
ghcr.io/${{ github.repository }}:${{ env.GIT_TAG }}-armv7,
304+
ghcr.io/${{ github.repository }}:${{ env.GIT_TAG }}-i386
305+
push: true
306+
307+
# Create and push manifest for :major tag
308+
- name: Create and push manifest (:major)
309+
uses: Noelware/docker-manifest-action@master
310+
with:
311+
base-image: ghcr.io/${{ github.repository }}:${{ env.MAJOR_TAG }}
312+
extra-images: |
313+
ghcr.io/${{ github.repository }}:${{ env.MAJOR_TAG }}-amd64,
314+
ghcr.io/${{ github.repository }}:${{ env.MAJOR_TAG }}-arm64v8,
315+
ghcr.io/${{ github.repository }}:${{ env.MAJOR_TAG }}-armv7,
316+
ghcr.io/${{ github.repository }}:${{ env.MAJOR_TAG }}-i386
317+
push: true
318+
319+
# Create and push manifest for :latest tag
320+
- name: Create and push manifest (:latest)
321+
uses: Noelware/docker-manifest-action@master
322+
with:
323+
base-image: ghcr.io/${{ github.repository }}:${{ env.LATEST_TAG }}
324+
extra-images: |
325+
ghcr.io/${{ github.repository }}:${{ env.LATEST_TAG }}-amd64,
326+
ghcr.io/${{ github.repository }}:${{ env.LATEST_TAG }}-arm64v8,
327+
ghcr.io/${{ github.repository }}:${{ env.LATEST_TAG }}-armv7,
328+
ghcr.io/${{ github.repository }}:${{ env.LATEST_TAG }}-i386
329+
push: true

0 commit comments

Comments
 (0)