mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
builder-next: allow outputs configuration
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
This commit is contained in:
parent
36d2c8b48e
commit
768c6d7b29
6 changed files with 55 additions and 3 deletions
|
@ -148,6 +148,17 @@ func newImageBuildOptions(ctx context.Context, r *http.Request) (*types.ImageBui
|
||||||
}
|
}
|
||||||
options.Version = builderVersion
|
options.Version = builderVersion
|
||||||
|
|
||||||
|
if versions.GreaterThanOrEqualTo(version, "1.40") {
|
||||||
|
outputsJSON := r.FormValue("outputs")
|
||||||
|
if outputsJSON != "" {
|
||||||
|
var outputs []types.ImageBuildOutput
|
||||||
|
if err := json.Unmarshal([]byte(outputsJSON), &outputs); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
options.Outputs = outputs
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return options, nil
|
return options, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6459,6 +6459,11 @@ paths:
|
||||||
description: "Target build stage"
|
description: "Target build stage"
|
||||||
type: "string"
|
type: "string"
|
||||||
default: ""
|
default: ""
|
||||||
|
- name: "outputs"
|
||||||
|
in: "query"
|
||||||
|
description: "BuildKit output configuration"
|
||||||
|
type: "string"
|
||||||
|
default: ""
|
||||||
responses:
|
responses:
|
||||||
200:
|
200:
|
||||||
description: "no error"
|
description: "no error"
|
||||||
|
|
|
@ -187,6 +187,15 @@ type ImageBuildOptions struct {
|
||||||
// build request. The same identifier can be used to gracefully cancel the
|
// build request. The same identifier can be used to gracefully cancel the
|
||||||
// build with the cancel request.
|
// build with the cancel request.
|
||||||
BuildID string
|
BuildID string
|
||||||
|
// Outputs defines configurations for exporting build results. Only supported
|
||||||
|
// in BuildKit mode
|
||||||
|
Outputs []ImageBuildOutput
|
||||||
|
}
|
||||||
|
|
||||||
|
// ImageBuildOutput defines configuration for exporting a build result
|
||||||
|
type ImageBuildOutput struct {
|
||||||
|
Type string
|
||||||
|
Attrs map[string]string
|
||||||
}
|
}
|
||||||
|
|
||||||
// BuilderVersion sets the version of underlying builder to use
|
// BuilderVersion sets the version of underlying builder to use
|
||||||
|
|
|
@ -313,10 +313,25 @@ func (b *Builder) Build(ctx context.Context, opt backend.BuildConfig) (*builder.
|
||||||
}
|
}
|
||||||
frontendAttrs["add-hosts"] = extraHosts
|
frontendAttrs["add-hosts"] = extraHosts
|
||||||
|
|
||||||
|
exporterName := ""
|
||||||
exporterAttrs := map[string]string{}
|
exporterAttrs := map[string]string{}
|
||||||
|
|
||||||
if len(opt.Options.Tags) > 0 {
|
if len(opt.Options.Outputs) > 1 {
|
||||||
exporterAttrs["name"] = strings.Join(opt.Options.Tags, ",")
|
return nil, errors.Errorf("multiple outputs not supported")
|
||||||
|
} else if len(opt.Options.Outputs) == 0 {
|
||||||
|
exporterName = "moby"
|
||||||
|
} else {
|
||||||
|
// cacheonly is a special type for triggering skipping all exporters
|
||||||
|
if opt.Options.Outputs[0].Type != "cacheonly" {
|
||||||
|
exporterName = opt.Options.Outputs[0].Type
|
||||||
|
exporterAttrs = opt.Options.Outputs[0].Attrs
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if exporterName == "moby" {
|
||||||
|
if len(opt.Options.Tags) > 0 {
|
||||||
|
exporterAttrs["name"] = strings.Join(opt.Options.Tags, ",")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cache := controlapi.CacheOptions{}
|
cache := controlapi.CacheOptions{}
|
||||||
|
@ -331,7 +346,7 @@ func (b *Builder) Build(ctx context.Context, opt backend.BuildConfig) (*builder.
|
||||||
|
|
||||||
req := &controlapi.SolveRequest{
|
req := &controlapi.SolveRequest{
|
||||||
Ref: id,
|
Ref: id,
|
||||||
Exporter: "moby",
|
Exporter: exporterName,
|
||||||
ExporterAttrs: exporterAttrs,
|
ExporterAttrs: exporterAttrs,
|
||||||
Frontend: "dockerfile.v0",
|
Frontend: "dockerfile.v0",
|
||||||
FrontendAttrs: frontendAttrs,
|
FrontendAttrs: frontendAttrs,
|
||||||
|
@ -352,6 +367,9 @@ func (b *Builder) Build(ctx context.Context, opt backend.BuildConfig) (*builder.
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
if exporterName != "moby" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
id, ok := resp.ExporterResponse["containerimage.digest"]
|
id, ok := resp.ExporterResponse["containerimage.digest"]
|
||||||
if !ok {
|
if !ok {
|
||||||
return errors.Errorf("missing image id")
|
return errors.Errorf("missing image id")
|
||||||
|
|
|
@ -134,5 +134,13 @@ func (cli *Client) imageBuildOptionsToQuery(options types.ImageBuildOptions) (ur
|
||||||
query.Set("buildid", options.BuildID)
|
query.Set("buildid", options.BuildID)
|
||||||
}
|
}
|
||||||
query.Set("version", string(options.Version))
|
query.Set("version", string(options.Version))
|
||||||
|
|
||||||
|
if options.Outputs != nil {
|
||||||
|
outputsJSON, err := json.Marshal(options.Outputs)
|
||||||
|
if err != nil {
|
||||||
|
return query, err
|
||||||
|
}
|
||||||
|
query.Set("outputs", string(outputsJSON))
|
||||||
|
}
|
||||||
return query, nil
|
return query, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,6 +65,7 @@ keywords: "API, Docker, rcli, REST, documentation"
|
||||||
back to `shareable` by using `DefaultIpcMode` daemon configuration parameter.
|
back to `shareable` by using `DefaultIpcMode` daemon configuration parameter.
|
||||||
* `POST /containers/{id}/update` now accepts a `PidsLimit` field to tune a container's
|
* `POST /containers/{id}/update` now accepts a `PidsLimit` field to tune a container's
|
||||||
PID limit. Set `0` or `-1` for unlimited. Leave `null` to not change the current value.
|
PID limit. Set `0` or `-1` for unlimited. Leave `null` to not change the current value.
|
||||||
|
* `POST /build` now accepts `outputs` key for configuring build outputs when using BuildKit mode.
|
||||||
|
|
||||||
## V1.39 API changes
|
## V1.39 API changes
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue