Skip to content

Commit

Permalink
buildinfo: handle deps
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 19, 2022
1 parent 292c0bf commit c8429c0
Show file tree
Hide file tree
Showing 7 changed files with 423 additions and 38 deletions.
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 from named 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

0 comments on commit c8429c0

Please sign in to comment.