MCPcopy
hub / github.com/moby/moby / ImageBuild

Method ImageBuild

client/image_build.go:20–43  ·  view source on GitHub ↗

ImageBuild sends a request to the daemon to build images. The Body in the response implements an [io.ReadCloser] and it's up to the caller to close it.

(ctx context.Context, buildContext io.Reader, options ImageBuildOptions)

Source from the content-addressed store, hash-verified

18// The Body in the response implements an [io.ReadCloser] and it's up to the caller to
19// close it.
20func (cli *Client) ImageBuild(ctx context.Context, buildContext io.Reader, options ImageBuildOptions) (ImageBuildResult, error) {
21 query, err := cli.imageBuildOptionsToQuery(ctx, options)
22 if err != nil {
23 return ImageBuildResult{}, err
24 }
25
26 buf, err := json.Marshal(options.AuthConfigs) // #nosec G117 -- ignore "Marshaled struct field "Password" (JSON key "password") matches secret pattern"
27 if err != nil {
28 return ImageBuildResult{}, err
29 }
30
31 headers := http.Header{}
32 headers.Add("X-Registry-Config", base64.URLEncoding.EncodeToString(buf))
33 headers.Set("Content-Type", "application/x-tar")
34
35 resp, err := cli.postRaw(ctx, "/build", query, buildContext, headers)
36 if err != nil {
37 return ImageBuildResult{}, err
38 }
39
40 return ImageBuildResult{
41 Body: resp.Body,
42 }, nil
43}
44
45func (cli *Client) imageBuildOptionsToQuery(_ context.Context, options ImageBuildOptions) (url.Values, error) {
46 query := url.Values{}

Callers

nothing calls this directly

Calls 5

postRawMethod · 0.95
AddMethod · 0.65
SetMethod · 0.65
MarshalMethod · 0.45

Tested by

no test coverage detected