1- name : Publish to ghcr
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+ #
7+ # Used by:
8+ # - publish-main-to-ghcr.yml (for main branch builds)
9+ # - release-sourcebot.yml (for versioned releases)
210
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
11+ name : Build Multi-Platform Images
512
613on :
7- push :
8- branches : ["main"]
14+ workflow_call :
15+ inputs :
16+ git_ref :
17+ description : " Git ref to checkout"
18+ required : true
19+ type : string
20+ docker_tags :
21+ description : " Docker tags configuration (JSON array or raw tags)"
22+ required : true
23+ type : string
24+ use_app_token :
25+ description : " Whether to use GitHub App token for checkout"
26+ required : false
27+ type : boolean
28+ default : false
29+ secrets :
30+ release_app_id :
31+ description : " GitHub App ID (required if use_app_token is true)"
32+ required : false
33+ release_app_private_key :
34+ description : " GitHub App private key (required if use_app_token is true)"
35+ required : false
936
1037env :
11- # Use docker.io for Docker Hub if empty
1238 REGISTRY_IMAGE : ghcr.io/sourcebot-dev/sourcebot
1339
1440jobs :
1844 permissions :
1945 contents : read
2046 packages : write
21- # This is used to complete the identity challenge
22- # with sigstore/fulcio when running outside of PRs .
47+ # Required for keyless signing with cosign/Sigstore.
48+ # Allows workflow to obtain OIDC token for ephemeral certificate from Fulcio .
2349 id-token : write
2450 strategy :
2551 matrix :
3157 runs-on : ubuntu-24.04-arm
3258
3359 steps :
60+ - name : Generate GitHub App token
61+ if : inputs.use_app_token
62+ id : generate_token
63+ uses : actions/create-github-app-token@v1
64+ with :
65+ app-id : ${{ secrets.release_app_id }}
66+ private-key : ${{ secrets.release_app_private_key }}
67+
3468 - name : Prepare
3569 run : |
3670 platform=${{ matrix.platform }}
3973 - name : Checkout repository
4074 uses : actions/checkout@v4
4175 with :
42- ref : ${{ github.ref_name }}
76+ ref : ${{ inputs.git_ref }}
4377 submodules : " true"
78+ fetch-depth : 0
79+ token : ${{ inputs.use_app_token && steps.generate_token.outputs.token || github.token }}
4480
4581 # Extract metadata (tags, labels) for Docker
4682 # https://github.com/docker/metadata-action
4985 uses : docker/metadata-action@v5
5086 with :
5187 images : ${{ env.REGISTRY_IMAGE }}
88+ tags : ${{ inputs.docker_tags }}
5289
5390 # Install the cosign tool except on PR
5491 # https://github.com/sigstore/cosign-installer
@@ -105,43 +142,4 @@ jobs:
105142 # This step uses the identity token to provision an ephemeral certificate
106143 # against the sigstore community Fulcio instance.
107144 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 }}
131145
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