diff --git a/exporter/containerimage/exptypes/types.go b/exporter/containerimage/exptypes/types.go index eddb4d30fbe5e..b98bf97d5a006 100644 --- a/exporter/containerimage/exptypes/types.go +++ b/exporter/containerimage/exptypes/types.go @@ -26,15 +26,26 @@ type Platform struct { Platform ocispecs.Platform } +// BuildInfo defines build dependencies that will be added to image config as +// moby.buildkit.buildinfo.v0 key and returned in solver ExporterResponse as +// ExporterBuildInfo key. type BuildInfo struct { - Type BuildInfoType `json:"type,omitempty"` - Ref string `json:"ref,omitempty"` - Alias string `json:"alias,omitempty"` - Pin string `json:"pin,omitempty"` + // Type defines the BuildInfoType source type (docker-image, git, http). + Type BuildInfoType `json:"type,omitempty"` + // Ref is the reference of the source type. + Ref string `json:"ref,omitempty"` + // Alias is a special field used to match with the actual source ref + // because frontend might have already transformed a string user typed + // before generating LLB. + Alias string `json:"alias,omitempty"` + // Pin is the source digest. + Pin string `json:"pin,omitempty"` } +// BuildInfoType contains source type. type BuildInfoType string +// List of source types. const ( BuildInfoTypeDockerImage BuildInfoType = "docker-image" BuildInfoTypeGit BuildInfoType = "git" diff --git a/frontend/dockerfile/dockerfile2llb/convert.go b/frontend/dockerfile/dockerfile2llb/convert.go index c7de217d42891..66bf33c560381 100644 --- a/frontend/dockerfile/dockerfile2llb/convert.go +++ b/frontend/dockerfile/dockerfile2llb/convert.go @@ -295,6 +295,8 @@ func Dockerfile2LLB(ctx context.Context, dt []byte, opt ConvertOpt) (*llb.State, } } if !isScratch { + // image not scratch set original image name as ref + // and actual reference as alias in BuildInfo d.buildInfo = &exptypes.BuildInfo{ Type: exptypes.BuildInfoTypeDockerImage, Ref: origName, @@ -411,7 +413,7 @@ func Dockerfile2LLB(ctx context.Context, dt []byte, opt ConvertOpt) (*llb.State, } } - // Set target with gathered build dependencies + // set target with gathered build dependencies target.image.BuildInfo = []byte{} if len(buildInfos) > 0 { target.image.BuildInfo, err = json.Marshal(buildInfos) diff --git a/frontend/dockerfile/dockerfile2llb/image.go b/frontend/dockerfile/dockerfile2llb/image.go index 418d2b503a582..c252332d4c73f 100644 --- a/frontend/dockerfile/dockerfile2llb/image.go +++ b/frontend/dockerfile/dockerfile2llb/image.go @@ -54,7 +54,7 @@ type Image struct { // Variant defines platform variant. To be added to OCI. Variant string `json:"variant,omitempty"` - // BuildInfo defines build dependencies + // BuildInfo defines build dependencies. BuildInfo []byte `json:"moby.buildkit.buildinfo.v0,omitempty"` }