Skip to content

Commit fe1378b

Browse files
committed
Add GitHub Actions workflow for building and pushing Docker images to GHCR
1 parent ec3d0dc commit fe1378b

1 file changed

Lines changed: 110 additions & 0 deletions

File tree

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
name: Build and Push to GHCR
2+
3+
on:
4+
push:
5+
branches: [ "master" ]
6+
paths:
7+
- 'Dockerfile'
8+
- '.dockerignore'
9+
- 'cpp2rust-*.sh'
10+
- 'cmake/**'
11+
- 'cpp2rust/**'
12+
- 'rules/**'
13+
- 'libcc2rs/**'
14+
- 'libcc2rs-macros/**'
15+
- 'libc-dep/**'
16+
- 'rule-preprocessor/**'
17+
- '.github/workflows/build-and-push.yml'
18+
workflow_dispatch:
19+
20+
env:
21+
REGISTRY: ghcr.io
22+
IMAGE_NAME: ${{ github.repository }}
23+
24+
jobs:
25+
build:
26+
strategy:
27+
matrix:
28+
include:
29+
- platform: linux/amd64
30+
runner: ubuntu-latest
31+
- platform: linux/arm64
32+
runner: ubuntu-24.04-arm
33+
34+
runs-on: ${{ matrix.runner }}
35+
permissions:
36+
contents: read
37+
packages: write
38+
39+
steps:
40+
- name: Checkout repository
41+
uses: actions/checkout@v7
42+
43+
- name: Set up Docker Buildx
44+
uses: docker/setup-buildx-action@v4
45+
46+
- name: Log in to GHCR
47+
uses: docker/login-action@v4
48+
with:
49+
registry: ${{ env.REGISTRY }}
50+
username: ${{ github.actor }}
51+
password: ${{ secrets.GITHUB_TOKEN }}
52+
53+
- name: Extract metadata
54+
id: meta
55+
uses: docker/metadata-action@v6
56+
with:
57+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
58+
59+
- name: Build and push by digest
60+
id: build
61+
uses: docker/build-push-action@v7
62+
with:
63+
context: .
64+
file: ./Dockerfile
65+
platforms: ${{ matrix.platform }}
66+
labels: ${{ steps.meta.outputs.labels }}
67+
outputs: type=image,name=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=true
68+
69+
- name: Export digest
70+
run: |
71+
mkdir -p /tmp/digests
72+
digest="${{ steps.build.outputs.digest }}"
73+
touch "/tmp/digests/${digest#sha256:}"
74+
75+
- name: Upload digest
76+
uses: actions/upload-artifact@v7
77+
with:
78+
name: digests-${{ strategy.job-index }}
79+
path: /tmp/digests/*
80+
if-no-files-found: error
81+
retention-days: 1
82+
83+
merge:
84+
runs-on: ubuntu-latest
85+
needs: build
86+
permissions:
87+
packages: write
88+
steps:
89+
- name: Download digests
90+
uses: actions/download-artifact@v8
91+
with:
92+
path: /tmp/digests
93+
pattern: digests-*
94+
merge-multiple: true
95+
96+
- name: Set up Docker Buildx
97+
uses: docker/setup-buildx-action@v4
98+
99+
- name: Log in to GHCR
100+
uses: docker/login-action@v4
101+
with:
102+
registry: ${{ env.REGISTRY }}
103+
username: ${{ github.actor }}
104+
password: ${{ secrets.GITHUB_TOKEN }}
105+
106+
- name: Create manifest list and push
107+
working-directory: /tmp/digests
108+
run: |
109+
docker buildx imagetools create -t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest \
110+
$(printf '${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@sha256:%s ' *)

0 commit comments

Comments
 (0)