1- name : Publish to ghcr
2-
3- # This workflow is a modification of a example.
1+ # Internal reusable workflow for building multi-platform Docker images.
2+ #
3+ # This workflow builds Docker images for linux/amd64 and linux/arm64 platforms,
4+ # pushes them by digest to GHCR, signs them with cosign/Sigstore for supply chain
5+ # security, and uploads build artifacts for subsequent manifest creation.
6+ #
47# @ see: https://docs.docker.com/build/ci/github-actions/multi-platform/#distribute-build-across-multiple-runners
58
9+ name : Build Multi-Platform Images
10+
611on :
7- push :
8- branches : ["main"]
9- tags : ["v*.*.*"]
12+ workflow_call :
13+ inputs :
14+ git_ref :
15+ description : " Git ref to checkout"
16+ required : true
17+ type : string
18+ docker_tags :
19+ description : " Docker tags configuration (JSON array or raw tags)"
20+ required : true
21+ type : string
22+ use_app_token :
23+ description : " Whether to use GitHub App token for checkout"
24+ required : false
25+ type : boolean
26+ default : false
27+ secrets :
28+ release_app_id :
29+ description : " GitHub App ID (required if use_app_token is true)"
30+ required : false
31+ release_app_private_key :
32+ description : " GitHub App private key (required if use_app_token is true)"
33+ required : false
1034
1135env :
12- # Use docker.io for Docker Hub if empty
1336 REGISTRY_IMAGE : ghcr.io/sourcebot-dev/sourcebot
1437
1538jobs :
@@ -19,19 +42,27 @@ jobs:
1942 permissions :
2043 contents : read
2144 packages : write
22- # This is used to complete the identity challenge
23- # with sigstore/fulcio when running outside of PRs .
45+ # Required for keyless signing with cosign/Sigstore.
46+ # Allows workflow to obtain OIDC token for ephemeral certificate from Fulcio .
2447 id-token : write
2548 strategy :
2649 matrix :
2750 platform : [linux/amd64, linux/arm64]
2851 include :
2952 - platform : linux/amd64
30- runs-on : blacksmith-4vcpu- ubuntu-2404
53+ runs-on : ubuntu-latest
3154 - platform : linux/arm64
32- runs-on : blacksmith-8vcpu- ubuntu-2204 -arm
55+ runs-on : ubuntu-24.04 -arm
3356
3457 steps :
58+ - name : Generate GitHub App token
59+ if : inputs.use_app_token
60+ id : generate_token
61+ uses : actions/create-github-app-token@v1
62+ with :
63+ app-id : ${{ secrets.release_app_id }}
64+ private-key : ${{ secrets.release_app_private_key }}
65+
3566 - name : Prepare
3667 run : |
3768 platform=${{ matrix.platform }}
4071 - name : Checkout repository
4172 uses : actions/checkout@v4
4273 with :
74+ ref : ${{ inputs.git_ref }}
4375 submodules : " true"
76+ fetch-depth : 0
77+ token : ${{ inputs.use_app_token && steps.generate_token.outputs.token || github.token }}
4478
4579 # Extract metadata (tags, labels) for Docker
4680 # https://github.com/docker/metadata-action
4983 uses : docker/metadata-action@v5
5084 with :
5185 images : ${{ env.REGISTRY_IMAGE }}
86+ tags : ${{ inputs.docker_tags }}
5287
5388 # Install the cosign tool except on PR
5489 # https://github.com/sigstore/cosign-installer
5792 with :
5893 cosign-release : " v2.2.4"
5994
60- - name : Setup Blacksmith Builder
61- uses : useblacksmith /setup-docker-builder@v1
95+ - name : Set up Docker Buildx
96+ uses : docker /setup-buildx-action@v3
6297
6398 - name : Login to GitHub Packages Docker Registry
6499 uses : docker/login-action@v3
@@ -69,15 +104,14 @@ jobs:
69104
70105 - name : Build Docker image
71106 id : build
72- uses : useblacksmith /build-push-action@v2
107+ uses : docker /build-push-action@v6
73108 with :
74109 context : .
75110 labels : ${{ steps.meta.outputs.labels }}
111+ cache-from : type=gha,scope=${{ env.PLATFORM_PAIR }}
112+ cache-to : type=gha,mode=max,scope=${{ env.PLATFORM_PAIR }}
76113 platforms : ${{ matrix.platform }}
77114 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
78- build-args : |
79- NEXT_PUBLIC_SOURCEBOT_VERSION=${{ github.ref_name }}
80- NEXT_PUBLIC_POSTHOG_PAPIK=${{ vars.NEXT_PUBLIC_POSTHOG_PAPIK }}
81115
82116 - name : Export digest
83117 run : |
@@ -106,43 +140,4 @@ jobs:
106140 # This step uses the identity token to provision an ephemeral certificate
107141 # against the sigstore community Fulcio instance.
108142 run : echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST}
109-
110- merge :
111- runs-on : blacksmith-4vcpu-ubuntu-2404
112- permissions :
113- packages : write
114- needs :
115- - build
116- steps :
117- - name : Download digests
118- uses : actions/download-artifact@v4
119- with :
120- path : /tmp/digests
121- pattern : digests-*
122- merge-multiple : true
123-
124- - name : Setup Blacksmith Builder
125- uses : useblacksmith/setup-docker-builder@v1
126-
127- - name : Extract Docker metadata
128- id : meta
129- uses : docker/metadata-action@v5
130- with :
131- images : ${{ env.REGISTRY_IMAGE }}
132143
133- - name : Login to GitHub Packages Docker Registry
134- uses : docker/login-action@v3
135- with :
136- registry : ghcr.io
137- username : ${{ github.actor }}
138- password : ${{ secrets.GITHUB_TOKEN }}
139-
140- - name : Create manifest list and push
141- working-directory : /tmp/digests
142- run : |
143- docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
144- $(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *)
145-
146- - name : Inspect image
147- run : |
148- docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }}
0 commit comments