|
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 | +# |
4 | 7 | # @ see: https://docs.docker.com/build/ci/github-actions/multi-platform/#distribute-build-across-multiple-runners |
5 | 8 |
|
| 9 | +name: Build Multi-Platform Images |
| 10 | + |
6 | 11 | on: |
7 | | - push: |
8 | | - branches: ["main"] |
9 | | - tags: ["v*.*.*"] |
10 | 12 | workflow_call: |
11 | 13 | inputs: |
12 | | - version: |
13 | | - description: 'Version tag (e.g., v4.10.5)' |
14 | | - required: false |
| 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 |
15 | 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 |
16 | 34 |
|
17 | 35 | env: |
18 | | - # Use docker.io for Docker Hub if empty |
19 | 36 | REGISTRY_IMAGE: ghcr.io/sourcebot-dev/sourcebot |
20 | 37 |
|
21 | 38 | jobs: |
|
25 | 42 | permissions: |
26 | 43 | contents: read |
27 | 44 | packages: write |
28 | | - # This is used to complete the identity challenge |
29 | | - # 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. |
30 | 47 | id-token: write |
31 | 48 | strategy: |
32 | 49 | matrix: |
|
38 | 55 | runs-on: ubuntu-24.04-arm |
39 | 56 |
|
40 | 57 | 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 | + |
41 | 66 | - name: Prepare |
42 | 67 | run: | |
43 | 68 | platform=${{ matrix.platform }} |
|
46 | 71 | - name: Checkout repository |
47 | 72 | uses: actions/checkout@v4 |
48 | 73 | with: |
49 | | - ref: ${{ inputs.version || github.ref_name }} |
| 74 | + ref: ${{ inputs.git_ref }} |
50 | 75 | submodules: "true" |
| 76 | + fetch-depth: 0 |
| 77 | + token: ${{ inputs.use_app_token && steps.generate_token.outputs.token || github.token }} |
51 | 78 |
|
52 | 79 | # Extract metadata (tags, labels) for Docker |
53 | 80 | # https://github.com/docker/metadata-action |
|
56 | 83 | uses: docker/metadata-action@v5 |
57 | 84 | with: |
58 | 85 | images: ${{ env.REGISTRY_IMAGE }} |
| 86 | + tags: ${{ inputs.docker_tags }} |
59 | 87 |
|
60 | 88 | # Install the cosign tool except on PR |
61 | 89 | # https://github.com/sigstore/cosign-installer |
@@ -112,43 +140,4 @@ jobs: |
112 | 140 | # This step uses the identity token to provision an ephemeral certificate |
113 | 141 | # against the sigstore community Fulcio instance. |
114 | 142 | run: echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST} |
115 | | - |
116 | | - merge: |
117 | | - runs-on: ubuntu-latest |
118 | | - permissions: |
119 | | - packages: write |
120 | | - needs: |
121 | | - - build |
122 | | - steps: |
123 | | - - name: Download digests |
124 | | - uses: actions/download-artifact@v4 |
125 | | - with: |
126 | | - path: /tmp/digests |
127 | | - pattern: digests-* |
128 | | - merge-multiple: true |
129 | | - |
130 | | - - name: Set up Docker Buildx |
131 | | - uses: docker/setup-buildx-action@v3 |
132 | | - |
133 | | - - name: Extract Docker metadata |
134 | | - id: meta |
135 | | - uses: docker/metadata-action@v5 |
136 | | - with: |
137 | | - images: ${{ env.REGISTRY_IMAGE }} |
138 | 143 |
|
139 | | - - name: Login to GitHub Packages Docker Registry |
140 | | - uses: docker/login-action@v3 |
141 | | - with: |
142 | | - registry: ghcr.io |
143 | | - username: ${{ github.actor }} |
144 | | - password: ${{ secrets.GITHUB_TOKEN }} |
145 | | - |
146 | | - - name: Create manifest list and push |
147 | | - working-directory: /tmp/digests |
148 | | - run: | |
149 | | - docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ |
150 | | - $(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *) |
151 | | - |
152 | | - - name: Inspect image |
153 | | - run: | |
154 | | - docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }} |
0 commit comments