Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

buildinfo: named input contexts support #2654

Merged
merged 3 commits into from
Feb 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5194,12 +5194,13 @@ func testBuildInfoInline(t *testing.T, sb integration.Sandbox) {
require.NoError(t, err)

var config binfotypes.ImageConfig
err = json.Unmarshal(dt, &config)
require.NoError(t, json.Unmarshal(dt, &config))

dec, err := base64.StdEncoding.DecodeString(config.BuildInfo)
require.NoError(t, err)

var bi binfotypes.BuildInfo
err = json.Unmarshal(config.BuildInfo, &bi)
require.NoError(t, err)
require.NoError(t, json.Unmarshal(dec, &bi))

if tt.buildAttrs {
attrval := "bar"
Expand Down
29 changes: 16 additions & 13 deletions docs/build-repro.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,6 @@ Build dependencies are generated when your image has been built. These
dependencies include versions of used images, git repositories and HTTP URLs
used by LLB `Source` operation as well as build request attributes.

By default, the build dependencies are inlined in the image configuration. You
can disable this behavior with the [`buildinfo` attribute](../README.md#imageregistry).

### Image config

A new field similar to the one for inline cache has been added to the image
configuration to embed build dependencies:

```text
"moby.buildkit.buildinfo.v1": <base64>
```

The structure is base64 encoded and has the following format when decoded:

```json
Expand Down Expand Up @@ -57,10 +45,25 @@ The structure is base64 encoded and has the following format when decoded:

* `frontend` defines the frontend used to build.
* `attrs` defines build request attributes.
* `sources` defines build dependencies.
* `sources` defines build sources.
* `type` defines the source type (`docker-image`, `git` or `http`).
* `ref` is the reference of the source.
* `pin` is the source digest.
* `deps` defines build dependencies of input contexts.

### Image config

A new field similar to the one for inline cache has been added to the image
configuration to embed build dependencies:

```json
{
"moby.buildkit.buildinfo.v0": "<base64>"
}
```

By default, the build dependencies are inlined in the image configuration. You
can disable this behavior with the [`buildinfo` attribute](../README.md#imageregistry).

### Exporter response (metadata)

Expand Down
14 changes: 7 additions & 7 deletions frontend/dockerfile/dockerfile2llb/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,16 +382,16 @@ func Dockerfile2LLB(ctx context.Context, dt []byte, opt ConvertOpt) (*llb.State,

buildContext := &mutableOutput{}
ctxPaths := map[string]struct{}{}
buildinfo := &binfotypes.BuildInfo{}
buildInfo := &binfotypes.BuildInfo{}

for _, d := range allDispatchStates.states {
if !isReachable(target, d) {
continue
}

// collect build dependencies
// collect build sources and dependencies
if d.buildSource != nil {
buildinfo.Sources = append(buildinfo.Sources, *d.buildSource)
buildInfo.Sources = append(buildInfo.Sources, *d.buildSource)
}

if d.base != nil {
Expand Down Expand Up @@ -469,9 +469,9 @@ func Dockerfile2LLB(ctx context.Context, dt []byte, opt ConvertOpt) (*llb.State,
}

// sort build sources
if len(buildinfo.Sources) > 0 {
sort.Slice(buildinfo.Sources, func(i, j int) bool {
return buildinfo.Sources[i].Ref < buildinfo.Sources[j].Ref
if len(buildInfo.Sources) > 0 {
sort.Slice(buildInfo.Sources, func(i, j int) bool {
return buildInfo.Sources[i].Ref < buildInfo.Sources[j].Ref
})
}

Expand Down Expand Up @@ -512,7 +512,7 @@ func Dockerfile2LLB(ctx context.Context, dt []byte, opt ConvertOpt) (*llb.State,
target.image.Variant = platformOpt.targetPlatform.Variant
}

return &st, &target.image, buildinfo, nil
return &st, &target.image, buildInfo, nil
}

func metaArgsToMap(metaArgs []instructions.KeyValuePairOptional) map[string]string {
Expand Down
Loading