Skip to content

Commit

Permalink
buildinfo: add BUILDKIT_BUILDINFO build arg
Browse files Browse the repository at this point in the history
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
  • Loading branch information
crazy-max committed Feb 28, 2023
1 parent 9ac210f commit 837b4b2
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 12 deletions.
9 changes: 9 additions & 0 deletions control/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,15 @@ func (c *Controller) Solve(ctx context.Context, req *controlapi.SolveRequest) (*
}
}

if v, ok := req.FrontendAttrs["build-arg:BUILDKIT_BUILDINFO"]; ok && v != "" {
if _, ok := req.ExporterAttrs["buildinfo"]; !ok {
if req.ExporterAttrs == nil {
req.ExporterAttrs = make(map[string]string)
}
req.ExporterAttrs["buildinfo"] = v
}
}

if req.Exporter != "" {
exp, err := w.Exporter(req.Exporter, c.opt.SessionManager)
if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions docs/deprecated.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,6 @@ With the introduction of [provenance attestations](./attestations/slsa-provenanc
in [BuildKit v0.11.0](https://github.com/moby/buildkit/releases/tag/v0.11.0),
the build information feature has been deprecated and will be removed in the
next release.

To completely disable the build information feature, set the build-arg
`BUILDKIT_BUILDINFO=false`.
25 changes: 13 additions & 12 deletions frontend/dockerfile/docs/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -2213,21 +2213,22 @@ RUN echo "I'm building for $TARGETPLATFORM"

### BuildKit built-in build args

| Arg | Type | Description |
|---------------------------------------|--------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `BUILDKIT_CACHE_MOUNT_NS` | String | Set optional cache ID namespace. |
| `BUILDKIT_CONTEXT_KEEP_GIT_DIR` | Bool | Trigger git context to keep the `.git` directory. |
| `BUILDKIT_INLINE_BUILDINFO_ATTRS`[^2] | Bool | Inline build info attributes in image config or not. |
| `BUILDKIT_INLINE_CACHE`[^2] | Bool | Inline cache metadata to image config or not. |
| `BUILDKIT_MULTI_PLATFORM` | Bool | Opt into determnistic output regardless of multi-platform output or not. |
| `BUILDKIT_SANDBOX_HOSTNAME` | String | Set the hostname (default `buildkitsandbox`) |
| `BUILDKIT_SYNTAX` | String | Set frontend image |
| `SOURCE_DATE_EPOCH` | Int | Set the UNIX timestamp for created image and layers. More info from [reproducible builds](https://reproducible-builds.org/docs/source-date-epoch/). Supported since Dockerfile 1.5, BuildKit 0.11 |
| Arg | Type | Description |
|---------------------------------------|--------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `BUILDKIT_CACHE_MOUNT_NS` | String | Set optional cache ID namespace. |
| `BUILDKIT_CONTEXT_KEEP_GIT_DIR` | Bool | Trigger git context to keep the `.git` directory. |
| `BUILDKIT_BUILDINFO` | Bool | Enable build info (default `true`). |
| `BUILDKIT_INLINE_BUILDINFO_ATTRS`[^2] | Bool | Inline build info attributes in image config or not. |
| `BUILDKIT_INLINE_CACHE`[^2] | Bool | Inline cache metadata to image config or not. |
| `BUILDKIT_MULTI_PLATFORM` | Bool | Opt into determnistic output regardless of multi-platform output or not. |
| `BUILDKIT_SANDBOX_HOSTNAME` | String | Set the hostname (default `buildkitsandbox`) |
| `BUILDKIT_SYNTAX` | String | Set frontend image |
| `SOURCE_DATE_EPOCH` | Int | Set the UNIX timestamp for created image and layers. More info from [reproducible builds](https://reproducible-builds.org/docs/source-date-epoch/). Supported since Dockerfile 1.5, BuildKit 0.11 |

> **Warning**
>
> Build information along `BUILDKIT_INLINE_BUILDINFO_ATTRS` build arg are
> deprecated and will be removed in the next release. See the [BuildKit Deprecated features page](https://github.com/moby/buildkit/blob/master/docs/deprecated.md)
> Build information along `BUILDKIT_BUILDINFO` and `BUILDKIT_INLINE_BUILDINFO_ATTRS`
> build args are deprecated and will be removed in the next release. See the [BuildKit Deprecated features page](https://github.com/moby/buildkit/blob/master/docs/deprecated.md)
> for status and alternative recommendation about this feature.
#### Example: keep `.git` dir
Expand Down
1 change: 1 addition & 0 deletions util/buildinfo/buildinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,7 @@ func filterAttrs(key string, attrs map[string]*string) map[string]*string {
var knownControlArgs = []string{
"BUILDKIT_CACHE_MOUNT_NS",
"BUILDKIT_CONTEXT_KEEP_GIT_DIR",
"BUILDKIT_BUILDINFO",
"BUILDKIT_INLINE_BUILDINFO_ATTRS",
"BUILDKIT_INLINE_CACHE",
"BUILDKIT_MULTI_PLATFORM",
Expand Down

0 comments on commit 837b4b2

Please sign in to comment.