Browse code

api/types/build: move build options to client and backend

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>

Sebastiaan van Stijn authored on 2025/09/05 21:35:26
Showing 27 changed files
... ...
@@ -1,12 +1,5 @@
1 1
 package build
2 2
 
3
-import (
4
-	"io"
5
-
6
-	"github.com/moby/moby/api/types/container"
7
-	"github.com/moby/moby/api/types/registry"
8
-)
9
-
10 3
 // BuilderVersion sets the version of underlying builder to use
11 4
 type BuilderVersion string
12 5
 
... ...
@@ -21,71 +14,3 @@ const (
21 21
 type Result struct {
22 22
 	ID string
23 23
 }
24
-
25
-// ImageBuildOptions holds the information
26
-// necessary to build images.
27
-type ImageBuildOptions struct {
28
-	Tags           []string
29
-	SuppressOutput bool
30
-	RemoteContext  string
31
-	NoCache        bool
32
-	Remove         bool
33
-	ForceRemove    bool
34
-	PullParent     bool
35
-	Isolation      container.Isolation
36
-	CPUSetCPUs     string
37
-	CPUSetMems     string
38
-	CPUShares      int64
39
-	CPUQuota       int64
40
-	CPUPeriod      int64
41
-	Memory         int64
42
-	MemorySwap     int64
43
-	CgroupParent   string
44
-	NetworkMode    string
45
-	ShmSize        int64
46
-	Dockerfile     string
47
-	Ulimits        []*container.Ulimit
48
-	// BuildArgs needs to be a *string instead of just a string so that
49
-	// we can tell the difference between "" (empty string) and no value
50
-	// at all (nil). See the parsing of buildArgs in
51
-	// api/server/router/build/build_routes.go for even more info.
52
-	BuildArgs   map[string]*string
53
-	AuthConfigs map[string]registry.AuthConfig
54
-	Context     io.Reader
55
-	Labels      map[string]string
56
-	// squash the resulting image's layers to the parent
57
-	// preserves the original image and creates a new one from the parent with all
58
-	// the changes applied to a single layer
59
-	Squash bool
60
-	// CacheFrom specifies images that are used for matching cache. Images
61
-	// specified here do not need to have a valid parent chain to match cache.
62
-	CacheFrom   []string
63
-	SecurityOpt []string
64
-	ExtraHosts  []string // List of extra hosts
65
-	Target      string
66
-	SessionID   string
67
-	Platform    string
68
-	// Version specifies the version of the underlying builder to use
69
-	Version BuilderVersion
70
-	// BuildID is an optional identifier that can be passed together with the
71
-	// build request. The same identifier can be used to gracefully cancel the
72
-	// build with the cancel request.
73
-	BuildID string
74
-	// Outputs defines configurations for exporting build results. Only supported
75
-	// in BuildKit mode
76
-	Outputs []ImageBuildOutput
77
-}
78
-
79
-// ImageBuildOutput defines configuration for exporting a build result
80
-type ImageBuildOutput struct {
81
-	Type  string
82
-	Attrs map[string]string
83
-}
84
-
85
-// ImageBuildResponse holds information
86
-// returned by a server after building
87
-// an image.
88
-type ImageBuildResponse struct {
89
-	Body   io.ReadCloser
90
-	OSType string
91
-}
... ...
@@ -106,7 +106,7 @@ type DistributionAPIClient interface {
106 106
 
107 107
 // ImageAPIClient defines API client methods for the images
108 108
 type ImageAPIClient interface {
109
-	ImageBuild(ctx context.Context, context io.Reader, options build.ImageBuildOptions) (build.ImageBuildResponse, error)
109
+	ImageBuild(ctx context.Context, context io.Reader, options ImageBuildOptions) (ImageBuildResponse, error)
110 110
 	BuildCachePrune(ctx context.Context, opts BuildCachePruneOptions) (*build.CachePruneReport, error)
111 111
 	BuildCancel(ctx context.Context, id string) error
112 112
 	ImageCreate(ctx context.Context, parentReference string, options ImageCreateOptions) (io.ReadCloser, error)
... ...
@@ -10,7 +10,6 @@ import (
10 10
 	"strconv"
11 11
 	"strings"
12 12
 
13
-	"github.com/moby/moby/api/types/build"
14 13
 	"github.com/moby/moby/api/types/container"
15 14
 	"github.com/moby/moby/api/types/network"
16 15
 )
... ...
@@ -18,15 +17,15 @@ import (
18 18
 // ImageBuild sends a request to the daemon to build images.
19 19
 // The Body in the response implements an [io.ReadCloser] and it's up to the caller to
20 20
 // close it.
21
-func (cli *Client) ImageBuild(ctx context.Context, buildContext io.Reader, options build.ImageBuildOptions) (build.ImageBuildResponse, error) {
21
+func (cli *Client) ImageBuild(ctx context.Context, buildContext io.Reader, options ImageBuildOptions) (ImageBuildResponse, error) {
22 22
 	query, err := cli.imageBuildOptionsToQuery(ctx, options)
23 23
 	if err != nil {
24
-		return build.ImageBuildResponse{}, err
24
+		return ImageBuildResponse{}, err
25 25
 	}
26 26
 
27 27
 	buf, err := json.Marshal(options.AuthConfigs)
28 28
 	if err != nil {
29
-		return build.ImageBuildResponse{}, err
29
+		return ImageBuildResponse{}, err
30 30
 	}
31 31
 
32 32
 	headers := http.Header{}
... ...
@@ -35,16 +34,16 @@ func (cli *Client) ImageBuild(ctx context.Context, buildContext io.Reader, optio
35 35
 
36 36
 	resp, err := cli.postRaw(ctx, "/build", query, buildContext, headers)
37 37
 	if err != nil {
38
-		return build.ImageBuildResponse{}, err
38
+		return ImageBuildResponse{}, err
39 39
 	}
40 40
 
41
-	return build.ImageBuildResponse{
41
+	return ImageBuildResponse{
42 42
 		Body:   resp.Body,
43 43
 		OSType: resp.Header.Get("Ostype"),
44 44
 	}, nil
45 45
 }
46 46
 
47
-func (cli *Client) imageBuildOptionsToQuery(ctx context.Context, options build.ImageBuildOptions) (url.Values, error) {
47
+func (cli *Client) imageBuildOptionsToQuery(ctx context.Context, options ImageBuildOptions) (url.Values, error) {
48 48
 	query := url.Values{}
49 49
 	if len(options.Tags) > 0 {
50 50
 		query["t"] = options.Tags
51 51
new file mode 100644
... ...
@@ -0,0 +1,77 @@
0
+package client
1
+
2
+import (
3
+	"io"
4
+
5
+	"github.com/moby/moby/api/types/build"
6
+	"github.com/moby/moby/api/types/container"
7
+	"github.com/moby/moby/api/types/registry"
8
+)
9
+
10
+// ImageBuildOptions holds the information
11
+// necessary to build images.
12
+type ImageBuildOptions struct {
13
+	Tags           []string
14
+	SuppressOutput bool
15
+	RemoteContext  string
16
+	NoCache        bool
17
+	Remove         bool
18
+	ForceRemove    bool
19
+	PullParent     bool
20
+	Isolation      container.Isolation
21
+	CPUSetCPUs     string
22
+	CPUSetMems     string
23
+	CPUShares      int64
24
+	CPUQuota       int64
25
+	CPUPeriod      int64
26
+	Memory         int64
27
+	MemorySwap     int64
28
+	CgroupParent   string
29
+	NetworkMode    string
30
+	ShmSize        int64
31
+	Dockerfile     string
32
+	Ulimits        []*container.Ulimit
33
+	// BuildArgs needs to be a *string instead of just a string so that
34
+	// we can tell the difference between "" (empty string) and no value
35
+	// at all (nil). See the parsing of buildArgs in
36
+	// api/server/router/build/build_routes.go for even more info.
37
+	BuildArgs   map[string]*string
38
+	AuthConfigs map[string]registry.AuthConfig
39
+	Context     io.Reader
40
+	Labels      map[string]string
41
+	// squash the resulting image's layers to the parent
42
+	// preserves the original image and creates a new one from the parent with all
43
+	// the changes applied to a single layer
44
+	Squash bool
45
+	// CacheFrom specifies images that are used for matching cache. Images
46
+	// specified here do not need to have a valid parent chain to match cache.
47
+	CacheFrom   []string
48
+	SecurityOpt []string
49
+	ExtraHosts  []string // List of extra hosts
50
+	Target      string
51
+	SessionID   string
52
+	Platform    string
53
+	// Version specifies the version of the underlying builder to use
54
+	Version build.BuilderVersion
55
+	// BuildID is an optional identifier that can be passed together with the
56
+	// build request. The same identifier can be used to gracefully cancel the
57
+	// build with the cancel request.
58
+	BuildID string
59
+	// Outputs defines configurations for exporting build results. Only supported
60
+	// in BuildKit mode
61
+	Outputs []ImageBuildOutput
62
+}
63
+
64
+// ImageBuildOutput defines configuration for exporting a build result
65
+type ImageBuildOutput struct {
66
+	Type  string
67
+	Attrs map[string]string
68
+}
69
+
70
+// ImageBuildResponse holds information
71
+// returned by a server after building
72
+// an image.
73
+type ImageBuildResponse struct {
74
+	Body   io.ReadCloser
75
+	OSType string
76
+}
... ...
@@ -11,7 +11,6 @@ import (
11 11
 	"testing"
12 12
 
13 13
 	cerrdefs "github.com/containerd/errdefs"
14
-	"github.com/moby/moby/api/types/build"
15 14
 	"github.com/moby/moby/api/types/container"
16 15
 	"github.com/moby/moby/api/types/registry"
17 16
 	"gotest.tools/v3/assert"
... ...
@@ -21,7 +20,7 @@ import (
21 21
 func TestImageBuildError(t *testing.T) {
22 22
 	client, err := NewClientWithOpts(WithMockClient(errorMock(http.StatusInternalServerError, "Server error")))
23 23
 	assert.NilError(t, err)
24
-	_, err = client.ImageBuild(context.Background(), nil, build.ImageBuildOptions{})
24
+	_, err = client.ImageBuild(context.Background(), nil, ImageBuildOptions{})
25 25
 	assert.Check(t, is.ErrorType(err, cerrdefs.IsInternal))
26 26
 }
27 27
 
... ...
@@ -30,13 +29,13 @@ func TestImageBuild(t *testing.T) {
30 30
 	v2 := "value2"
31 31
 	emptyRegistryConfig := "bnVsbA=="
32 32
 	buildCases := []struct {
33
-		buildOptions           build.ImageBuildOptions
33
+		buildOptions           ImageBuildOptions
34 34
 		expectedQueryParams    map[string]string
35 35
 		expectedTags           []string
36 36
 		expectedRegistryConfig string
37 37
 	}{
38 38
 		{
39
-			buildOptions: build.ImageBuildOptions{
39
+			buildOptions: ImageBuildOptions{
40 40
 				SuppressOutput: true,
41 41
 				NoCache:        true,
42 42
 				Remove:         true,
... ...
@@ -53,7 +52,7 @@ func TestImageBuild(t *testing.T) {
53 53
 			expectedRegistryConfig: emptyRegistryConfig,
54 54
 		},
55 55
 		{
56
-			buildOptions: build.ImageBuildOptions{
56
+			buildOptions: ImageBuildOptions{
57 57
 				SuppressOutput: false,
58 58
 				NoCache:        false,
59 59
 				Remove:         false,
... ...
@@ -71,7 +70,7 @@ func TestImageBuild(t *testing.T) {
71 71
 			expectedRegistryConfig: emptyRegistryConfig,
72 72
 		},
73 73
 		{
74
-			buildOptions: build.ImageBuildOptions{
74
+			buildOptions: ImageBuildOptions{
75 75
 				RemoteContext: "remoteContext",
76 76
 				Isolation:     container.Isolation("isolation"),
77 77
 				CPUSetCPUs:    "2",
... ...
@@ -104,7 +103,7 @@ func TestImageBuild(t *testing.T) {
104 104
 			expectedRegistryConfig: emptyRegistryConfig,
105 105
 		},
106 106
 		{
107
-			buildOptions: build.ImageBuildOptions{
107
+			buildOptions: ImageBuildOptions{
108 108
 				BuildArgs: map[string]*string{
109 109
 					"ARG1": &v1,
110 110
 					"ARG2": &v2,
... ...
@@ -119,7 +118,7 @@ func TestImageBuild(t *testing.T) {
119 119
 			expectedRegistryConfig: emptyRegistryConfig,
120 120
 		},
121 121
 		{
122
-			buildOptions: build.ImageBuildOptions{
122
+			buildOptions: ImageBuildOptions{
123 123
 				Ulimits: []*container.Ulimit{
124 124
 					{
125 125
 						Name: "nproc",
... ...
@@ -141,7 +140,7 @@ func TestImageBuild(t *testing.T) {
141 141
 			expectedRegistryConfig: emptyRegistryConfig,
142 142
 		},
143 143
 		{
144
-			buildOptions: build.ImageBuildOptions{
144
+			buildOptions: ImageBuildOptions{
145 145
 				AuthConfigs: map[string]registry.AuthConfig{
146 146
 					"https://index.docker.io/v1/": {
147 147
 						Auth: "dG90bwo=",
... ...
@@ -98,7 +98,7 @@ func (bm *BuildManager) Build(ctx context.Context, config buildbackend.BuildConf
98 98
 
99 99
 // builderOptions are the dependencies required by the builder
100 100
 type builderOptions struct {
101
-	Options        *build.ImageBuildOptions
101
+	Options        *buildbackend.BuildOptions
102 102
 	Backend        builder.Backend
103 103
 	ProgressWriter buildbackend.ProgressWriter
104 104
 	PathCache      pathCache
... ...
@@ -108,7 +108,7 @@ type builderOptions struct {
108 108
 // Builder is a Dockerfile builder
109 109
 // It implements the builder.Backend interface.
110 110
 type Builder struct {
111
-	options *build.ImageBuildOptions
111
+	options *buildbackend.BuildOptions
112 112
 
113 113
 	Stdout io.Writer
114 114
 	Stderr io.Writer
... ...
@@ -130,7 +130,7 @@ type Builder struct {
130 130
 func newBuilder(ctx context.Context, options builderOptions) (*Builder, error) {
131 131
 	config := options.Options
132 132
 	if config == nil {
133
-		config = new(build.ImageBuildOptions)
133
+		config = &buildbackend.BuildOptions{}
134 134
 	}
135 135
 
136 136
 	imgProber, err := newImageProber(ctx, options.Backend, config.CacheFrom, config.NoCache)
... ...
@@ -343,7 +343,7 @@ func BuildFromConfig(ctx context.Context, config *container.Config, changes []st
343 343
 	}
344 344
 
345 345
 	b, err := newBuilder(ctx, builderOptions{
346
-		Options: &build.ImageBuildOptions{NoCache: true},
346
+		Options: &buildbackend.BuildOptions{NoCache: true},
347 347
 	})
348 348
 	if err != nil {
349 349
 		return nil, err
... ...
@@ -11,12 +11,12 @@ import (
11 11
 	"github.com/moby/buildkit/frontend/dockerfile/instructions"
12 12
 	"github.com/moby/buildkit/frontend/dockerfile/parser"
13 13
 	"github.com/moby/buildkit/frontend/dockerfile/shell"
14
-	"github.com/moby/moby/api/types/build"
15 14
 	"github.com/moby/moby/api/types/container"
16 15
 	"github.com/moby/moby/v2/daemon/builder"
17 16
 	"github.com/moby/moby/v2/daemon/internal/image"
18 17
 	"github.com/moby/moby/v2/daemon/pkg/oci"
19 18
 	"github.com/moby/moby/v2/daemon/server/backend"
19
+	"github.com/moby/moby/v2/daemon/server/buildbackend"
20 20
 	"gotest.tools/v3/assert"
21 21
 	is "gotest.tools/v3/assert/cmp"
22 22
 )
... ...
@@ -24,19 +24,18 @@ import (
24 24
 func newBuilderWithMockBackend(t *testing.T) *Builder {
25 25
 	t.Helper()
26 26
 	mockBackend := &MockBackend{}
27
-	opts := &build.ImageBuildOptions{}
28 27
 	ctx := context.Background()
29 28
 
30 29
 	imageProber, err := newImageProber(ctx, mockBackend, nil, false)
31 30
 	assert.NilError(t, err, "Could not create image prober")
32 31
 
33 32
 	b := &Builder{
34
-		options:       opts,
33
+		options:       &buildbackend.BuildOptions{},
35 34
 		docker:        mockBackend,
36 35
 		Stdout:        new(bytes.Buffer),
37 36
 		disableCommit: true,
38 37
 		imageSources: newImageSources(builderOptions{
39
-			Options: opts,
38
+			Options: &buildbackend.BuildOptions{},
40 39
 			Backend: mockBackend,
41 40
 		}),
42 41
 		imageProber:      imageProber,
... ...
@@ -16,7 +16,6 @@ import (
16 16
 	"github.com/containerd/platforms"
17 17
 	"github.com/moby/go-archive"
18 18
 	"github.com/moby/go-archive/chrootarchive"
19
-	"github.com/moby/moby/api/types/build"
20 19
 	"github.com/moby/moby/api/types/container"
21 20
 	"github.com/moby/moby/api/types/network"
22 21
 	"github.com/moby/moby/v2/daemon/builder"
... ...
@@ -24,6 +23,7 @@ import (
24 24
 	"github.com/moby/moby/v2/daemon/internal/stringid"
25 25
 	networkSettings "github.com/moby/moby/v2/daemon/network"
26 26
 	"github.com/moby/moby/v2/daemon/server/backend"
27
+	"github.com/moby/moby/v2/daemon/server/buildbackend"
27 28
 	ocispec "github.com/opencontainers/image-spec/specs-go/v1"
28 29
 	"github.com/pkg/errors"
29 30
 )
... ...
@@ -340,7 +340,7 @@ func (b *Builder) create(ctx context.Context, runConfig *container.Config) (stri
340 340
 	return ctr.ID, nil
341 341
 }
342 342
 
343
-func hostConfigFromOptions(options *build.ImageBuildOptions) *container.HostConfig {
343
+func hostConfigFromOptions(options *buildbackend.BuildOptions) *container.HostConfig {
344 344
 	resources := container.Resources{
345 345
 		CgroupParent: options.CgroupParent,
346 346
 		CPUShares:    options.CPUShares,
... ...
@@ -6,7 +6,7 @@ import (
6 6
 	"path/filepath"
7 7
 	"testing"
8 8
 
9
-	"github.com/moby/moby/api/types/build"
9
+	"github.com/moby/moby/v2/daemon/server/buildbackend"
10 10
 	"github.com/moby/sys/user"
11 11
 	"gotest.tools/v3/assert"
12 12
 	is "gotest.tools/v3/assert/cmp"
... ...
@@ -58,7 +58,7 @@ othergrp:x:6666:
58 58
 		expected  identity
59 59
 	}{
60 60
 		{
61
-			builder:   &Builder{options: &build.ImageBuildOptions{Platform: "linux"}},
61
+			builder:   &Builder{options: &buildbackend.BuildOptions{Platform: "linux"}},
62 62
 			name:      "UIDNoMap",
63 63
 			chownStr:  "1",
64 64
 			idMapping: unmapped,
... ...
@@ -66,7 +66,7 @@ othergrp:x:6666:
66 66
 			expected:  identity{UID: 1, GID: 1},
67 67
 		},
68 68
 		{
69
-			builder:   &Builder{options: &build.ImageBuildOptions{Platform: "linux"}},
69
+			builder:   &Builder{options: &buildbackend.BuildOptions{Platform: "linux"}},
70 70
 			name:      "UIDGIDNoMap",
71 71
 			chownStr:  "0:1",
72 72
 			idMapping: unmapped,
... ...
@@ -74,7 +74,7 @@ othergrp:x:6666:
74 74
 			expected:  identity{UID: 0, GID: 1},
75 75
 		},
76 76
 		{
77
-			builder:   &Builder{options: &build.ImageBuildOptions{Platform: "linux"}},
77
+			builder:   &Builder{options: &buildbackend.BuildOptions{Platform: "linux"}},
78 78
 			name:      "UIDWithMap",
79 79
 			chownStr:  "0",
80 80
 			idMapping: remapped,
... ...
@@ -82,7 +82,7 @@ othergrp:x:6666:
82 82
 			expected:  identity{UID: 100000, GID: 100000},
83 83
 		},
84 84
 		{
85
-			builder:   &Builder{options: &build.ImageBuildOptions{Platform: "linux"}},
85
+			builder:   &Builder{options: &buildbackend.BuildOptions{Platform: "linux"}},
86 86
 			name:      "UIDGIDWithMap",
87 87
 			chownStr:  "1:33",
88 88
 			idMapping: remapped,
... ...
@@ -90,7 +90,7 @@ othergrp:x:6666:
90 90
 			expected:  identity{UID: 100001, GID: 100033},
91 91
 		},
92 92
 		{
93
-			builder:   &Builder{options: &build.ImageBuildOptions{Platform: "linux"}},
93
+			builder:   &Builder{options: &buildbackend.BuildOptions{Platform: "linux"}},
94 94
 			name:      "UserNoMap",
95 95
 			chownStr:  "bin:5555",
96 96
 			idMapping: unmapped,
... ...
@@ -98,7 +98,7 @@ othergrp:x:6666:
98 98
 			expected:  identity{UID: 1, GID: 5555},
99 99
 		},
100 100
 		{
101
-			builder:   &Builder{options: &build.ImageBuildOptions{Platform: "linux"}},
101
+			builder:   &Builder{options: &buildbackend.BuildOptions{Platform: "linux"}},
102 102
 			name:      "GroupWithMap",
103 103
 			chownStr:  "0:unicorn",
104 104
 			idMapping: remapped,
... ...
@@ -106,7 +106,7 @@ othergrp:x:6666:
106 106
 			expected:  identity{UID: 100000, GID: 101002},
107 107
 		},
108 108
 		{
109
-			builder:   &Builder{options: &build.ImageBuildOptions{Platform: "linux"}},
109
+			builder:   &Builder{options: &buildbackend.BuildOptions{Platform: "linux"}},
110 110
 			name:      "UserOnlyWithMap",
111 111
 			chownStr:  "unicorn",
112 112
 			idMapping: remapped,
... ...
@@ -131,7 +131,7 @@ othergrp:x:6666:
131 131
 		descr     string
132 132
 	}{
133 133
 		{
134
-			builder:   &Builder{options: &build.ImageBuildOptions{Platform: "linux"}},
134
+			builder:   &Builder{options: &buildbackend.BuildOptions{Platform: "linux"}},
135 135
 			name:      "BadChownFlagFormat",
136 136
 			chownStr:  "bob:1:555",
137 137
 			idMapping: unmapped,
... ...
@@ -139,7 +139,7 @@ othergrp:x:6666:
139 139
 			descr:     "invalid chown string format: bob:1:555",
140 140
 		},
141 141
 		{
142
-			builder:   &Builder{options: &build.ImageBuildOptions{Platform: "linux"}},
142
+			builder:   &Builder{options: &buildbackend.BuildOptions{Platform: "linux"}},
143 143
 			name:      "UserNoExist",
144 144
 			chownStr:  "bob",
145 145
 			idMapping: unmapped,
... ...
@@ -147,7 +147,7 @@ othergrp:x:6666:
147 147
 			descr:     "can't find uid for user bob: no such user: bob",
148 148
 		},
149 149
 		{
150
-			builder:   &Builder{options: &build.ImageBuildOptions{Platform: "linux"}},
150
+			builder:   &Builder{options: &buildbackend.BuildOptions{Platform: "linux"}},
151 151
 			name:      "GroupNoExist",
152 152
 			chownStr:  "root:bob",
153 153
 			idMapping: unmapped,
... ...
@@ -8,7 +8,6 @@ import (
8 8
 	"testing"
9 9
 
10 10
 	"github.com/moby/go-archive"
11
-	"github.com/moby/moby/api/types/build"
12 11
 	"github.com/moby/moby/api/types/container"
13 12
 	"github.com/moby/moby/v2/daemon/builder"
14 13
 	"github.com/moby/moby/v2/daemon/builder/remotecontext"
... ...
@@ -76,7 +75,7 @@ func readAndCheckDockerfile(t *testing.T, testName, contextDir, dockerfilePath,
76 76
 	}
77 77
 
78 78
 	config := buildbackend.BuildConfig{
79
-		Options: &build.ImageBuildOptions{Dockerfile: dockerfilePath},
79
+		Options: &buildbackend.BuildOptions{Dockerfile: dockerfilePath},
80 80
 		Source:  tarStream,
81 81
 	}
82 82
 	_, _, err = remotecontext.Detect(config)
... ...
@@ -6,6 +6,7 @@ import (
6 6
 	ocispec "github.com/opencontainers/image-spec/specs-go/v1"
7 7
 
8 8
 	"github.com/moby/moby/api/types/build"
9
+	"github.com/moby/moby/api/types/container"
9 10
 	"github.com/moby/moby/api/types/filters"
10 11
 	"github.com/moby/moby/api/types/registry"
11 12
 )
... ...
@@ -48,7 +49,67 @@ type AuxEmitter interface {
48 48
 type BuildConfig struct {
49 49
 	Source         io.ReadCloser
50 50
 	ProgressWriter ProgressWriter
51
-	Options        *build.ImageBuildOptions
51
+	Options        *BuildOptions
52
+}
53
+
54
+// BuildOptions holds the information
55
+// necessary to build images.
56
+type BuildOptions struct {
57
+	Tags           []string
58
+	SuppressOutput bool
59
+	RemoteContext  string
60
+	NoCache        bool
61
+	Remove         bool
62
+	ForceRemove    bool
63
+	PullParent     bool
64
+	Isolation      container.Isolation
65
+	CPUSetCPUs     string
66
+	CPUSetMems     string
67
+	CPUShares      int64
68
+	CPUQuota       int64
69
+	CPUPeriod      int64
70
+	Memory         int64
71
+	MemorySwap     int64
72
+	CgroupParent   string
73
+	NetworkMode    string
74
+	ShmSize        int64
75
+	Dockerfile     string
76
+	Ulimits        []*container.Ulimit
77
+	// BuildArgs needs to be a *string instead of just a string so that
78
+	// we can tell the difference between "" (empty string) and no value
79
+	// at all (nil). See the parsing of buildArgs in
80
+	// api/server/router/build/build_routes.go for even more info.
81
+	BuildArgs   map[string]*string
82
+	AuthConfigs map[string]registry.AuthConfig
83
+	Context     io.Reader
84
+	Labels      map[string]string
85
+	// squash the resulting image's layers to the parent
86
+	// preserves the original image and creates a new one from the parent with all
87
+	// the changes applied to a single layer
88
+	Squash bool
89
+	// CacheFrom specifies images that are used for matching cache. Images
90
+	// specified here do not need to have a valid parent chain to match cache.
91
+	CacheFrom   []string
92
+	SecurityOpt []string
93
+	ExtraHosts  []string // List of extra hosts
94
+	Target      string
95
+	SessionID   string
96
+	Platform    string
97
+	// Version specifies the version of the underlying builder to use
98
+	Version build.BuilderVersion
99
+	// BuildID is an optional identifier that can be passed together with the
100
+	// build request. The same identifier can be used to gracefully cancel the
101
+	// build with the cancel request.
102
+	BuildID string
103
+	// Outputs defines configurations for exporting build results. Only supported
104
+	// in BuildKit mode
105
+	Outputs []BuildOutput
106
+}
107
+
108
+// BuildOutput defines configuration for exporting a build result
109
+type BuildOutput struct {
110
+	Type  string
111
+	Attrs map[string]string
52 112
 }
53 113
 
54 114
 // GetImageAndLayerOptions are the options supported by GetImageAndReleasableLayer
... ...
@@ -35,8 +35,8 @@ type invalidParam struct {
35 35
 
36 36
 func (e invalidParam) InvalidParameter() {}
37 37
 
38
-func newImageBuildOptions(ctx context.Context, r *http.Request) (*build.ImageBuildOptions, error) {
39
-	options := &build.ImageBuildOptions{
38
+func newImageBuildOptions(ctx context.Context, r *http.Request) (*buildbackend.BuildOptions, error) {
39
+	options := &buildbackend.BuildOptions{
40 40
 		Version:        build.BuilderV1, // Builder V1 is the default, but can be overridden
41 41
 		Dockerfile:     r.FormValue("dockerfile"),
42 42
 		SuppressOutput: httputils.BoolValue(r, "q"),
... ...
@@ -81,7 +81,7 @@ func newImageBuildOptions(ctx context.Context, r *http.Request) (*build.ImageBui
81 81
 	if versions.GreaterThanOrEqualTo(version, "1.40") {
82 82
 		outputsJSON := r.FormValue("outputs")
83 83
 		if outputsJSON != "" {
84
-			var outputs []build.ImageBuildOutput
84
+			var outputs []buildbackend.BuildOutput
85 85
 			if err := json.Unmarshal([]byte(outputsJSON), &outputs); err != nil {
86 86
 				return nil, invalidParam{errors.Wrap(err, "invalid outputs specified")}
87 87
 			}
... ...
@@ -7,7 +7,7 @@ import (
7 7
 	"strings"
8 8
 	"testing"
9 9
 
10
-	"github.com/moby/moby/api/types/build"
10
+	"github.com/moby/moby/client"
11 11
 	"github.com/moby/moby/client/pkg/jsonmessage"
12 12
 	"github.com/moby/moby/v2/integration/internal/requirement"
13 13
 	"github.com/moby/moby/v2/testutil"
... ...
@@ -51,14 +51,12 @@ func testBuildWithCgroupNs(ctx context.Context, t *testing.T, daemonNsMode strin
51 51
 	source := fakecontext.New(t, "", fakecontext.WithDockerfile(dockerfile))
52 52
 	defer source.Close()
53 53
 
54
-	client := d.NewClientT(t)
55
-	resp, err := client.ImageBuild(ctx,
56
-		source.AsTarReader(t),
57
-		build.ImageBuildOptions{
58
-			Remove:      true,
59
-			ForceRemove: true,
60
-			Tags:        []string{"buildcgroupns"},
61
-		})
54
+	apiClient := d.NewClientT(t)
55
+	resp, err := apiClient.ImageBuild(ctx, source.AsTarReader(t), client.ImageBuildOptions{
56
+		Remove:      true,
57
+		ForceRemove: true,
58
+		Tags:        []string{"buildcgroupns"},
59
+	})
62 60
 	assert.NilError(t, err)
63 61
 	defer resp.Body.Close()
64 62
 
... ...
@@ -7,7 +7,6 @@ import (
7 7
 	"testing"
8 8
 
9 9
 	"github.com/moby/moby/api/pkg/stdcopy"
10
-	"github.com/moby/moby/api/types/build"
11 10
 	"github.com/moby/moby/client"
12 11
 	"github.com/moby/moby/v2/integration/internal/container"
13 12
 	"github.com/moby/moby/v2/testutil"
... ...
@@ -51,13 +50,11 @@ func TestBuildSquashParent(t *testing.T) {
51 51
 	defer source.Close()
52 52
 
53 53
 	name := strings.ToLower(t.Name())
54
-	resp, err := apiClient.ImageBuild(ctx,
55
-		source.AsTarReader(t),
56
-		build.ImageBuildOptions{
57
-			Remove:      true,
58
-			ForceRemove: true,
59
-			Tags:        []string{name},
60
-		})
54
+	resp, err := apiClient.ImageBuild(ctx, source.AsTarReader(t), client.ImageBuildOptions{
55
+		Remove:      true,
56
+		ForceRemove: true,
57
+		Tags:        []string{name},
58
+	})
61 59
 	assert.NilError(t, err)
62 60
 	_, err = io.Copy(io.Discard, resp.Body)
63 61
 	resp.Body.Close()
... ...
@@ -70,7 +67,7 @@ func TestBuildSquashParent(t *testing.T) {
70 70
 	// build with squash
71 71
 	resp, err = apiClient.ImageBuild(ctx,
72 72
 		source.AsTarReader(t),
73
-		build.ImageBuildOptions{
73
+		client.ImageBuildOptions{
74 74
 			Remove:      true,
75 75
 			ForceRemove: true,
76 76
 			Squash:      true,
... ...
@@ -110,7 +110,7 @@ func TestBuildWithRemoveAndForceRemove(t *testing.T) {
110 110
 			_, err := tw.Write(dockerfile)
111 111
 			assert.NilError(t, err)
112 112
 			assert.NilError(t, tw.Close())
113
-			resp, err := apiClient.ImageBuild(ctx, buff, build.ImageBuildOptions{Remove: tc.rm, ForceRemove: tc.forceRm, NoCache: true})
113
+			resp, err := apiClient.ImageBuild(ctx, buff, client.ImageBuildOptions{Remove: tc.rm, ForceRemove: tc.forceRm, NoCache: true})
114 114
 			assert.NilError(t, err)
115 115
 			defer resp.Body.Close()
116 116
 			filter, err := buildContainerIdsFilter(resp.Body)
... ...
@@ -163,16 +163,12 @@ func TestBuildMultiStageCopy(t *testing.T) {
163 163
 		t.Run(target, func(t *testing.T) {
164 164
 			imgName := strings.ToLower(t.Name())
165 165
 
166
-			resp, err := apiclient.ImageBuild(
167
-				ctx,
168
-				source.AsTarReader(t),
169
-				build.ImageBuildOptions{
170
-					Remove:      true,
171
-					ForceRemove: true,
172
-					Target:      target,
173
-					Tags:        []string{imgName},
174
-				},
175
-			)
166
+			resp, err := apiclient.ImageBuild(ctx, source.AsTarReader(t), client.ImageBuildOptions{
167
+				Remove:      true,
168
+				ForceRemove: true,
169
+				Target:      target,
170
+				Tags:        []string{imgName},
171
+			})
176 172
 			assert.NilError(t, err)
177 173
 
178 174
 			out := bytes.NewBuffer(nil)
... ...
@@ -213,13 +209,11 @@ func TestBuildMultiStageParentConfig(t *testing.T) {
213 213
 
214 214
 	apiclient := testEnv.APIClient()
215 215
 	imgName := strings.ToLower(t.Name())
216
-	resp, err := apiclient.ImageBuild(ctx,
217
-		source.AsTarReader(t),
218
-		build.ImageBuildOptions{
219
-			Remove:      true,
220
-			ForceRemove: true,
221
-			Tags:        []string{imgName},
222
-		})
216
+	resp, err := apiclient.ImageBuild(ctx, source.AsTarReader(t), client.ImageBuildOptions{
217
+		Remove:      true,
218
+		ForceRemove: true,
219
+		Tags:        []string{imgName},
220
+	})
223 221
 	assert.NilError(t, err)
224 222
 	_, err = io.Copy(io.Discard, resp.Body)
225 223
 	assert.Check(t, resp.Body.Close())
... ...
@@ -260,15 +254,13 @@ func TestBuildLabelWithTargets(t *testing.T) {
260 260
 
261 261
 	apiclient := testEnv.APIClient()
262 262
 	// For `target-a` build
263
-	resp, err := apiclient.ImageBuild(ctx,
264
-		source.AsTarReader(t),
265
-		build.ImageBuildOptions{
266
-			Remove:      true,
267
-			ForceRemove: true,
268
-			Tags:        []string{imgName},
269
-			Labels:      testLabels,
270
-			Target:      "target-a",
271
-		})
263
+	resp, err := apiclient.ImageBuild(ctx, source.AsTarReader(t), client.ImageBuildOptions{
264
+		Remove:      true,
265
+		ForceRemove: true,
266
+		Tags:        []string{imgName},
267
+		Labels:      testLabels,
268
+		Target:      "target-a",
269
+	})
272 270
 	assert.NilError(t, err)
273 271
 	_, err = io.Copy(io.Discard, resp.Body)
274 272
 	assert.Check(t, resp.Body.Close())
... ...
@@ -289,7 +281,7 @@ func TestBuildLabelWithTargets(t *testing.T) {
289 289
 	delete(testLabels, "label-a")
290 290
 	resp, err = apiclient.ImageBuild(ctx,
291 291
 		source.AsTarReader(t),
292
-		build.ImageBuildOptions{
292
+		client.ImageBuildOptions{
293 293
 			Remove:      true,
294 294
 			ForceRemove: true,
295 295
 			Tags:        []string{imgName},
... ...
@@ -328,12 +320,10 @@ COPY    3/ /target/
328 328
 	defer source.Close()
329 329
 
330 330
 	apiclient := testEnv.APIClient()
331
-	resp, err := apiclient.ImageBuild(ctx,
332
-		source.AsTarReader(t),
333
-		build.ImageBuildOptions{
334
-			Remove:      true,
335
-			ForceRemove: true,
336
-		})
331
+	resp, err := apiclient.ImageBuild(ctx, source.AsTarReader(t), client.ImageBuildOptions{
332
+		Remove:      true,
333
+		ForceRemove: true,
334
+	})
337 335
 	assert.NilError(t, err)
338 336
 	_, err = io.Copy(io.Discard, resp.Body)
339 337
 	assert.Check(t, resp.Body.Close())
... ...
@@ -364,12 +354,10 @@ RUN cat somefile`
364 364
 	defer source.Close()
365 365
 
366 366
 	apiclient := testEnv.APIClient()
367
-	resp, err := apiclient.ImageBuild(ctx,
368
-		source.AsTarReader(t),
369
-		build.ImageBuildOptions{
370
-			Remove:      true,
371
-			ForceRemove: true,
372
-		})
367
+	resp, err := apiclient.ImageBuild(ctx, source.AsTarReader(t), client.ImageBuildOptions{
368
+		Remove:      true,
369
+		ForceRemove: true,
370
+	})
373 371
 
374 372
 	out := bytes.NewBuffer(nil)
375 373
 	assert.NilError(t, err)
... ...
@@ -410,12 +398,10 @@ COPY bar /
410 410
 	assert.NilError(t, err)
411 411
 
412 412
 	apiclient := testEnv.APIClient()
413
-	resp, err := apiclient.ImageBuild(ctx,
414
-		buf,
415
-		build.ImageBuildOptions{
416
-			Remove:      true,
417
-			ForceRemove: true,
418
-		})
413
+	resp, err := apiclient.ImageBuild(ctx, buf, client.ImageBuildOptions{
414
+		Remove:      true,
415
+		ForceRemove: true,
416
+	})
419 417
 
420 418
 	out := bytes.NewBuffer(nil)
421 419
 	assert.NilError(t, err)
... ...
@@ -435,7 +421,7 @@ COPY bar /
435 435
 
436 436
 	resp, err = apiclient.ImageBuild(ctx,
437 437
 		buf,
438
-		build.ImageBuildOptions{
438
+		client.ImageBuildOptions{
439 439
 			Remove:      true,
440 440
 			ForceRemove: true,
441 441
 		})
... ...
@@ -472,12 +458,10 @@ RUN [ ! -f foo ]
472 472
 	defer source.Close()
473 473
 
474 474
 	apiClient := testEnv.APIClient()
475
-	resp, err := apiClient.ImageBuild(ctx,
476
-		source.AsTarReader(t),
477
-		build.ImageBuildOptions{
478
-			Remove:      true,
479
-			ForceRemove: true,
480
-		})
475
+	resp, err := apiClient.ImageBuild(ctx, source.AsTarReader(t), client.ImageBuildOptions{
476
+		Remove:      true,
477
+		ForceRemove: true,
478
+	})
481 479
 
482 480
 	out := bytes.NewBuffer(nil)
483 481
 	assert.NilError(t, err)
... ...
@@ -518,12 +502,10 @@ RUN for g in $(seq 0 8); do dd if=/dev/urandom of=rnd bs=1K count=1 seek=$((1024
518 518
 	assert.NilError(t, err)
519 519
 
520 520
 	apiClient := testEnv.APIClient()
521
-	resp, err := apiClient.ImageBuild(ctx,
522
-		buf,
523
-		build.ImageBuildOptions{
524
-			Remove:      true,
525
-			ForceRemove: true,
526
-		})
521
+	resp, err := apiClient.ImageBuild(ctx, buf, client.ImageBuildOptions{
522
+		Remove:      true,
523
+		ForceRemove: true,
524
+	})
527 525
 
528 526
 	out := bytes.NewBuffer(nil)
529 527
 	assert.NilError(t, err)
... ...
@@ -559,12 +541,10 @@ COPY --from=intermediate C:\\stuff C:\\stuff
559 559
 	assert.NilError(t, err)
560 560
 
561 561
 	apiClient := testEnv.APIClient()
562
-	resp, err := apiClient.ImageBuild(ctx,
563
-		buf,
564
-		build.ImageBuildOptions{
565
-			Remove:      true,
566
-			ForceRemove: true,
567
-		})
562
+	resp, err := apiClient.ImageBuild(ctx, buf, client.ImageBuildOptions{
563
+		Remove:      true,
564
+		ForceRemove: true,
565
+	})
568 566
 
569 567
 	out := bytes.NewBuffer(nil)
570 568
 	assert.NilError(t, err)
... ...
@@ -626,7 +606,7 @@ func TestBuildWithEmptyDockerfile(t *testing.T) {
626 626
 
627 627
 			_, err = apiClient.ImageBuild(ctx,
628 628
 				buf,
629
-				build.ImageBuildOptions{
629
+				client.ImageBuildOptions{
630 630
 					Remove:      true,
631 631
 					ForceRemove: true,
632 632
 				})
... ...
@@ -653,15 +633,11 @@ func TestBuildPreserveOwnership(t *testing.T) {
653 653
 		t.Run(target, func(t *testing.T) {
654 654
 			ctx := testutil.StartSpan(ctx, t)
655 655
 
656
-			resp, err := apiClient.ImageBuild(
657
-				ctx,
658
-				source.AsTarReader(t),
659
-				build.ImageBuildOptions{
660
-					Remove:      true,
661
-					ForceRemove: true,
662
-					Target:      target,
663
-				},
664
-			)
656
+			resp, err := apiClient.ImageBuild(ctx, source.AsTarReader(t), client.ImageBuildOptions{
657
+				Remove:      true,
658
+				ForceRemove: true,
659
+				Target:      target,
660
+			})
665 661
 			assert.NilError(t, err)
666 662
 
667 663
 			out := bytes.NewBuffer(nil)
... ...
@@ -684,7 +660,7 @@ func TestBuildPlatformInvalid(t *testing.T) {
684 684
 	err := w.Close()
685 685
 	assert.NilError(t, err)
686 686
 
687
-	_, err = testEnv.APIClient().ImageBuild(ctx, buf, build.ImageBuildOptions{
687
+	_, err = testEnv.APIClient().ImageBuild(ctx, buf, client.ImageBuildOptions{
688 688
 		Remove:      true,
689 689
 		ForceRemove: true,
690 690
 		Platform:    "foobar",
... ...
@@ -713,7 +689,7 @@ func TestBuildWorkdirNoCacheMiss(t *testing.T) {
713 713
 			apiClient := testEnv.APIClient()
714 714
 
715 715
 			buildAndGetID := func() string {
716
-				resp, err := apiClient.ImageBuild(ctx, source.AsTarReader(t), build.ImageBuildOptions{
716
+				resp, err := apiClient.ImageBuild(ctx, source.AsTarReader(t), client.ImageBuildOptions{
717 717
 					Version: build.BuilderV1,
718 718
 				})
719 719
 				assert.NilError(t, err)
... ...
@@ -752,7 +728,7 @@ func TestBuildEmitsImageCreateEvent(t *testing.T) {
752 752
 
753 753
 			since := time.Now()
754 754
 
755
-			resp, err := apiClient.ImageBuild(ctx, source.AsTarReader(t), build.ImageBuildOptions{
755
+			resp, err := apiClient.ImageBuild(ctx, source.AsTarReader(t), client.ImageBuildOptions{
756 756
 				Version: builderVersion,
757 757
 				NoCache: true,
758 758
 			})
... ...
@@ -807,7 +783,7 @@ func TestBuildHistoryDoesNotPreventRemoval(t *testing.T) {
807 807
 	apiClient := testEnv.APIClient()
808 808
 
809 809
 	buildImage := func(imgName string) error {
810
-		resp, err := apiClient.ImageBuild(ctx, source.AsTarReader(t), build.ImageBuildOptions{
810
+		resp, err := apiClient.ImageBuild(ctx, source.AsTarReader(t), client.ImageBuildOptions{
811 811
 			Remove:      true,
812 812
 			ForceRemove: true,
813 813
 			Tags:        []string{imgName},
... ...
@@ -10,7 +10,6 @@ import (
10 10
 	"testing"
11 11
 
12 12
 	"github.com/moby/moby/api/pkg/stdcopy"
13
-	"github.com/moby/moby/api/types/build"
14 13
 	"github.com/moby/moby/client"
15 14
 	"github.com/moby/moby/client/pkg/jsonmessage"
16 15
 	"github.com/moby/moby/v2/integration/internal/container"
... ...
@@ -64,11 +63,9 @@ func TestBuildUserNamespaceValidateCapabilitiesAreV2(t *testing.T) {
64 64
 	source := fakecontext.New(t, "", fakecontext.WithDockerfile(dockerfile))
65 65
 	defer source.Close()
66 66
 
67
-	resp, err := clientUserRemap.ImageBuild(ctx,
68
-		source.AsTarReader(t),
69
-		build.ImageBuildOptions{
70
-			Tags: []string{imageTag},
71
-		})
67
+	resp, err := clientUserRemap.ImageBuild(ctx, source.AsTarReader(t), client.ImageBuildOptions{
68
+		Tags: []string{imageTag},
69
+	})
72 70
 	assert.NilError(t, err)
73 71
 	defer resp.Body.Close()
74 72
 
... ...
@@ -7,9 +7,8 @@ import (
7 7
 	"testing"
8 8
 
9 9
 	"github.com/moby/moby/api/pkg/stdcopy"
10
-	"github.com/moby/moby/api/types/build"
11 10
 	containertypes "github.com/moby/moby/api/types/container"
12
-	client2 "github.com/moby/moby/client"
11
+	"github.com/moby/moby/client"
13 12
 	"github.com/moby/moby/v2/integration/internal/container"
14 13
 	"github.com/moby/moby/v2/testutil"
15 14
 	"github.com/moby/moby/v2/testutil/fakecontext"
... ...
@@ -32,14 +31,12 @@ func TestNoNewPrivileges(t *testing.T) {
32 32
 	source := fakecontext.New(t, "", fakecontext.WithDockerfile(withFileCapability))
33 33
 	defer source.Close()
34 34
 
35
-	client := testEnv.APIClient()
35
+	apiClient := testEnv.APIClient()
36 36
 
37 37
 	// Build image
38
-	resp, err := client.ImageBuild(ctx,
39
-		source.AsTarReader(t),
40
-		build.ImageBuildOptions{
41
-			Tags: []string{imageTag},
42
-		})
38
+	resp, err := apiClient.ImageBuild(ctx, source.AsTarReader(t), client.ImageBuildOptions{
39
+		Tags: []string{imageTag},
40
+	})
43 41
 	assert.NilError(t, err)
44 42
 	_, err = io.Copy(io.Discard, resp.Body)
45 43
 	assert.NilError(t, err)
... ...
@@ -78,11 +75,11 @@ func TestNoNewPrivileges(t *testing.T) {
78 78
 				container.WithCmd("/bin/cat", "/txt"),
79 79
 				container.WithSecurityOpt("no-new-privileges=true"),
80 80
 			)
81
-			cid := container.Run(ctx, t, client, opts...)
82
-			poll.WaitOn(t, container.IsInState(ctx, client, cid, containertypes.StateExited))
81
+			cid := container.Run(ctx, t, apiClient, opts...)
82
+			poll.WaitOn(t, container.IsInState(ctx, apiClient, cid, containertypes.StateExited))
83 83
 
84 84
 			// Assert on outputs
85
-			logReader, err := client.ContainerLogs(ctx, cid, client2.ContainerLogsOptions{
85
+			logReader, err := apiClient.ContainerLogs(ctx, cid, client.ContainerLogsOptions{
86 86
 				ShowStdout: true,
87 87
 				ShowStderr: true,
88 88
 			})
... ...
@@ -213,7 +213,7 @@ func makeTestImage(ctx context.Context, t *testing.T) (imageID string) {
213 213
 	`))
214 214
 	defer buildCtx.Close()
215 215
 
216
-	resp, err := apiClient.ImageBuild(ctx, buildCtx.AsTarReader(t), build.ImageBuildOptions{})
216
+	resp, err := apiClient.ImageBuild(ctx, buildCtx.AsTarReader(t), client.ImageBuildOptions{})
217 217
 	assert.NilError(t, err)
218 218
 	defer resp.Body.Close()
219 219
 
... ...
@@ -287,7 +287,7 @@ func TestCopyFromContainer(t *testing.T) {
287 287
 	`))
288 288
 	defer buildCtx.Close()
289 289
 
290
-	resp, err := apiClient.ImageBuild(ctx, buildCtx.AsTarReader(t), build.ImageBuildOptions{})
290
+	resp, err := apiClient.ImageBuild(ctx, buildCtx.AsTarReader(t), client.ImageBuildOptions{})
291 291
 	assert.NilError(t, err)
292 292
 	defer resp.Body.Close()
293 293
 
... ...
@@ -68,7 +68,7 @@ func TestAPIImageHistoryCrossPlatform(t *testing.T) {
68 68
 	defer buildCtx.Close()
69 69
 
70 70
 	// Build the image for a non-native platform
71
-	resp, err := apiClient.ImageBuild(ctx, buildCtx.AsTarReader(t), buildtypes.ImageBuildOptions{
71
+	resp, err := apiClient.ImageBuild(ctx, buildCtx.AsTarReader(t), client.ImageBuildOptions{
72 72
 		Version:  buildtypes.BuilderBuildKit,
73 73
 		Tags:     []string{"cross-platform-test"},
74 74
 		Platform: platforms.FormatAll(nonNativePlatform),
... ...
@@ -18,7 +18,7 @@ import (
18 18
 
19 19
 // Do builds an image from the given context and returns the image ID.
20 20
 func Do(ctx context.Context, t *testing.T, apiClient client.APIClient, buildCtx *fakecontext.Fake) string {
21
-	resp, err := apiClient.ImageBuild(ctx, buildCtx.AsTarReader(t), build.ImageBuildOptions{})
21
+	resp, err := apiClient.ImageBuild(ctx, buildCtx.AsTarReader(t), client.ImageBuildOptions{})
22 22
 	if resp.Body != nil {
23 23
 		defer resp.Body.Close()
24 24
 	}
... ...
@@ -9,7 +9,6 @@ import (
9 9
 	"strings"
10 10
 	"testing"
11 11
 
12
-	"github.com/moby/moby/api/types/build"
13 12
 	containertypes "github.com/moby/moby/api/types/container"
14 13
 	"github.com/moby/moby/api/types/mount"
15 14
 	"github.com/moby/moby/api/types/network"
... ...
@@ -320,13 +319,11 @@ func setupTestImage(t *testing.T, ctx context.Context, apiClient client.APIClien
320 320
 	)
321 321
 	defer source.Close()
322 322
 
323
-	resp, err := apiClient.ImageBuild(ctx,
324
-		source.AsTarReader(t),
325
-		build.ImageBuildOptions{
326
-			Remove:      false,
327
-			ForceRemove: false,
328
-			Tags:        []string{imgName},
329
-		})
323
+	resp, err := apiClient.ImageBuild(ctx, source.AsTarReader(t), client.ImageBuildOptions{
324
+		Remove:      false,
325
+		ForceRemove: false,
326
+		Tags:        []string{imgName},
327
+	})
330 328
 	assert.NilError(t, err)
331 329
 
332 330
 	out := bytes.NewBuffer(nil)
... ...
@@ -10,7 +10,7 @@ import (
10 10
 	"testing"
11 11
 
12 12
 	"github.com/moby/go-archive"
13
-	"github.com/moby/moby/api/types/build"
13
+	"github.com/moby/moby/client"
14 14
 	"gotest.tools/v3/assert"
15 15
 )
16 16
 
... ...
@@ -76,7 +76,7 @@ CMD ["./httpserver"]
76 76
 	assert.NilError(t, err)
77 77
 
78 78
 	apiClient := testEnv.APIClient()
79
-	resp, err := apiClient.ImageBuild(context.Background(), reader, build.ImageBuildOptions{
79
+	resp, err := apiClient.ImageBuild(context.Background(), reader, client.ImageBuildOptions{
80 80
 		Remove:      true,
81 81
 		ForceRemove: true,
82 82
 		Tags:        []string{"httpserver"},
... ...
@@ -11,7 +11,6 @@ import (
11 11
 	"strings"
12 12
 	"testing"
13 13
 
14
-	"github.com/moby/moby/api/types/build"
15 14
 	containertypes "github.com/moby/moby/api/types/container"
16 15
 	"github.com/moby/moby/client"
17 16
 	"github.com/moby/moby/v2/testutil"
... ...
@@ -145,7 +144,7 @@ func newRemoteFileServer(t testing.TB, ctx *fakecontext.Fake, c client.APIClient
145 145
 COPY . /static`); err != nil {
146 146
 		t.Fatal(err)
147 147
 	}
148
-	resp, err := c.ImageBuild(context.Background(), ctx.AsTarReader(t), build.ImageBuildOptions{
148
+	resp, err := c.ImageBuild(context.Background(), ctx.AsTarReader(t), client.ImageBuildOptions{
149 149
 		NoCache: true,
150 150
 		Tags:    []string{imgName},
151 151
 	})
... ...
@@ -1,12 +1,5 @@
1 1
 package build
2 2
 
3
-import (
4
-	"io"
5
-
6
-	"github.com/moby/moby/api/types/container"
7
-	"github.com/moby/moby/api/types/registry"
8
-)
9
-
10 3
 // BuilderVersion sets the version of underlying builder to use
11 4
 type BuilderVersion string
12 5
 
... ...
@@ -21,71 +14,3 @@ const (
21 21
 type Result struct {
22 22
 	ID string
23 23
 }
24
-
25
-// ImageBuildOptions holds the information
26
-// necessary to build images.
27
-type ImageBuildOptions struct {
28
-	Tags           []string
29
-	SuppressOutput bool
30
-	RemoteContext  string
31
-	NoCache        bool
32
-	Remove         bool
33
-	ForceRemove    bool
34
-	PullParent     bool
35
-	Isolation      container.Isolation
36
-	CPUSetCPUs     string
37
-	CPUSetMems     string
38
-	CPUShares      int64
39
-	CPUQuota       int64
40
-	CPUPeriod      int64
41
-	Memory         int64
42
-	MemorySwap     int64
43
-	CgroupParent   string
44
-	NetworkMode    string
45
-	ShmSize        int64
46
-	Dockerfile     string
47
-	Ulimits        []*container.Ulimit
48
-	// BuildArgs needs to be a *string instead of just a string so that
49
-	// we can tell the difference between "" (empty string) and no value
50
-	// at all (nil). See the parsing of buildArgs in
51
-	// api/server/router/build/build_routes.go for even more info.
52
-	BuildArgs   map[string]*string
53
-	AuthConfigs map[string]registry.AuthConfig
54
-	Context     io.Reader
55
-	Labels      map[string]string
56
-	// squash the resulting image's layers to the parent
57
-	// preserves the original image and creates a new one from the parent with all
58
-	// the changes applied to a single layer
59
-	Squash bool
60
-	// CacheFrom specifies images that are used for matching cache. Images
61
-	// specified here do not need to have a valid parent chain to match cache.
62
-	CacheFrom   []string
63
-	SecurityOpt []string
64
-	ExtraHosts  []string // List of extra hosts
65
-	Target      string
66
-	SessionID   string
67
-	Platform    string
68
-	// Version specifies the version of the underlying builder to use
69
-	Version BuilderVersion
70
-	// BuildID is an optional identifier that can be passed together with the
71
-	// build request. The same identifier can be used to gracefully cancel the
72
-	// build with the cancel request.
73
-	BuildID string
74
-	// Outputs defines configurations for exporting build results. Only supported
75
-	// in BuildKit mode
76
-	Outputs []ImageBuildOutput
77
-}
78
-
79
-// ImageBuildOutput defines configuration for exporting a build result
80
-type ImageBuildOutput struct {
81
-	Type  string
82
-	Attrs map[string]string
83
-}
84
-
85
-// ImageBuildResponse holds information
86
-// returned by a server after building
87
-// an image.
88
-type ImageBuildResponse struct {
89
-	Body   io.ReadCloser
90
-	OSType string
91
-}
... ...
@@ -106,7 +106,7 @@ type DistributionAPIClient interface {
106 106
 
107 107
 // ImageAPIClient defines API client methods for the images
108 108
 type ImageAPIClient interface {
109
-	ImageBuild(ctx context.Context, context io.Reader, options build.ImageBuildOptions) (build.ImageBuildResponse, error)
109
+	ImageBuild(ctx context.Context, context io.Reader, options ImageBuildOptions) (ImageBuildResponse, error)
110 110
 	BuildCachePrune(ctx context.Context, opts BuildCachePruneOptions) (*build.CachePruneReport, error)
111 111
 	BuildCancel(ctx context.Context, id string) error
112 112
 	ImageCreate(ctx context.Context, parentReference string, options ImageCreateOptions) (io.ReadCloser, error)
... ...
@@ -10,7 +10,6 @@ import (
10 10
 	"strconv"
11 11
 	"strings"
12 12
 
13
-	"github.com/moby/moby/api/types/build"
14 13
 	"github.com/moby/moby/api/types/container"
15 14
 	"github.com/moby/moby/api/types/network"
16 15
 )
... ...
@@ -18,15 +17,15 @@ import (
18 18
 // ImageBuild sends a request to the daemon to build images.
19 19
 // The Body in the response implements an [io.ReadCloser] and it's up to the caller to
20 20
 // close it.
21
-func (cli *Client) ImageBuild(ctx context.Context, buildContext io.Reader, options build.ImageBuildOptions) (build.ImageBuildResponse, error) {
21
+func (cli *Client) ImageBuild(ctx context.Context, buildContext io.Reader, options ImageBuildOptions) (ImageBuildResponse, error) {
22 22
 	query, err := cli.imageBuildOptionsToQuery(ctx, options)
23 23
 	if err != nil {
24
-		return build.ImageBuildResponse{}, err
24
+		return ImageBuildResponse{}, err
25 25
 	}
26 26
 
27 27
 	buf, err := json.Marshal(options.AuthConfigs)
28 28
 	if err != nil {
29
-		return build.ImageBuildResponse{}, err
29
+		return ImageBuildResponse{}, err
30 30
 	}
31 31
 
32 32
 	headers := http.Header{}
... ...
@@ -35,16 +34,16 @@ func (cli *Client) ImageBuild(ctx context.Context, buildContext io.Reader, optio
35 35
 
36 36
 	resp, err := cli.postRaw(ctx, "/build", query, buildContext, headers)
37 37
 	if err != nil {
38
-		return build.ImageBuildResponse{}, err
38
+		return ImageBuildResponse{}, err
39 39
 	}
40 40
 
41
-	return build.ImageBuildResponse{
41
+	return ImageBuildResponse{
42 42
 		Body:   resp.Body,
43 43
 		OSType: resp.Header.Get("Ostype"),
44 44
 	}, nil
45 45
 }
46 46
 
47
-func (cli *Client) imageBuildOptionsToQuery(ctx context.Context, options build.ImageBuildOptions) (url.Values, error) {
47
+func (cli *Client) imageBuildOptionsToQuery(ctx context.Context, options ImageBuildOptions) (url.Values, error) {
48 48
 	query := url.Values{}
49 49
 	if len(options.Tags) > 0 {
50 50
 		query["t"] = options.Tags
51 51
new file mode 100644
... ...
@@ -0,0 +1,77 @@
0
+package client
1
+
2
+import (
3
+	"io"
4
+
5
+	"github.com/moby/moby/api/types/build"
6
+	"github.com/moby/moby/api/types/container"
7
+	"github.com/moby/moby/api/types/registry"
8
+)
9
+
10
+// ImageBuildOptions holds the information
11
+// necessary to build images.
12
+type ImageBuildOptions struct {
13
+	Tags           []string
14
+	SuppressOutput bool
15
+	RemoteContext  string
16
+	NoCache        bool
17
+	Remove         bool
18
+	ForceRemove    bool
19
+	PullParent     bool
20
+	Isolation      container.Isolation
21
+	CPUSetCPUs     string
22
+	CPUSetMems     string
23
+	CPUShares      int64
24
+	CPUQuota       int64
25
+	CPUPeriod      int64
26
+	Memory         int64
27
+	MemorySwap     int64
28
+	CgroupParent   string
29
+	NetworkMode    string
30
+	ShmSize        int64
31
+	Dockerfile     string
32
+	Ulimits        []*container.Ulimit
33
+	// BuildArgs needs to be a *string instead of just a string so that
34
+	// we can tell the difference between "" (empty string) and no value
35
+	// at all (nil). See the parsing of buildArgs in
36
+	// api/server/router/build/build_routes.go for even more info.
37
+	BuildArgs   map[string]*string
38
+	AuthConfigs map[string]registry.AuthConfig
39
+	Context     io.Reader
40
+	Labels      map[string]string
41
+	// squash the resulting image's layers to the parent
42
+	// preserves the original image and creates a new one from the parent with all
43
+	// the changes applied to a single layer
44
+	Squash bool
45
+	// CacheFrom specifies images that are used for matching cache. Images
46
+	// specified here do not need to have a valid parent chain to match cache.
47
+	CacheFrom   []string
48
+	SecurityOpt []string
49
+	ExtraHosts  []string // List of extra hosts
50
+	Target      string
51
+	SessionID   string
52
+	Platform    string
53
+	// Version specifies the version of the underlying builder to use
54
+	Version build.BuilderVersion
55
+	// BuildID is an optional identifier that can be passed together with the
56
+	// build request. The same identifier can be used to gracefully cancel the
57
+	// build with the cancel request.
58
+	BuildID string
59
+	// Outputs defines configurations for exporting build results. Only supported
60
+	// in BuildKit mode
61
+	Outputs []ImageBuildOutput
62
+}
63
+
64
+// ImageBuildOutput defines configuration for exporting a build result
65
+type ImageBuildOutput struct {
66
+	Type  string
67
+	Attrs map[string]string
68
+}
69
+
70
+// ImageBuildResponse holds information
71
+// returned by a server after building
72
+// an image.
73
+type ImageBuildResponse struct {
74
+	Body   io.ReadCloser
75
+	OSType string
76
+}