|
| 1 | +--- |
| 2 | +title: Docker GitHub Builder |
| 3 | +linkTitle: GitHub Builder |
| 4 | +description: Use Docker-maintained reusable GitHub Actions workflows to build images and artifacts with BuildKit. |
| 5 | +keywords: ci, github actions, gha, buildkit, buildx, bake, reusable workflows |
| 6 | +params: |
| 7 | + sidebar: |
| 8 | + badge: |
| 9 | + color: green |
| 10 | + text: New |
| 11 | +--- |
| 12 | + |
| 13 | +Docker GitHub Builder is a set of [reusable workflows](https://docs.github.com/en/actions/how-tos/reuse-automations/reuse-workflows) |
| 14 | +in the [`docker/github-builder` repository](https://github.com/docker/github-builder) |
| 15 | +for building container images and local artifacts with [BuildKit](../../../buildkit/_index.md). |
| 16 | +This section explains what the workflows solve, how they differ from wiring |
| 17 | +together individual GitHub Actions in each repository, and when to use |
| 18 | +[`build.yml`](build.md) or [`bake.yml`](bake.md). |
| 19 | + |
| 20 | +If you compose a build job from `docker/login-action`, `docker/setup-buildx-action`, |
| 21 | +`docker/metadata-action`, and either `docker/build-push-action` or |
| 22 | +`docker/bake-action`, your repository owns every detail of how the build runs. |
| 23 | +That approach works, but it also means every repository has to maintain its own |
| 24 | +runner selection, [cache setup](../cache.md), [Provenance settings](../attestations.md), |
| 25 | +signing behavior, and [multi-platform manifest handling](../multi-platform.md). |
| 26 | +Docker GitHub Builder moves that implementation into Docker-maintained reusable |
| 27 | +workflows, so your workflow only decides when to build and which inputs to pass. |
| 28 | + |
| 29 | +The difference is easiest to see in the job definition. A conventional workflow |
| 30 | +spells out each action step: |
| 31 | + |
| 32 | +```yaml |
| 33 | +jobs: |
| 34 | + docker: |
| 35 | + runs-on: ubuntu-latest |
| 36 | + steps: |
| 37 | + - name: Login to Docker Hub |
| 38 | + uses: docker/login-action@{{% param "login_action_version" %}} |
| 39 | + with: |
| 40 | + username: ${{ vars.DOCKERHUB_USERNAME }} |
| 41 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 42 | + |
| 43 | + - name: Set up QEMU |
| 44 | + uses: docker/setup-qemu-action@{{% param "setup_qemu_action_version" %}} |
| 45 | + |
| 46 | + - name: Set up Docker Buildx |
| 47 | + uses: docker/setup-buildx-action@{{% param "setup_buildx_action_version" %}} |
| 48 | + |
| 49 | + - name: Docker meta |
| 50 | + uses: docker/metadata-action@{{% param "metadata_action_version" %}} |
| 51 | + id: meta |
| 52 | + with: |
| 53 | + images: name/app |
| 54 | + |
| 55 | + - name: Build and push |
| 56 | + uses: docker/build-push-action@{{% param "build_push_action_version" %}} |
| 57 | + with: |
| 58 | + push: ${{ github.event_name != 'pull_request' }} |
| 59 | + tags: ${{ steps.meta.outputs.tags }} |
| 60 | + labels: ${{ steps.meta.outputs.labels }} |
| 61 | + cache-from: type=gha |
| 62 | + cache-to: type=gha |
| 63 | +``` |
| 64 | +
|
| 65 | +With Docker GitHub Builder, the same build is a reusable workflow call: |
| 66 | +
|
| 67 | +```yaml |
| 68 | +jobs: |
| 69 | + build: |
| 70 | + uses: docker/github-builder/.github/workflows/build.yml@{{% param "github_builder_version" %}} |
| 71 | + permissions: |
| 72 | + contents: read # to fetch the repository content |
| 73 | + id-token: write # for signing attestation(s) with GitHub OIDC Token |
| 74 | + with: |
| 75 | + output: image |
| 76 | + push: ${{ github.event_name != 'pull_request' }} |
| 77 | + meta-images: name/app |
| 78 | + secrets: |
| 79 | + registry-auths: | |
| 80 | + - registry: docker.io |
| 81 | + username: ${{ vars.DOCKERHUB_USERNAME }} |
| 82 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 83 | +``` |
| 84 | +
|
| 85 | +This model gives you a build pipeline that is maintained in the Docker |
| 86 | +organization, uses a pinned [BuildKit](../../../buildkit/_index.md) environment, |
| 87 | +distributes [multi-platform builds](../../../building/multi-platform.md) across |
| 88 | +runners when that helps, and emits signed [SLSA provenance](../../../metadata/attestations/slsa-provenance.md) |
| 89 | +that records both the source commit and the builder identity. |
| 90 | +
|
| 91 | +That tradeoff is intentional. You keep control of when the build runs and which |
| 92 | +inputs it uses, but the build implementation itself lives in the |
| 93 | +Docker-maintained workflow rather than in per-repository job steps. |
| 94 | +
|
| 95 | +Use [`build.yml`](build.md) when your repository builds from a Dockerfile and |
| 96 | +the familiar `build-push-action` inputs map cleanly to your workflow. Use |
| 97 | +[`bake.yml`](bake.md) when your repository already describes builds in a |
| 98 | +[Bake definition](../../../bake/_index.md), or when you want Bake targets, |
| 99 | +overrides, and variables to stay as the source of truth. |
| 100 | + |
| 101 | +Both workflows support image output, local output, cache export to the |
| 102 | +[GitHub Actions cache backend](../../../cache/backends/gha.md), |
| 103 | +[SBOM generation](../../../metadata/attestations/sbom.md), and signing. The |
| 104 | +Bake workflow adds Bake definition validation and builds one target per workflow |
| 105 | +call. |
| 106 | + |
| 107 | +{{% sectionlinks %}} |
0 commit comments