1+ name : Publish to ghcr
2+
3+ # This workflow is a modification of a example.
4+ # @ see: https://docs.docker.com/build/ci/github-actions/multi-platform/#distribute-build-across-multiple-runners
5+
6+ on :
7+ push :
8+ branches : ["main"]
9+
10+ env :
11+ # Use docker.io for Docker Hub if empty
12+ REGISTRY_IMAGE : ghcr.io/sourcebot-dev/sourcebot
13+
14+ jobs :
15+ build :
16+ runs-on : ${{ matrix.runs-on}}
17+ environment : oss
18+ permissions :
19+ contents : read
20+ packages : write
21+ # This is used to complete the identity challenge
22+ # with sigstore/fulcio when running outside of PRs.
23+ id-token : write
24+ strategy :
25+ matrix :
26+ platform : [linux/amd64, linux/arm64]
27+ include :
28+ - platform : linux/amd64
29+ runs-on : ubuntu-latest
30+ - platform : linux/arm64
31+ runs-on : ubuntu-24.04-arm
32+
33+ steps :
34+ - name : Prepare
35+ run : |
36+ platform=${{ matrix.platform }}
37+ echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
38+
39+ - name : Checkout repository
40+ uses : actions/checkout@v4
41+ with :
42+ ref : ${{ github.ref_name }}
43+ submodules : " true"
44+
45+ # Extract metadata (tags, labels) for Docker
46+ # https://github.com/docker/metadata-action
47+ - name : Extract Docker metadata
48+ id : meta
49+ uses : docker/metadata-action@v5
50+ with :
51+ images : ${{ env.REGISTRY_IMAGE }}
52+
53+ # Install the cosign tool except on PR
54+ # https://github.com/sigstore/cosign-installer
55+ - name : Install cosign
56+ uses : sigstore/cosign-installer@v3.5.0
57+ with :
58+ cosign-release : " v2.2.4"
59+
60+ - name : Set up Docker Buildx
61+ uses : docker/setup-buildx-action@v3
62+
63+ - name : Login to GitHub Packages Docker Registry
64+ uses : docker/login-action@v3
65+ with :
66+ registry : ghcr.io
67+ username : ${{ github.actor }}
68+ password : ${{ secrets.GITHUB_TOKEN }}
69+
70+ - name : Build Docker image
71+ id : build
72+ uses : docker/build-push-action@v6
73+ with :
74+ context : .
75+ labels : ${{ steps.meta.outputs.labels }}
76+ cache-from : type=gha,scope=${{ env.PLATFORM_PAIR }}
77+ cache-to : type=gha,mode=max,scope=${{ env.PLATFORM_PAIR }}
78+ platforms : ${{ matrix.platform }}
79+ outputs : type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true,annotation.org.opencontainers.image.description=Blazingly fast code search
80+
81+ - name : Export digest
82+ run : |
83+ mkdir -p /tmp/digests
84+ digest="${{ steps.build.outputs.digest }}"
85+ touch "/tmp/digests/${digest#sha256:}"
86+
87+ - name : Upload digest
88+ uses : actions/upload-artifact@v4
89+ with :
90+ name : digests-${{ env.PLATFORM_PAIR }}
91+ path : /tmp/digests/*
92+ if-no-files-found : error
93+ retention-days : 1
94+
95+ # Sign the resulting Docker image digest except on PRs.
96+ # This will only write to the public Rekor transparency log when the Docker
97+ # repository is public to avoid leaking data. If you would like to publish
98+ # transparency data even for private images, pass --force to cosign below.
99+ # https://github.com/sigstore/cosign
100+ - name : Sign the published Docker image
101+ env :
102+ # https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#using-an-intermediate-environment-variable
103+ TAGS : ${{ steps.meta.outputs.tags }}
104+ DIGEST : ${{ steps.build.outputs.digest }}
105+ # This step uses the identity token to provision an ephemeral certificate
106+ # against the sigstore community Fulcio instance.
107+ run : echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST}
108+
109+ merge :
110+ runs-on : ubuntu-latest
111+ permissions :
112+ packages : write
113+ needs :
114+ - build
115+ steps :
116+ - name : Download digests
117+ uses : actions/download-artifact@v4
118+ with :
119+ path : /tmp/digests
120+ pattern : digests-*
121+ merge-multiple : true
122+
123+ - name : Set up Docker Buildx
124+ uses : docker/setup-buildx-action@v3
125+
126+ - name : Extract Docker metadata
127+ id : meta
128+ uses : docker/metadata-action@v5
129+ with :
130+ images : ${{ env.REGISTRY_IMAGE }}
131+
132+ - name : Login to GitHub Packages Docker Registry
133+ uses : docker/login-action@v3
134+ with :
135+ registry : ghcr.io
136+ username : ${{ github.actor }}
137+ password : ${{ secrets.GITHUB_TOKEN }}
138+
139+ - name : Create manifest list and push
140+ working-directory : /tmp/digests
141+ run : |
142+ docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
143+ $(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *)
144+
145+ - name : Inspect image
146+ run : |
147+ docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }}
0 commit comments