2021-01-28 23:14:03 +01:00
[](https://github.com/docker/bake-action/releases/latest)
2020-10-08 00:52:52 +02:00
[](https://github.com/marketplace/actions/docker-buildx-bake)
2022-12-19 20:39:40 +01:00
[](https://github.com/docker/bake-action/actions?workflow=ci)
[](https://github.com/docker/bake-action/actions?workflow=test)
2021-01-28 23:14:03 +01:00
[](https://codecov.io/gh/docker/bake-action)
2020-10-08 00:52:52 +02:00
## About
2022-10-07 16:41:51 +02:00
GitHub Action to use Docker [Buildx Bake ](https://docs.docker.com/build/customize/bake/ )
2021-04-03 20:37:29 +02:00
as a high-level build command.
2020-10-08 00:52:52 +02:00
2021-05-26 15:22:18 +02:00

2020-10-08 00:52:52 +02:00
___
* [Usage ](#usage )
2024-01-12 14:15:02 +01:00
* [Git context ](#git-context )
2024-06-18 12:03:27 +02:00
* [Path context ](#path-context )
2024-06-27 12:55:15 +02:00
* [Summaries ](#summaries )
2020-10-08 00:52:52 +02:00
* [Customizing ](#customizing )
* [inputs ](#inputs )
2021-09-01 22:22:37 +02:00
* [outputs ](#outputs )
2024-05-15 09:42:30 +02:00
* [environment variables ](#environment-variables )
2023-12-19 13:39:15 +01:00
* [Subactions ](#subactions )
2024-07-03 20:15:30 +02:00
* [`list-targets` ](subaction/list-targets )
2022-10-07 16:41:51 +02:00
* [Contributing ](#contributing )
2020-10-08 00:52:52 +02:00
## Usage
2024-01-12 14:15:02 +01:00
### Git context
2024-06-18 12:03:27 +02:00
Since `v6` this action uses the [Git context ](https://docs.docker.com/build/bake/remote-definition/ )
to build from a remote bake definition by default like the [build-push-action ](https://github.com/docker/build-push-action )
does. This means that you don't need to use the [`actions/checkout` ](https://github.com/actions/checkout/ )
2024-01-12 14:15:02 +01:00
action to check out the repository as [BuildKit ](https://docs.docker.com/build/buildkit/ )
will do this directly.
2024-06-18 12:03:27 +02:00
The git reference will be based on the [event that triggered your workflow ](https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows )
and will result in the following context: `https://github.com/<owner>/<repo>.git#<ref>` .
2024-01-12 14:15:02 +01:00
```yaml
name: ci
on:
push:
jobs:
bake:
runs-on: ubuntu-latest
steps:
-
name: Login to DockerHub
uses: docker/login-action@v3
with:
2024-12-03 15:25:30 +01:00
username: ${{ vars.DOCKERHUB_USERNAME }}
2024-01-12 14:15:02 +01:00
password: ${{ secrets.DOCKERHUB_TOKEN }}
2024-12-03 15:25:30 +01:00
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
2024-01-12 14:15:02 +01:00
-
name: Build and push
2025-01-08 11:07:02 +01:00
uses: docker/bake-action@v6
2024-01-12 14:15:02 +01:00
with:
push: true
2024-06-18 12:03:27 +02:00
set: |
*.tags=user/app:latest
2024-01-12 14:15:02 +01:00
```
Be careful because **any file mutation in the steps that precede the build step
will be ignored, including processing of the `.dockerignore` file** since
the context is based on the Git reference. However, you can use the
2024-06-18 12:03:27 +02:00
[Path context ](#path-context ) using the [`source` input ](#inputs ) alongside
the [`actions/checkout` ](https://github.com/actions/checkout/ ) action to remove
this restriction.
2024-01-12 14:15:02 +01:00
Default Git context can also be provided using the [Handlebars template ](https://handlebarsjs.com/guide/ )
expression `{{defaultContext}}` . Here we can use it to provide a subdirectory
to the default Git context:
```yaml
-
name: Build and push
2025-01-08 11:07:02 +01:00
uses: docker/bake-action@v6
2024-01-12 14:15:02 +01:00
with:
source: "{{defaultContext}}:mysubdir"
push: true
2024-06-18 12:03:27 +02:00
set: |
*.tags=user/app:latest
2024-01-12 14:15:02 +01:00
```
2024-04-13 15:20:19 +02:00
Building from the current repository automatically uses the `GITHUB_TOKEN`
secret that GitHub [automatically creates for workflows ](https://docs.github.com/en/actions/security-guides/automatic-token-authentication ),
so you don't need to pass that manually. If you want to authenticate against
another private repository for remote definitions, you can set the
[`BUILDX_BAKE_GIT_AUTH_TOKEN` environment variable ](https://docs.docker.com/build/building/variables/#buildx_bake_git_auth_token ).
> [!NOTE]
> Supported since Buildx 0.14.0
```yaml
-
name: Build and push
2025-01-08 11:07:02 +01:00
uses: docker/bake-action@v6
2024-04-13 15:20:19 +02:00
with:
push: true
2024-06-18 12:03:27 +02:00
set: |
*.tags=user/app:latest
2024-04-13 15:20:19 +02:00
env:
BUILDX_BAKE_GIT_AUTH_TOKEN: ${{ secrets.MYTOKEN }}
```
2024-06-18 12:03:27 +02:00
### Path context
```yaml
name: ci
on:
push:
jobs:
bake:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v4
-
name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ vars.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
-
name: Build and push
2025-01-08 11:07:02 +01:00
uses: docker/bake-action@v6
2024-06-18 12:03:27 +02:00
with:
source: .
push: true
set: |
*.tags=user/app:latest
```
2024-06-27 12:55:15 +02:00
## Summaries
This action generates a [job summary ](https://github.blog/2022-05-09-supercharging-github-actions-with-job-summaries/ )
that provides a detailed overview of the build execution. The summary shows an
overview of all the steps executed during the build, including the build
inputs, bake definition, and eventual errors.

The summary also includes a link for downloading a build record archive with
additional details about the build execution for all the bake targets,
including build stats, logs, outputs, and more. The build record can be
imported to Docker Desktop for inspecting the build in greater detail.
Summaries are enabled by default, but can be disabled with the
2024-07-02 18:52:07 +02:00
`DOCKER_BUILD_SUMMARY` [environment variable ](#environment-variables ).
2024-06-27 12:55:15 +02:00
For more information about summaries, refer to the
[documentation ](https://docs.docker.com/go/build-summary/ ).
2023-12-19 13:39:15 +01:00
## Customizing
### inputs
2024-01-12 14:15:02 +01:00
The following inputs can be used as `step.with` keys
2023-12-19 13:39:15 +01:00
> `List` type is a newline-delimited string
> ```yaml
> set: target.args.mybuildarg=value
> ```
> ```yaml
> set: |
> target.args.mybuildarg=value
> foo*.args.mybuildarg=value
> ```
> `CSV` type is a comma-delimited string
> ```yaml
> targets: default,release
> ```
2024-04-13 15:20:19 +02:00
| Name | Type | Description |
|----------------|-------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `builder` | String | Builder instance (see [setup-buildx ](https://github.com/docker/setup-buildx-action ) action) |
| `source` | String | Context to build from. Can be either local (`.` ) or a [remote bake definition ](https://docs.docker.com/build/customize/bake/file-definition/#remote-definition ) |
2024-10-02 16:50:35 +02:00
| `allow` | List/CSV | Allow build to access specified resources (e.g., `network.host` ) |
2024-04-13 15:20:19 +02:00
| `files` | List/CSV | List of [bake definition files ](https://docs.docker.com/build/customize/bake/file-definition/ ) |
| `workdir` | String | Working directory of execution |
| `targets` | List/CSV | List of bake targets (`default` target used if empty) |
| `no-cache` | Bool | Do not use cache when building the image (default `false` ) |
| `pull` | Bool | Always attempt to pull a newer version of the image (default `false` ) |
| `load` | Bool | Load is a shorthand for `--set=*.output=type=docker` (default `false` ) |
| `provenance` | Bool/String | [Provenance ](https://docs.docker.com/build/attestations/slsa-provenance/ ) is a shorthand for `--set=*.attest=type=provenance` |
| `push` | Bool | Push is a shorthand for `--set=*.output=type=registry` (default `false` ) |
| `sbom` | Bool/String | [SBOM ](https://docs.docker.com/build/attestations/sbom/ ) is a shorthand for `--set=*.attest=type=sbom` |
2024-10-02 16:50:35 +02:00
| `set` | List | List of [targets values to override ](https://docs.docker.com/engine/reference/commandline/buildx_bake/#set ) (e.g., `targetpattern.key=value` ) |
2024-04-13 15:20:19 +02:00
| `github-token` | String | API token used to authenticate to a Git repository for [remote definitions ](https://docs.docker.com/build/bake/remote-definition/ ) (default `${{ github.token }}` ) |
2023-12-19 13:39:15 +01:00
### outputs
The following outputs are available
| Name | Type | Description |
|------------|------|-----------------------|
| `metadata` | JSON | Build result metadata |
2024-07-03 20:09:59 +02:00
### environment variables
| Name | Type | Default | Description |
|--------------------------------------|--------|---------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
2024-07-31 14:24:42 +02:00
| `DOCKER_BUILD_CHECKS_ANNOTATIONS` | Bool | `true` | If `false` , GitHub annotations are not generated for [build checks ](https://docs.docker.com/build/checks/ ) |
2024-07-03 20:09:59 +02:00
| `DOCKER_BUILD_SUMMARY` | Bool | `true` | If `false` , [build summary ](https://docs.docker.com/build/ci/github-actions/build-summary/ ) generation is disabled |
| `DOCKER_BUILD_RECORD_UPLOAD` | Bool | `true` | If `false` , build record upload as [GitHub artifact ](https://docs.github.com/en/actions/using-workflows/storing-workflow-data-as-artifacts ) is disabled |
| `DOCKER_BUILD_RECORD_RETENTION_DAYS` | Number | | Duration after which build record artifact will expire in days. Defaults to repository/org [retention settings ](https://docs.github.com/en/actions/learn-github-actions/usage-limits-billing-and-administration#artifact-and-log-retention-policy ) if unset or `0` |
2023-11-09 11:07:49 +01:00
## Subactions
2024-07-03 20:15:30 +02:00
* [`list-targets` ](subaction/list-targets )
2023-11-09 11:07:49 +01:00
2022-10-07 16:41:51 +02:00
## Contributing
2020-10-08 00:52:52 +02:00
2022-10-07 16:41:51 +02:00
Want to contribute? Awesome! You can find information about contributing to
this project in the [CONTRIBUTING.md ](/.github/CONTRIBUTING.md )