2020-08-19 19:46:12 +00:00
[![GitHub release ](https://img.shields.io/github/release/docker/build-push-action.svg?style=flat-square )](https://github.com/docker/build-push-action/releases/latest)
2020-09-08 22:03:42 +00:00
[![GitHub marketplace ](https://img.shields.io/badge/marketplace-build--and--push--docker--images-blue?logo=github&style=flat-square )](https://github.com/marketplace/actions/build-and-push-docker-images)
2022-12-19 19:17:13 +00:00
[![CI workflow ](https://img.shields.io/github/actions/workflow/status/docker/build-push-action/ci.yml?branch=master&label=ci&logo=github&style=flat-square )](https://github.com/docker/build-push-action/actions?workflow=ci)
[![Test workflow ](https://img.shields.io/github/actions/workflow/status/docker/build-push-action/test.yml?branch=master&label=test&logo=github&style=flat-square )](https://github.com/docker/build-push-action/actions?workflow=test)
2020-09-08 21:34:53 +00:00
[![Codecov ](https://img.shields.io/codecov/c/github/docker/build-push-action?logo=codecov&style=flat-square )](https://codecov.io/gh/docker/build-push-action)
2020-08-19 19:46:12 +00:00
2020-08-15 22:36:41 +00:00
## About
2020-03-05 16:28:11 +00:00
2022-10-07 17:16:42 +00:00
GitHub Action to build and push Docker images with [Buildx ](https://github.com/docker/buildx )
with full support of the features provided by [Moby BuildKit ](https://github.com/moby/buildkit )
builder toolkit. This includes multi-platform build, secrets, remote cache, etc.
and different builder deployment/namespacing options.
2020-03-16 15:13:04 +00:00
2020-08-19 19:46:12 +00:00
![Screenshot ](.github/build-push-action.png )
2020-08-15 22:36:41 +00:00
___
2020-03-05 16:28:11 +00:00
2020-08-15 22:36:41 +00:00
* [Usage ](#usage )
2020-09-02 08:07:11 +00:00
* [Git context ](#git-context )
* [Path context ](#path-context )
2022-11-04 08:17:25 +00:00
* [Examples ](#examples )
2024-06-27 10:44:35 +00:00
* [Summaries ](#summaries )
2020-08-15 22:36:41 +00:00
* [Customizing ](#customizing )
* [inputs ](#inputs )
* [outputs ](#outputs )
2024-05-15 07:40:14 +00:00
* [environment variables ](#environment-variables )
2020-09-21 16:22:47 +00:00
* [Troubleshooting ](#troubleshooting )
2022-10-07 17:16:42 +00:00
* [Contributing ](#contributing )
2020-03-05 16:28:11 +00:00
2020-08-15 22:36:41 +00:00
## Usage
2020-03-05 16:28:11 +00:00
2022-01-30 17:12:55 +00:00
In the examples below we are also using 3 other actions:
2020-09-02 08:07:11 +00:00
2022-10-07 17:16:42 +00:00
* [`setup-buildx` ](https://github.com/docker/setup-buildx-action ) action will
create and boot a builder using by default the [`docker-container` driver ](https://docs.docker.com/build/building/drivers/docker-container/ ).
This is **not required but recommended** using it to be able to build
multi-platform images, export cache, etc.
* [`setup-qemu` ](https://github.com/docker/setup-qemu-action ) action can be
useful if you want to add emulation support with QEMU to be able to build
against more platforms.
* [`login` ](https://github.com/docker/login-action ) action will take care to
log in against a Docker registry.
2021-02-17 17:53:15 +00:00
### Git context
2020-09-12 18:40:12 +00:00
2022-09-02 10:24:08 +00:00
By default, this action uses the [Git context ](https://docs.docker.com/engine/reference/commandline/build/#git-repositories ),
so you don't need to use the [`actions/checkout` ](https://github.com/actions/checkout/ )
action to check out the repository as this will be done directly by [BuildKit ](https://github.com/moby/buildkit ).
2022-01-30 17:12:55 +00:00
2022-10-07 17:16:42 +00: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 )
2022-01-30 17:12:55 +00:00
and will result in the following context: `https://github.com/<owner>/<repo>.git#<ref>` .
2020-09-22 18:49:18 +00:00
```yaml
2020-08-15 22:36:41 +00:00
name: ci
on:
push:
jobs:
2021-02-17 17:53:15 +00:00
docker:
2020-08-17 20:18:15 +00:00
runs-on: ubuntu-latest
steps:
2024-12-03 14:35:13 +00:00
-
name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ vars.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
2020-09-05 03:18:00 +00:00
-
name: Set up QEMU
2023-09-12 08:12:12 +00:00
uses: docker/setup-qemu-action@v3
2020-08-17 20:18:15 +00:00
-
name: Set up Docker Buildx
2023-09-12 08:12:12 +00:00
uses: docker/setup-buildx-action@v3
2020-08-17 20:18:15 +00:00
-
name: Build and push
2024-06-17 09:46:56 +00:00
uses: docker/build-push-action@v6
2020-08-17 20:18:15 +00:00
with:
push: true
2020-08-18 20:54:44 +00:00
tags: user/app:latest
2020-09-22 18:49:18 +00:00
```
2020-08-17 20:18:15 +00:00
2022-01-30 17:12:55 +00: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
[Path context ](#path-context ) using the [`context` input ](#inputs ) alongside
the [`actions/checkout` ](https://github.com/actions/checkout/ ) action to remove
this restriction.
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
2024-06-17 09:46:56 +00:00
uses: docker/build-push-action@v6
2022-01-30 17:12:55 +00:00
with:
context: "{{defaultContext}}:mysubdir"
push: true
tags: user/app:latest
```
2022-10-07 17:16:42 +00:00
Building from the current repository automatically uses the [GitHub Token ](https://docs.github.com/en/actions/security-guides/automatic-token-authentication ),
2022-01-30 17:12:55 +00:00
so it does not need to be passed. If you want to authenticate against another
2023-05-31 09:36:48 +00:00
private repository, you have to use a [secret ](https://docs.docker.com/build/ci/github-actions/secrets )
2022-11-04 08:17:25 +00:00
named `GIT_AUTH_TOKEN` to be able to authenticate against it with Buildx:
2020-09-02 08:07:11 +00:00
```yaml
-
name: Build and push
2024-06-17 09:46:56 +00:00
uses: docker/build-push-action@v6
2020-09-02 08:07:11 +00:00
with:
push: true
tags: user/app:latest
secrets: |
2020-09-22 18:49:18 +00:00
GIT_AUTH_TOKEN=${{ secrets.MYTOKEN }}
2020-09-02 08:07:11 +00:00
```
### Path context
2020-09-22 18:49:18 +00:00
```yaml
name: ci
2020-09-21 16:22:47 +00:00
2020-09-22 18:49:18 +00:00
on:
push:
2020-09-21 16:22:47 +00:00
2020-09-22 18:49:18 +00:00
jobs:
2021-02-17 17:53:15 +00:00
docker:
2020-09-22 18:49:18 +00:00
runs-on: ubuntu-latest
steps:
-
name: Checkout
2024-01-26 05:16:15 +00:00
uses: actions/checkout@v4
2024-12-03 14:35:13 +00:00
-
name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ vars.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
2020-09-22 18:49:18 +00:00
-
name: Set up QEMU
2023-09-12 08:12:12 +00:00
uses: docker/setup-qemu-action@v3
2020-09-22 18:49:18 +00:00
-
name: Set up Docker Buildx
2023-09-12 08:12:12 +00:00
uses: docker/setup-buildx-action@v3
2020-09-22 18:49:18 +00:00
-
name: Build and push
2024-06-17 09:46:56 +00:00
uses: docker/build-push-action@v6
2020-09-22 18:49:18 +00:00
with:
context: .
push: true
tags: user/app:latest
```
2020-09-02 08:07:11 +00:00
2022-11-04 08:17:25 +00:00
## Examples
2023-02-23 16:16:49 +00:00
* [Multi-platform image ](https://docs.docker.com/build/ci/github-actions/multi-platform/ )
* [Secrets ](https://docs.docker.com/build/ci/github-actions/secrets/ )
* [Push to multi-registries ](https://docs.docker.com/build/ci/github-actions/push-multi-registries/ )
* [Manage tags and labels ](https://docs.docker.com/build/ci/github-actions/manage-tags-labels/ )
* [Cache management ](https://docs.docker.com/build/ci/github-actions/cache/ )
* [Export to Docker ](https://docs.docker.com/build/ci/github-actions/export-docker/ )
* [Test before push ](https://docs.docker.com/build/ci/github-actions/test-before-push/ )
* [Local registry ](https://docs.docker.com/build/ci/github-actions/local-registry/ )
* [Share built image between jobs ](https://docs.docker.com/build/ci/github-actions/share-image-jobs/ )
* [Named contexts ](https://docs.docker.com/build/ci/github-actions/named-contexts/ )
* [Copy image between registries ](https://docs.docker.com/build/ci/github-actions/copy-image-registries/ )
* [Update Docker Hub repo description ](https://docs.docker.com/build/ci/github-actions/update-dockerhub-desc/ )
2024-04-26 09:12:45 +00:00
* [SBOM and provenance attestations ](https://docs.docker.com/build/ci/github-actions/attestations/ )
* [Annotations ](https://docs.docker.com/build/ci/github-actions/annotations/ )
* [Reproducible builds ](https://docs.docker.com/build/ci/github-actions/reproducible-builds/ )
2020-09-09 23:14:41 +00:00
2024-06-27 10:44:35 +00: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
and eventual errors.
![build-push-action job summary ](./.github/build-push-summary.png )
The summary also includes a link for downloading the build record with
additional details about the build, 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 15:38:24 +00:00
`DOCKER_BUILD_SUMMARY` [environment variable ](#environment-variables ).
2024-06-27 10:44:35 +00:00
For more information about summaries, refer to the
[documentation ](https://docs.docker.com/go/build-summary/ ).
2020-08-15 22:36:41 +00:00
## Customizing
2020-03-05 16:28:11 +00:00
2020-08-15 22:36:41 +00:00
### inputs
2020-03-05 16:28:11 +00:00
2024-06-30 22:54:10 +00:00
The following inputs can be used as `step.with` keys:
2020-03-05 16:28:11 +00:00
2020-10-22 19:50:22 +00:00
> `List` type is a newline-delimited string
> ```yaml
> cache-from: |
> user/app:cache
> type=local,src=path/to/dir
> ```
> `CSV` type is a comma-delimited string
> ```yaml
> tags: name/app:latest,name/app:1.0.0
> ```
2023-01-11 11:12:09 +00:00
| Name | Type | Description |
|--------------------|-------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `add-hosts` | List/CSV | List of [customs host-to-IP mapping ](https://docs.docker.com/engine/reference/commandline/build/#add-entries-to-container-hosts-file---add-host ) (e.g., `docker:10.180.0.1` ) |
| `allow` | List/CSV | List of [extra privileged entitlement ](https://docs.docker.com/engine/reference/commandline/buildx_build/#allow ) (e.g., `network.host,security.insecure` ) |
2023-10-24 05:23:44 +00:00
| `annotations` | List | List of annotation to set to the image |
2023-01-11 11:12:09 +00:00
| `attests` | List | List of [attestation ](https://docs.docker.com/build/attestations/ ) parameters (e.g., `type=sbom,generator=image` ) |
| `builder` | String | Builder instance (see [setup-buildx ](https://github.com/docker/setup-buildx-action ) action) |
| `build-args` | List | List of [build-time variables ](https://docs.docker.com/engine/reference/commandline/buildx_build/#build-arg ) |
| `build-contexts` | List | List of additional [build contexts ](https://docs.docker.com/engine/reference/commandline/buildx_build/#build-context ) (e.g., `name=path` ) |
| `cache-from` | List | List of [external cache sources ](https://docs.docker.com/engine/reference/commandline/buildx_build/#cache-from ) (e.g., `type=local,src=path/to/dir` ) |
| `cache-to` | List | List of [cache export destinations ](https://docs.docker.com/engine/reference/commandline/buildx_build/#cache-to ) (e.g., `type=local,dest=path/to/dir` ) |
2024-11-25 16:14:29 +00:00
| `call` | String | Set [method for evaluating build ](https://docs.docker.com/reference/cli/docker/buildx/build/#call ) (e.g., `check` ) |
2023-01-11 11:12:09 +00:00
| `cgroup-parent` | String | Optional [parent cgroup ](https://docs.docker.com/engine/reference/commandline/build/#use-a-custom-parent-cgroup---cgroup-parent ) for the container used in the build |
| `context` | String | Build's context is the set of files located in the specified [`PATH` or `URL` ](https://docs.docker.com/engine/reference/commandline/build/ ) (default [Git context ](#git-context )) |
| `file` | String | Path to the Dockerfile. (default `{context}/Dockerfile` ) |
| `labels` | List | List of metadata for an image |
| `load` | Bool | [Load ](https://docs.docker.com/engine/reference/commandline/buildx_build/#load ) is a shorthand for `--output=type=docker` (default `false` ) |
| `network` | String | Set the networking mode for the `RUN` instructions during build |
| `no-cache` | Bool | Do not use cache when building the image (default `false` ) |
| `no-cache-filters` | List/CSV | Do not cache specified stages |
2024-04-15 07:50:33 +00:00
| `outputs` | List | List of [output destinations ](https://docs.docker.com/engine/reference/commandline/buildx_build/#output ) (format: `type=local,dest=path` ) |
2023-01-11 11:12:09 +00:00
| `platforms` | List/CSV | List of [target platforms ](https://docs.docker.com/engine/reference/commandline/buildx_build/#platform ) for build |
| `provenance` | Bool/String | Generate [provenance ](https://docs.docker.com/build/attestations/slsa-provenance/ ) attestation for the build (shorthand for `--attest=type=provenance` ) |
| `pull` | Bool | Always attempt to pull all referenced images (default `false` ) |
| `push` | Bool | [Push ](https://docs.docker.com/engine/reference/commandline/buildx_build/#push ) is a shorthand for `--output=type=registry` (default `false` ) |
| `sbom` | Bool/String | Generate [SBOM ](https://docs.docker.com/build/attestations/sbom/ ) attestation for the build (shorthand for `--attest=type=sbom` ) |
| `secrets` | List | List of [secrets ](https://docs.docker.com/engine/reference/commandline/buildx_build/#secret ) to expose to the build (e.g., `key=string` , `GIT_AUTH_TOKEN=mytoken` ) |
2023-10-12 12:32:49 +00:00
| `secret-envs` | List/CSV | List of [secret env vars ](https://docs.docker.com/engine/reference/commandline/buildx_build/#secret ) to expose to the build (e.g., `key=envname` , `MY_SECRET=MY_ENV_VAR` ) |
2023-01-11 11:12:09 +00:00
| `secret-files` | List | List of [secret files ](https://docs.docker.com/engine/reference/commandline/buildx_build/#secret ) to expose to the build (e.g., `key=filename` , `MY_SECRET=./secret.txt` ) |
| `shm-size` | String | Size of [`/dev/shm` ](https://docs.docker.com/engine/reference/commandline/buildx_build/#shm-size ) (e.g., `2g` ) |
| `ssh` | List | List of [SSH agent socket or keys ](https://docs.docker.com/engine/reference/commandline/buildx_build/#ssh ) to expose to the build |
| `tags` | List/CSV | List of tags |
| `target` | String | Sets the target stage to build |
| `ulimit` | List | [Ulimit ](https://docs.docker.com/engine/reference/commandline/buildx_build/#ulimit ) options (e.g., `nofile=1024:1024` ) |
| `github-token` | String | GitHub Token used to authenticate against a repository for [Git context ](#git-context ) (default `${{ github.token }}` ) |
2022-01-18 13:57:27 +00:00
2020-08-15 22:36:41 +00:00
### outputs
2020-03-05 16:28:11 +00:00
2023-09-12 08:12:12 +00:00
The following outputs are available:
2020-03-05 16:28:11 +00:00
2022-10-07 17:16:42 +00:00
| Name | Type | Description |
|------------|---------|-----------------------|
| `imageid` | String | Image ID |
| `digest` | String | Image digest |
| `metadata` | JSON | Build result metadata |
2020-03-05 16:28:11 +00:00
2024-05-15 07:40:14 +00:00
### environment variables
2024-07-02 15:38:24 +00:00
| Name | Type | Default | Description |
|--------------------------------------|--------|---------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
2024-07-31 10:39:27 +00: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-02 15:38:24 +00:00
| `DOCKER_BUILD_SUMMARY` | Bool | `true` | If `false` , [build summary ](https://docs.docker.com/build/ci/github-actions/build-summary/ ) generation is disabled |
2024-07-02 16:07:54 +00:00
| `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 |
2024-07-02 16:09:36 +00:00
| `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` |
2024-05-15 07:40:14 +00:00
2020-09-21 16:22:47 +00:00
## Troubleshooting
2020-09-21 19:06:04 +00:00
See [TROUBLESHOOTING.md ](TROUBLESHOOTING.md )
2020-09-21 16:22:47 +00:00
2022-10-07 17:16:42 +00:00
## Contributing
2020-08-20 15:25:55 +00:00
2022-10-07 17:16:42 +00:00
Want to contribute? Awesome! You can find information about contributing to
this project in the [CONTRIBUTING.md ](/.github/CONTRIBUTING.md )