Skip to content

Commit 3d1e4d9

Browse files
committed
api/types: move build-related types to api/types/build
Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent bb7dbaa commit 3d1e4d9

29 files changed

Lines changed: 225 additions & 191 deletions

api/server/backend/build/backend.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"strconv"
77

88
"github.com/distribution/reference"
9-
"github.com/docker/docker/api/types"
109
"github.com/docker/docker/api/types/backend"
1110
"github.com/docker/docker/api/types/build"
1211
"github.com/docker/docker/api/types/events"
@@ -53,7 +52,7 @@ func (b *Backend) RegisterGRPC(s *grpc.Server) {
5352
// Build builds an image from a Source
5453
func (b *Backend) Build(ctx context.Context, config backend.BuildConfig) (string, error) {
5554
options := config.Options
56-
useBuildKit := options.Version == types.BuilderBuildKit
55+
useBuildKit := options.Version == build.BuilderBuildKit
5756

5857
tags, err := sanitizeRepoAndTags(options.Tags)
5958
if err != nil {

api/server/router/build/build.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"runtime"
55

66
"github.com/docker/docker/api/server/router"
7-
"github.com/docker/docker/api/types"
7+
build2 "github.com/docker/docker/api/types/build"
88
)
99

1010
// buildRouter is a router to talk with the build controller
@@ -46,15 +46,15 @@ func (br *buildRouter) initRoutes() {
4646
//
4747
// This value is only a recommendation as advertised by the daemon, and it is
4848
// up to the client to choose which builder to use.
49-
func BuilderVersion(features map[string]bool) types.BuilderVersion {
49+
func BuilderVersion(features map[string]bool) build2.BuilderVersion {
5050
// TODO(thaJeztah) move the default to daemon/config
5151
if runtime.GOOS == "windows" {
52-
return types.BuilderV1
52+
return build2.BuilderV1
5353
}
5454

55-
bv := types.BuilderBuildKit
55+
bv := build2.BuilderBuildKit
5656
if v, ok := features["buildkit"]; ok && !v {
57-
bv = types.BuilderV1
57+
bv = build2.BuilderV1
5858
}
5959
return bv
6060
}

api/server/router/build/build_routes.go

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import (
1717

1818
"github.com/containerd/log"
1919
"github.com/docker/docker/api/server/httputils"
20-
"github.com/docker/docker/api/types"
2120
"github.com/docker/docker/api/types/backend"
2221
"github.com/docker/docker/api/types/build"
2322
"github.com/docker/docker/api/types/container"
@@ -36,9 +35,9 @@ type invalidParam struct {
3635

3736
func (e invalidParam) InvalidParameter() {}
3837

39-
func newImageBuildOptions(ctx context.Context, r *http.Request) (*types.ImageBuildOptions, error) {
40-
options := &types.ImageBuildOptions{
41-
Version: types.BuilderV1, // Builder V1 is the default, but can be overridden
38+
func newImageBuildOptions(ctx context.Context, r *http.Request) (*build.ImageBuildOptions, error) {
39+
options := &build.ImageBuildOptions{
40+
Version: build.BuilderV1, // Builder V1 is the default, but can be overridden
4241
Dockerfile: r.FormValue("dockerfile"),
4342
SuppressOutput: httputils.BoolValue(r, "q"),
4443
NoCache: httputils.BoolValue(r, "nocache"),
@@ -82,7 +81,7 @@ func newImageBuildOptions(ctx context.Context, r *http.Request) (*types.ImageBui
8281
if versions.GreaterThanOrEqualTo(version, "1.40") {
8382
outputsJSON := r.FormValue("outputs")
8483
if outputsJSON != "" {
85-
var outputs []types.ImageBuildOutput
84+
var outputs []build.ImageBuildOutput
8685
if err := json.Unmarshal([]byte(outputsJSON), &outputs); err != nil {
8786
return nil, invalidParam{errors.Wrap(err, "invalid outputs specified")}
8887
}
@@ -160,12 +159,12 @@ func newImageBuildOptions(ctx context.Context, r *http.Request) (*types.ImageBui
160159
return options, nil
161160
}
162161

163-
func parseVersion(s string) (types.BuilderVersion, error) {
164-
switch types.BuilderVersion(s) {
165-
case types.BuilderV1:
166-
return types.BuilderV1, nil
167-
case types.BuilderBuildKit:
168-
return types.BuilderBuildKit, nil
162+
func parseVersion(s string) (build.BuilderVersion, error) {
163+
switch build.BuilderVersion(s) {
164+
case build.BuilderV1:
165+
return build.BuilderV1, nil
166+
case build.BuilderBuildKit:
167+
return build.BuilderBuildKit, nil
169168
default:
170169
return "", invalidParam{errors.Errorf("invalid version %q", s)}
171170
}

api/types/backend/build.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package backend // import "github.com/docker/docker/api/types/backend"
33
import (
44
"io"
55

6-
"github.com/docker/docker/api/types"
6+
"github.com/docker/docker/api/types/build"
77
"github.com/docker/docker/api/types/registry"
88
"github.com/docker/docker/pkg/streamformatter"
99
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
@@ -34,7 +34,7 @@ type ProgressWriter struct {
3434
type BuildConfig struct {
3535
Source io.ReadCloser
3636
ProgressWriter ProgressWriter
37-
Options *types.ImageBuildOptions
37+
Options *build.ImageBuildOptions
3838
}
3939

4040
// GetImageAndLayerOptions are the options supported by GetImageAndReleasableLayer

api/types/build/build.go

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,91 @@
11
package build
22

3+
import (
4+
"io"
5+
6+
"github.com/docker/docker/api/types/container"
7+
"github.com/docker/docker/api/types/registry"
8+
)
9+
10+
// BuilderVersion sets the version of underlying builder to use
11+
type BuilderVersion string
12+
13+
const (
14+
// BuilderV1 is the first generation builder in docker daemon
15+
BuilderV1 BuilderVersion = "1"
16+
// BuilderBuildKit is builder based on moby/buildkit project
17+
BuilderBuildKit BuilderVersion = "2"
18+
)
19+
320
// Result contains the image id of a successful build.
421
type Result struct {
522
ID string
623
}
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+
}

api/types/client.go

Lines changed: 0 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,9 @@ package types // import "github.com/docker/docker/api/types"
33
import (
44
"bufio"
55
"context"
6-
"io"
76
"net"
87

9-
"github.com/docker/docker/api/types/container"
108
"github.com/docker/docker/api/types/filters"
11-
"github.com/docker/docker/api/types/registry"
129
)
1310

1411
// NewHijackedResponse initializes a [HijackedResponse] type.
@@ -51,84 +48,6 @@ func (h *HijackedResponse) CloseWrite() error {
5148
return nil
5249
}
5350

54-
// ImageBuildOptions holds the information
55-
// necessary to build images.
56-
type ImageBuildOptions 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 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 []ImageBuildOutput
106-
}
107-
108-
// ImageBuildOutput defines configuration for exporting a build result
109-
type ImageBuildOutput struct {
110-
Type string
111-
Attrs map[string]string
112-
}
113-
114-
// BuilderVersion sets the version of underlying builder to use
115-
type BuilderVersion string
116-
117-
const (
118-
// BuilderV1 is the first generation builder in docker daemon
119-
BuilderV1 BuilderVersion = "1"
120-
// BuilderBuildKit is builder based on moby/buildkit project
121-
BuilderBuildKit BuilderVersion = "2"
122-
)
123-
124-
// ImageBuildResponse holds information
125-
// returned by a server after building
126-
// an image.
127-
type ImageBuildResponse struct {
128-
Body io.ReadCloser
129-
OSType string
130-
}
131-
13251
// NodeListOptions holds parameters to list nodes with.
13352
type NodeListOptions struct {
13453
Filters filters.Args

api/types/types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ type Ping struct {
2323
APIVersion string
2424
OSType string
2525
Experimental bool
26-
BuilderVersion BuilderVersion
26+
BuilderVersion build.BuilderVersion
2727

2828
// SwarmStatus provides information about the current swarm status of the
2929
// engine, obtained from the "Swarm" header in the API response.

api/types/types_deprecated.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,37 @@ type BuildCachePruneReport = build.CachePruneReport
135135
//
136136
// Deprecated: use [build.Result].
137137
type BuildResult = build.Result
138+
139+
// ImageBuildOptions holds the information
140+
// necessary to build images.
141+
//
142+
// Deprecated: use [build.ImageBuildOptions].
143+
type ImageBuildOptions = build.ImageBuildOptions
144+
145+
// ImageBuildOutput defines configuration for exporting a build result
146+
//
147+
// Deprecated: use [build.ImageBuildOutput].
148+
type ImageBuildOutput = build.ImageBuildOutput
149+
150+
// ImageBuildResponse holds information
151+
// returned by a server after building
152+
// an image.
153+
//
154+
// Deprecated: use [build.ImageBuildResponse].
155+
type ImageBuildResponse = build.ImageBuildResponse
156+
157+
// BuilderVersion sets the version of underlying builder to use
158+
//
159+
// Deprecated: use [build.BuilderVersion].
160+
type BuilderVersion = build.BuilderVersion
161+
162+
const (
163+
// BuilderV1 is the first generation builder in docker daemon
164+
//
165+
// Deprecated: use [build.BuilderV1].
166+
BuilderV1 = build.BuilderV1
167+
// BuilderBuildKit is builder based on moby/buildkit project
168+
//
169+
// Deprecated: use [build.BuilderBuildKit].
170+
BuilderBuildKit = build.BuilderBuildKit
171+
)

builder/dockerfile/builder.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010

1111
"github.com/containerd/log"
1212
"github.com/containerd/platforms"
13-
"github.com/docker/docker/api/types"
1413
"github.com/docker/docker/api/types/backend"
1514
"github.com/docker/docker/api/types/build"
1615
"github.com/docker/docker/api/types/container"
@@ -100,7 +99,7 @@ func (bm *BuildManager) Build(ctx context.Context, config backend.BuildConfig) (
10099

101100
// builderOptions are the dependencies required by the builder
102101
type builderOptions struct {
103-
Options *types.ImageBuildOptions
102+
Options *build.ImageBuildOptions
104103
Backend builder.Backend
105104
ProgressWriter backend.ProgressWriter
106105
PathCache pathCache
@@ -110,7 +109,7 @@ type builderOptions struct {
110109
// Builder is a Dockerfile builder
111110
// It implements the builder.Backend interface.
112111
type Builder struct {
113-
options *types.ImageBuildOptions
112+
options *build.ImageBuildOptions
114113

115114
Stdout io.Writer
116115
Stderr io.Writer
@@ -132,7 +131,7 @@ type Builder struct {
132131
func newBuilder(ctx context.Context, options builderOptions) (*Builder, error) {
133132
config := options.Options
134133
if config == nil {
135-
config = new(types.ImageBuildOptions)
134+
config = new(build.ImageBuildOptions)
136135
}
137136

138137
imgProber, err := newImageProber(ctx, options.Backend, config.CacheFrom, config.NoCache)
@@ -332,7 +331,7 @@ func BuildFromConfig(ctx context.Context, config *container.Config, changes []st
332331
}
333332

334333
b, err := newBuilder(ctx, builderOptions{
335-
Options: &types.ImageBuildOptions{NoCache: true},
334+
Options: &build.ImageBuildOptions{NoCache: true},
336335
})
337336
if err != nil {
338337
return nil, err

0 commit comments

Comments
 (0)