api/types/build: move build options to client and backend
| ... | ... |
@@ -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=", |
| ... | ... |
@@ -13,7 +13,6 @@ import ( |
| 13 | 13 |
buildkit "github.com/moby/moby/v2/daemon/internal/builder-next" |
| 14 | 14 |
"github.com/moby/moby/v2/daemon/internal/image" |
| 15 | 15 |
"github.com/moby/moby/v2/daemon/internal/stringid" |
| 16 |
- "github.com/moby/moby/v2/daemon/server/backend" |
|
| 17 | 16 |
"github.com/moby/moby/v2/daemon/server/buildbackend" |
| 18 | 17 |
"github.com/pkg/errors" |
| 19 | 18 |
"google.golang.org/grpc" |
| ... | ... |
@@ -27,7 +26,7 @@ type ImageComponent interface {
|
| 27 | 27 |
|
| 28 | 28 |
// Builder defines interface for running a build |
| 29 | 29 |
type Builder interface {
|
| 30 |
- Build(context.Context, backend.BuildConfig) (*builder.Result, error) |
|
| 30 |
+ Build(context.Context, buildbackend.BuildConfig) (*builder.Result, error) |
|
| 31 | 31 |
} |
| 32 | 32 |
|
| 33 | 33 |
// Backend provides build functionality to the API router |
| ... | ... |
@@ -51,7 +50,7 @@ func (b *Backend) RegisterGRPC(s *grpc.Server) {
|
| 51 | 51 |
} |
| 52 | 52 |
|
| 53 | 53 |
// Build builds an image from a Source |
| 54 |
-func (b *Backend) Build(ctx context.Context, config backend.BuildConfig) (string, error) {
|
|
| 54 |
+func (b *Backend) Build(ctx context.Context, config buildbackend.BuildConfig) (string, error) {
|
|
| 55 | 55 |
options := config.Options |
| 56 | 56 |
useBuildKit := options.Version == build.BuilderBuildKit |
| 57 | 57 |
|
| ... | ... |
@@ -13,6 +13,7 @@ import ( |
| 13 | 13 |
"github.com/moby/moby/v2/daemon/internal/image" |
| 14 | 14 |
"github.com/moby/moby/v2/daemon/internal/layer" |
| 15 | 15 |
"github.com/moby/moby/v2/daemon/server/backend" |
| 16 |
+ "github.com/moby/moby/v2/daemon/server/buildbackend" |
|
| 16 | 17 |
"github.com/opencontainers/go-digest" |
| 17 | 18 |
ocispec "github.com/opencontainers/image-spec/specs-go/v1" |
| 18 | 19 |
) |
| ... | ... |
@@ -52,7 +53,7 @@ type Backend interface {
|
| 52 | 52 |
|
| 53 | 53 |
// ImageBackend are the interface methods required from an image component |
| 54 | 54 |
type ImageBackend interface {
|
| 55 |
- GetImageAndReleasableLayer(ctx context.Context, refOrID string, opts backend.GetImageAndLayerOptions) (Image, ROLayer, error) |
|
| 55 |
+ GetImageAndReleasableLayer(ctx context.Context, refOrID string, opts buildbackend.GetImageAndLayerOptions) (Image, ROLayer, error) |
|
| 56 | 56 |
} |
| 57 | 57 |
|
| 58 | 58 |
// ExecBackend contains the interface methods required for executing containers |
| ... | ... |
@@ -18,7 +18,7 @@ import ( |
| 18 | 18 |
"github.com/moby/moby/v2/daemon/builder" |
| 19 | 19 |
"github.com/moby/moby/v2/daemon/builder/remotecontext" |
| 20 | 20 |
"github.com/moby/moby/v2/daemon/internal/stringid" |
| 21 |
- "github.com/moby/moby/v2/daemon/server/backend" |
|
| 21 |
+ "github.com/moby/moby/v2/daemon/server/buildbackend" |
|
| 22 | 22 |
"github.com/moby/moby/v2/errdefs" |
| 23 | 23 |
"github.com/moby/sys/user" |
| 24 | 24 |
ocispec "github.com/opencontainers/image-spec/specs-go/v1" |
| ... | ... |
@@ -62,7 +62,7 @@ func NewBuildManager(b builder.Backend, identityMapping user.IdentityMapping) (* |
| 62 | 62 |
} |
| 63 | 63 |
|
| 64 | 64 |
// Build starts a new build from a BuildConfig |
| 65 |
-func (bm *BuildManager) Build(ctx context.Context, config backend.BuildConfig) (*builder.Result, error) {
|
|
| 65 |
+func (bm *BuildManager) Build(ctx context.Context, config buildbackend.BuildConfig) (*builder.Result, error) {
|
|
| 66 | 66 |
buildsTriggered.Inc() |
| 67 | 67 |
if config.Options.Dockerfile == "" {
|
| 68 | 68 |
config.Options.Dockerfile = builder.DefaultDockerfileName |
| ... | ... |
@@ -98,9 +98,9 @@ func (bm *BuildManager) Build(ctx context.Context, config backend.BuildConfig) ( |
| 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 |
- ProgressWriter backend.ProgressWriter |
|
| 103 |
+ ProgressWriter buildbackend.ProgressWriter |
|
| 104 | 104 |
PathCache pathCache |
| 105 | 105 |
IDMapping user.IdentityMapping |
| 106 | 106 |
} |
| ... | ... |
@@ -108,11 +108,11 @@ 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 |
| 115 |
- Aux backend.AuxEmitter |
|
| 115 |
+ Aux buildbackend.AuxEmitter |
|
| 116 | 116 |
Output io.Writer |
| 117 | 117 |
|
| 118 | 118 |
docker builder.Backend |
| ... | ... |
@@ -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) |
| ... | ... |
@@ -217,7 +217,7 @@ func (b *Builder) build(ctx context.Context, source builder.Source, dockerfile * |
| 217 | 217 |
return &builder.Result{ImageID: state.imageID, FromImage: state.baseImage}, nil
|
| 218 | 218 |
} |
| 219 | 219 |
|
| 220 |
-func emitImageID(aux backend.AuxEmitter, state *dispatchState) error {
|
|
| 220 |
+func emitImageID(aux buildbackend.AuxEmitter, state *dispatchState) error {
|
|
| 221 | 221 |
if aux == nil || state.imageID == "" {
|
| 222 | 222 |
return nil |
| 223 | 223 |
} |
| ... | ... |
@@ -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, |
| ... | ... |
@@ -8,7 +8,7 @@ import ( |
| 8 | 8 |
"github.com/containerd/platforms" |
| 9 | 9 |
"github.com/moby/moby/v2/daemon/builder" |
| 10 | 10 |
dockerimage "github.com/moby/moby/v2/daemon/internal/image" |
| 11 |
- "github.com/moby/moby/v2/daemon/server/backend" |
|
| 11 |
+ "github.com/moby/moby/v2/daemon/server/buildbackend" |
|
| 12 | 12 |
ocispec "github.com/opencontainers/image-spec/specs-go/v1" |
| 13 | 13 |
"github.com/pkg/errors" |
| 14 | 14 |
) |
| ... | ... |
@@ -25,15 +25,15 @@ type imageSources struct {
|
| 25 | 25 |
|
| 26 | 26 |
func newImageSources(options builderOptions) *imageSources {
|
| 27 | 27 |
getAndMount := func(ctx context.Context, idOrRef string, localOnly bool, platform *ocispec.Platform) (builder.Image, builder.ROLayer, error) {
|
| 28 |
- pullOption := backend.PullOptionNoPull |
|
| 28 |
+ pullOption := buildbackend.PullOptionNoPull |
|
| 29 | 29 |
if !localOnly {
|
| 30 | 30 |
if options.Options.PullParent {
|
| 31 |
- pullOption = backend.PullOptionForcePull |
|
| 31 |
+ pullOption = buildbackend.PullOptionForcePull |
|
| 32 | 32 |
} else {
|
| 33 |
- pullOption = backend.PullOptionPreferLocal |
|
| 33 |
+ pullOption = buildbackend.PullOptionPreferLocal |
|
| 34 | 34 |
} |
| 35 | 35 |
} |
| 36 |
- return options.Backend.GetImageAndReleasableLayer(ctx, idOrRef, backend.GetImageAndLayerOptions{
|
|
| 36 |
+ return options.Backend.GetImageAndReleasableLayer(ctx, idOrRef, buildbackend.GetImageAndLayerOptions{
|
|
| 37 | 37 |
PullOption: pullOption, |
| 38 | 38 |
AuthConfig: options.Options.AuthConfigs, |
| 39 | 39 |
Output: options.ProgressWriter.Output, |
| ... | ... |
@@ -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,13 +8,12 @@ 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" |
| 15 | 14 |
"github.com/moby/moby/v2/daemon/internal/image" |
| 16 | 15 |
"github.com/moby/moby/v2/daemon/internal/layer" |
| 17 |
- "github.com/moby/moby/v2/daemon/server/backend" |
|
| 16 |
+ "github.com/moby/moby/v2/daemon/server/buildbackend" |
|
| 18 | 17 |
"github.com/opencontainers/go-digest" |
| 19 | 18 |
"gotest.tools/v3/assert" |
| 20 | 19 |
is "gotest.tools/v3/assert/cmp" |
| ... | ... |
@@ -75,8 +74,8 @@ func readAndCheckDockerfile(t *testing.T, testName, contextDir, dockerfilePath, |
| 75 | 75 |
dockerfilePath = builder.DefaultDockerfileName |
| 76 | 76 |
} |
| 77 | 77 |
|
| 78 |
- config := backend.BuildConfig{
|
|
| 79 |
- Options: &build.ImageBuildOptions{Dockerfile: dockerfilePath},
|
|
| 78 |
+ config := buildbackend.BuildConfig{
|
|
| 79 |
+ Options: &buildbackend.BuildOptions{Dockerfile: dockerfilePath},
|
|
| 80 | 80 |
Source: tarStream, |
| 81 | 81 |
} |
| 82 | 82 |
_, _, err = remotecontext.Detect(config) |
| ... | ... |
@@ -12,6 +12,7 @@ import ( |
| 12 | 12 |
"github.com/moby/moby/v2/daemon/internal/image" |
| 13 | 13 |
"github.com/moby/moby/v2/daemon/internal/layer" |
| 14 | 14 |
"github.com/moby/moby/v2/daemon/server/backend" |
| 15 |
+ "github.com/moby/moby/v2/daemon/server/buildbackend" |
|
| 15 | 16 |
"github.com/opencontainers/go-digest" |
| 16 | 17 |
ocispec "github.com/opencontainers/image-spec/specs-go/v1" |
| 17 | 18 |
) |
| ... | ... |
@@ -62,7 +63,7 @@ func (m *MockBackend) CopyOnBuild(containerID string, destPath string, srcRoot s |
| 62 | 62 |
return nil |
| 63 | 63 |
} |
| 64 | 64 |
|
| 65 |
-func (m *MockBackend) GetImageAndReleasableLayer(ctx context.Context, refOrID string, opts backend.GetImageAndLayerOptions) (builder.Image, builder.ROLayer, error) {
|
|
| 65 |
+func (m *MockBackend) GetImageAndReleasableLayer(ctx context.Context, refOrID string, opts buildbackend.GetImageAndLayerOptions) (builder.Image, builder.ROLayer, error) {
|
|
| 66 | 66 |
if m.getImageFunc != nil {
|
| 67 | 67 |
return m.getImageFunc(refOrID) |
| 68 | 68 |
} |
| ... | ... |
@@ -15,7 +15,7 @@ import ( |
| 15 | 15 |
"github.com/moby/buildkit/frontend/dockerfile/parser" |
| 16 | 16 |
"github.com/moby/moby/v2/daemon/builder" |
| 17 | 17 |
"github.com/moby/moby/v2/daemon/builder/remotecontext/urlutil" |
| 18 |
- "github.com/moby/moby/v2/daemon/server/backend" |
|
| 18 |
+ "github.com/moby/moby/v2/daemon/server/buildbackend" |
|
| 19 | 19 |
"github.com/moby/moby/v2/errdefs" |
| 20 | 20 |
"github.com/moby/patternmatcher" |
| 21 | 21 |
"github.com/moby/patternmatcher/ignorefile" |
| ... | ... |
@@ -28,7 +28,7 @@ const ClientSessionRemote = "client-session" |
| 28 | 28 |
|
| 29 | 29 |
// Detect returns a context and dockerfile from remote location or local |
| 30 | 30 |
// archive. |
| 31 |
-func Detect(config backend.BuildConfig) (remote builder.Source, dockerfile *parser.Result, _ error) {
|
|
| 31 |
+func Detect(config buildbackend.BuildConfig) (remote builder.Source, dockerfile *parser.Result, _ error) {
|
|
| 32 | 32 |
remoteURL := config.Options.RemoteContext |
| 33 | 33 |
switch {
|
| 34 | 34 |
case remoteURL == "": |
| ... | ... |
@@ -33,6 +33,7 @@ import ( |
| 33 | 33 |
"github.com/moby/moby/v2/daemon/internal/layer" |
| 34 | 34 |
"github.com/moby/moby/v2/daemon/internal/stringid" |
| 35 | 35 |
"github.com/moby/moby/v2/daemon/server/backend" |
| 36 |
+ "github.com/moby/moby/v2/daemon/server/buildbackend" |
|
| 36 | 37 |
"github.com/moby/moby/v2/errdefs" |
| 37 | 38 |
"github.com/opencontainers/go-digest" |
| 38 | 39 |
"github.com/opencontainers/image-spec/identity" |
| ... | ... |
@@ -64,7 +65,7 @@ const ( |
| 64 | 64 |
// GetImageAndReleasableLayer returns an image and releaseable layer for a |
| 65 | 65 |
// reference or ID. Every call to GetImageAndReleasableLayer MUST call |
| 66 | 66 |
// releasableLayer.Release() to prevent leaking of layers. |
| 67 |
-func (i *ImageService) GetImageAndReleasableLayer(ctx context.Context, refOrID string, opts backend.GetImageAndLayerOptions) (builder.Image, builder.ROLayer, error) {
|
|
| 67 |
+func (i *ImageService) GetImageAndReleasableLayer(ctx context.Context, refOrID string, opts buildbackend.GetImageAndLayerOptions) (builder.Image, builder.ROLayer, error) {
|
|
| 68 | 68 |
if refOrID == "" { // FROM scratch
|
| 69 | 69 |
if runtime.GOOS == "windows" {
|
| 70 | 70 |
return nil, nil, errors.New(`"FROM scratch" is not supported on Windows`) |
| ... | ... |
@@ -80,10 +81,10 @@ func (i *ImageService) GetImageAndReleasableLayer(ctx context.Context, refOrID s |
| 80 | 80 |
}, nil |
| 81 | 81 |
} |
| 82 | 82 |
|
| 83 |
- if opts.PullOption != backend.PullOptionForcePull {
|
|
| 83 |
+ if opts.PullOption != buildbackend.PullOptionForcePull {
|
|
| 84 | 84 |
// TODO(laurazard): same as below |
| 85 | 85 |
img, err := i.GetImage(ctx, refOrID, backend.GetImageOpts{Platform: opts.Platform})
|
| 86 |
- if err != nil && opts.PullOption == backend.PullOptionNoPull {
|
|
| 86 |
+ if err != nil && opts.PullOption == buildbackend.PullOptionNoPull {
|
|
| 87 | 87 |
return nil, nil, err |
| 88 | 88 |
} |
| 89 | 89 |
imgDesc, err := i.resolveDescriptor(ctx, refOrID) |
| ... | ... |
@@ -16,6 +16,7 @@ import ( |
| 16 | 16 |
"github.com/moby/moby/v2/daemon/internal/image" |
| 17 | 17 |
"github.com/moby/moby/v2/daemon/internal/layer" |
| 18 | 18 |
"github.com/moby/moby/v2/daemon/server/backend" |
| 19 |
+ "github.com/moby/moby/v2/daemon/server/buildbackend" |
|
| 19 | 20 |
"github.com/moby/moby/v2/daemon/server/imagebackend" |
| 20 | 21 |
"github.com/opencontainers/go-digest" |
| 21 | 22 |
ocispec "github.com/opencontainers/image-spec/specs-go/v1" |
| ... | ... |
@@ -48,7 +49,7 @@ type ImageService interface {
|
| 48 | 48 |
|
| 49 | 49 |
// Layers |
| 50 | 50 |
|
| 51 |
- GetImageAndReleasableLayer(ctx context.Context, refOrID string, opts backend.GetImageAndLayerOptions) (builder.Image, builder.ROLayer, error) |
|
| 51 |
+ GetImageAndReleasableLayer(ctx context.Context, refOrID string, opts buildbackend.GetImageAndLayerOptions) (builder.Image, builder.ROLayer, error) |
|
| 52 | 52 |
CreateLayer(container *container.Container, initFunc layer.MountInit) (container.RWLayer, error) |
| 53 | 53 |
CreateLayerFromImage(img *image.Image, layerName string, rwLayerOpts *layer.CreateRWLayerOpts) (container.RWLayer, error) |
| 54 | 54 |
GetLayerByID(cid string) (container.RWLayer, error) |
| ... | ... |
@@ -17,6 +17,7 @@ import ( |
| 17 | 17 |
"github.com/moby/moby/v2/daemon/internal/layer" |
| 18 | 18 |
"github.com/moby/moby/v2/daemon/internal/stringid" |
| 19 | 19 |
"github.com/moby/moby/v2/daemon/server/backend" |
| 20 |
+ "github.com/moby/moby/v2/daemon/server/buildbackend" |
|
| 20 | 21 |
"github.com/opencontainers/go-digest" |
| 21 | 22 |
ocispec "github.com/opencontainers/image-spec/specs-go/v1" |
| 22 | 23 |
"github.com/pkg/errors" |
| ... | ... |
@@ -195,7 +196,7 @@ Please notify the image author to correct the configuration.`, |
| 195 | 195 |
// GetImageAndReleasableLayer returns an image and releaseable layer for a reference or ID. |
| 196 | 196 |
// Every call to GetImageAndReleasableLayer MUST call releasableLayer.Release() to prevent |
| 197 | 197 |
// leaking of layers. |
| 198 |
-func (i *ImageService) GetImageAndReleasableLayer(ctx context.Context, refOrID string, opts backend.GetImageAndLayerOptions) (builder.Image, builder.ROLayer, error) {
|
|
| 198 |
+func (i *ImageService) GetImageAndReleasableLayer(ctx context.Context, refOrID string, opts buildbackend.GetImageAndLayerOptions) (builder.Image, builder.ROLayer, error) {
|
|
| 199 | 199 |
if refOrID == "" { // FROM scratch
|
| 200 | 200 |
if runtime.GOOS == "windows" {
|
| 201 | 201 |
return nil, nil, errors.New(`"FROM scratch" is not supported on Windows`) |
| ... | ... |
@@ -209,9 +210,9 @@ func (i *ImageService) GetImageAndReleasableLayer(ctx context.Context, refOrID s |
| 209 | 209 |
return nil, lyr, err |
| 210 | 210 |
} |
| 211 | 211 |
|
| 212 |
- if opts.PullOption != backend.PullOptionForcePull {
|
|
| 212 |
+ if opts.PullOption != buildbackend.PullOptionForcePull {
|
|
| 213 | 213 |
img, err := i.GetImage(ctx, refOrID, backend.GetImageOpts{Platform: opts.Platform})
|
| 214 |
- if err != nil && opts.PullOption == backend.PullOptionNoPull {
|
|
| 214 |
+ if err != nil && opts.PullOption == buildbackend.PullOptionNoPull {
|
|
| 215 | 215 |
return nil, nil, err |
| 216 | 216 |
} |
| 217 | 217 |
if err != nil && !cerrdefs.IsNotFound(err) {
|
| ... | ... |
@@ -32,7 +32,6 @@ import ( |
| 32 | 32 |
"github.com/moby/moby/v2/daemon/internal/timestamp" |
| 33 | 33 |
"github.com/moby/moby/v2/daemon/libnetwork" |
| 34 | 34 |
"github.com/moby/moby/v2/daemon/pkg/opts" |
| 35 |
- "github.com/moby/moby/v2/daemon/server/backend" |
|
| 36 | 35 |
"github.com/moby/moby/v2/daemon/server/buildbackend" |
| 37 | 36 |
"github.com/moby/moby/v2/errdefs" |
| 38 | 37 |
"github.com/moby/sys/user" |
| ... | ... |
@@ -243,7 +242,7 @@ func (b *Builder) Prune(ctx context.Context, opts buildbackend.CachePruneOptions |
| 243 | 243 |
} |
| 244 | 244 |
|
| 245 | 245 |
// Build executes a build request |
| 246 |
-func (b *Builder) Build(ctx context.Context, opt backend.BuildConfig) (*builder.Result, error) {
|
|
| 246 |
+func (b *Builder) Build(ctx context.Context, opt buildbackend.BuildConfig) (*builder.Result, error) {
|
|
| 247 | 247 |
if len(opt.Options.Outputs) > 1 {
|
| 248 | 248 |
return nil, errors.Errorf("multiple outputs not supported")
|
| 249 | 249 |
} |
| 250 | 250 |
deleted file mode 100644 |
| ... | ... |
@@ -1,50 +0,0 @@ |
| 1 |
-package backend |
|
| 2 |
- |
|
| 3 |
-import ( |
|
| 4 |
- "io" |
|
| 5 |
- |
|
| 6 |
- "github.com/moby/moby/api/types/build" |
|
| 7 |
- "github.com/moby/moby/api/types/registry" |
|
| 8 |
- ocispec "github.com/opencontainers/image-spec/specs-go/v1" |
|
| 9 |
-) |
|
| 10 |
- |
|
| 11 |
-// PullOption defines different modes for accessing images |
|
| 12 |
-type PullOption int |
|
| 13 |
- |
|
| 14 |
-const ( |
|
| 15 |
- // PullOptionNoPull only returns local images |
|
| 16 |
- PullOptionNoPull PullOption = iota |
|
| 17 |
- // PullOptionForcePull always tries to pull a ref from the registry first |
|
| 18 |
- PullOptionForcePull |
|
| 19 |
- // PullOptionPreferLocal uses local image if it exists, otherwise pulls |
|
| 20 |
- PullOptionPreferLocal |
|
| 21 |
-) |
|
| 22 |
- |
|
| 23 |
-// ProgressWriter is a data object to transport progress streams to the client |
|
| 24 |
-type ProgressWriter struct {
|
|
| 25 |
- Output io.Writer |
|
| 26 |
- StdoutFormatter io.Writer |
|
| 27 |
- StderrFormatter io.Writer |
|
| 28 |
- AuxFormatter AuxEmitter |
|
| 29 |
- ProgressReaderFunc func(io.ReadCloser) io.ReadCloser |
|
| 30 |
-} |
|
| 31 |
- |
|
| 32 |
-// AuxEmitter is an interface for emitting aux messages during build progress |
|
| 33 |
-type AuxEmitter interface {
|
|
| 34 |
- Emit(string, any) error |
|
| 35 |
-} |
|
| 36 |
- |
|
| 37 |
-// BuildConfig is the configuration used by a BuildManager to start a build |
|
| 38 |
-type BuildConfig struct {
|
|
| 39 |
- Source io.ReadCloser |
|
| 40 |
- ProgressWriter ProgressWriter |
|
| 41 |
- Options *build.ImageBuildOptions |
|
| 42 |
-} |
|
| 43 |
- |
|
| 44 |
-// GetImageAndLayerOptions are the options supported by GetImageAndReleasableLayer |
|
| 45 |
-type GetImageAndLayerOptions struct {
|
|
| 46 |
- PullOption PullOption |
|
| 47 |
- AuthConfig map[string]registry.AuthConfig |
|
| 48 |
- Output io.Writer |
|
| 49 |
- Platform *ocispec.Platform |
|
| 50 |
-} |
| ... | ... |
@@ -1,6 +1,15 @@ |
| 1 | 1 |
package buildbackend |
| 2 | 2 |
|
| 3 |
-import "github.com/moby/moby/api/types/filters" |
|
| 3 |
+import ( |
|
| 4 |
+ "io" |
|
| 5 |
+ |
|
| 6 |
+ ocispec "github.com/opencontainers/image-spec/specs-go/v1" |
|
| 7 |
+ |
|
| 8 |
+ "github.com/moby/moby/api/types/build" |
|
| 9 |
+ "github.com/moby/moby/api/types/container" |
|
| 10 |
+ "github.com/moby/moby/api/types/filters" |
|
| 11 |
+ "github.com/moby/moby/api/types/registry" |
|
| 12 |
+) |
|
| 4 | 13 |
|
| 5 | 14 |
type CachePruneOptions struct {
|
| 6 | 15 |
All bool |
| ... | ... |
@@ -9,3 +18,104 @@ type CachePruneOptions struct {
|
| 9 | 9 |
MinFreeSpace int64 |
| 10 | 10 |
Filters filters.Args |
| 11 | 11 |
} |
| 12 |
+ |
|
| 13 |
+// PullOption defines different modes for accessing images |
|
| 14 |
+type PullOption int |
|
| 15 |
+ |
|
| 16 |
+const ( |
|
| 17 |
+ // PullOptionNoPull only returns local images |
|
| 18 |
+ PullOptionNoPull PullOption = iota |
|
| 19 |
+ // PullOptionForcePull always tries to pull a ref from the registry first |
|
| 20 |
+ PullOptionForcePull |
|
| 21 |
+ // PullOptionPreferLocal uses local image if it exists, otherwise pulls |
|
| 22 |
+ PullOptionPreferLocal |
|
| 23 |
+) |
|
| 24 |
+ |
|
| 25 |
+// ProgressWriter is a data object to transport progress streams to the client |
|
| 26 |
+type ProgressWriter struct {
|
|
| 27 |
+ Output io.Writer |
|
| 28 |
+ StdoutFormatter io.Writer |
|
| 29 |
+ StderrFormatter io.Writer |
|
| 30 |
+ AuxFormatter AuxEmitter |
|
| 31 |
+ ProgressReaderFunc func(io.ReadCloser) io.ReadCloser |
|
| 32 |
+} |
|
| 33 |
+ |
|
| 34 |
+// AuxEmitter is an interface for emitting aux messages during build progress |
|
| 35 |
+type AuxEmitter interface {
|
|
| 36 |
+ Emit(string, any) error |
|
| 37 |
+} |
|
| 38 |
+ |
|
| 39 |
+// BuildConfig is the configuration used by a BuildManager to start a build |
|
| 40 |
+type BuildConfig struct {
|
|
| 41 |
+ Source io.ReadCloser |
|
| 42 |
+ ProgressWriter ProgressWriter |
|
| 43 |
+ Options *BuildOptions |
|
| 44 |
+} |
|
| 45 |
+ |
|
| 46 |
+// BuildOptions holds the information |
|
| 47 |
+// necessary to build images. |
|
| 48 |
+type BuildOptions struct {
|
|
| 49 |
+ Tags []string |
|
| 50 |
+ SuppressOutput bool |
|
| 51 |
+ RemoteContext string |
|
| 52 |
+ NoCache bool |
|
| 53 |
+ Remove bool |
|
| 54 |
+ ForceRemove bool |
|
| 55 |
+ PullParent bool |
|
| 56 |
+ Isolation container.Isolation |
|
| 57 |
+ CPUSetCPUs string |
|
| 58 |
+ CPUSetMems string |
|
| 59 |
+ CPUShares int64 |
|
| 60 |
+ CPUQuota int64 |
|
| 61 |
+ CPUPeriod int64 |
|
| 62 |
+ Memory int64 |
|
| 63 |
+ MemorySwap int64 |
|
| 64 |
+ CgroupParent string |
|
| 65 |
+ NetworkMode string |
|
| 66 |
+ ShmSize int64 |
|
| 67 |
+ Dockerfile string |
|
| 68 |
+ Ulimits []*container.Ulimit |
|
| 69 |
+ // BuildArgs needs to be a *string instead of just a string so that |
|
| 70 |
+ // we can tell the difference between "" (empty string) and no value |
|
| 71 |
+ // at all (nil). See the parsing of buildArgs in |
|
| 72 |
+ // api/server/router/build/build_routes.go for even more info. |
|
| 73 |
+ BuildArgs map[string]*string |
|
| 74 |
+ AuthConfigs map[string]registry.AuthConfig |
|
| 75 |
+ Context io.Reader |
|
| 76 |
+ Labels map[string]string |
|
| 77 |
+ // squash the resulting image's layers to the parent |
|
| 78 |
+ // preserves the original image and creates a new one from the parent with all |
|
| 79 |
+ // the changes applied to a single layer |
|
| 80 |
+ Squash bool |
|
| 81 |
+ // CacheFrom specifies images that are used for matching cache. Images |
|
| 82 |
+ // specified here do not need to have a valid parent chain to match cache. |
|
| 83 |
+ CacheFrom []string |
|
| 84 |
+ SecurityOpt []string |
|
| 85 |
+ ExtraHosts []string // List of extra hosts |
|
| 86 |
+ Target string |
|
| 87 |
+ SessionID string |
|
| 88 |
+ Platform string |
|
| 89 |
+ // Version specifies the version of the underlying builder to use |
|
| 90 |
+ Version build.BuilderVersion |
|
| 91 |
+ // BuildID is an optional identifier that can be passed together with the |
|
| 92 |
+ // build request. The same identifier can be used to gracefully cancel the |
|
| 93 |
+ // build with the cancel request. |
|
| 94 |
+ BuildID string |
|
| 95 |
+ // Outputs defines configurations for exporting build results. Only supported |
|
| 96 |
+ // in BuildKit mode |
|
| 97 |
+ Outputs []BuildOutput |
|
| 98 |
+} |
|
| 99 |
+ |
|
| 100 |
+// BuildOutput defines configuration for exporting a build result |
|
| 101 |
+type BuildOutput struct {
|
|
| 102 |
+ Type string |
|
| 103 |
+ Attrs map[string]string |
|
| 104 |
+} |
|
| 105 |
+ |
|
| 106 |
+// GetImageAndLayerOptions are the options supported by GetImageAndReleasableLayer |
|
| 107 |
+type GetImageAndLayerOptions struct {
|
|
| 108 |
+ PullOption PullOption |
|
| 109 |
+ AuthConfig map[string]registry.AuthConfig |
|
| 110 |
+ Output io.Writer |
|
| 111 |
+ Platform *ocispec.Platform |
|
| 112 |
+} |
| ... | ... |
@@ -4,7 +4,6 @@ import ( |
| 4 | 4 |
"context" |
| 5 | 5 |
|
| 6 | 6 |
"github.com/moby/moby/api/types/build" |
| 7 |
- "github.com/moby/moby/v2/daemon/server/backend" |
|
| 8 | 7 |
"github.com/moby/moby/v2/daemon/server/buildbackend" |
| 9 | 8 |
) |
| 10 | 9 |
|
| ... | ... |
@@ -12,7 +11,7 @@ import ( |
| 12 | 12 |
type Backend interface {
|
| 13 | 13 |
// Build a Docker image returning the id of the image |
| 14 | 14 |
// TODO: make this return a reference instead of string |
| 15 |
- Build(context.Context, backend.BuildConfig) (string, error) |
|
| 15 |
+ Build(context.Context, buildbackend.BuildConfig) (string, error) |
|
| 16 | 16 |
|
| 17 | 17 |
// PruneCache prunes the build cache. |
| 18 | 18 |
PruneCache(context.Context, buildbackend.CachePruneOptions) (*build.CachePruneReport, error) |
| ... | ... |
@@ -23,7 +23,6 @@ import ( |
| 23 | 23 |
"github.com/moby/moby/api/types/filters" |
| 24 | 24 |
"github.com/moby/moby/api/types/registry" |
| 25 | 25 |
"github.com/moby/moby/api/types/versions" |
| 26 |
- "github.com/moby/moby/v2/daemon/server/backend" |
|
| 27 | 26 |
"github.com/moby/moby/v2/daemon/server/buildbackend" |
| 28 | 27 |
"github.com/moby/moby/v2/daemon/server/httputils" |
| 29 | 28 |
"github.com/moby/moby/v2/pkg/ioutils" |
| ... | ... |
@@ -36,8 +35,8 @@ type invalidParam struct {
|
| 36 | 36 |
|
| 37 | 37 |
func (e invalidParam) InvalidParameter() {}
|
| 38 | 38 |
|
| 39 |
-func newImageBuildOptions(ctx context.Context, r *http.Request) (*build.ImageBuildOptions, error) {
|
|
| 40 |
- options := &build.ImageBuildOptions{
|
|
| 39 |
+func newImageBuildOptions(ctx context.Context, r *http.Request) (*buildbackend.BuildOptions, error) {
|
|
| 40 |
+ options := &buildbackend.BuildOptions{
|
|
| 41 | 41 |
Version: build.BuilderV1, // Builder V1 is the default, but can be overridden |
| 42 | 42 |
Dockerfile: r.FormValue("dockerfile"),
|
| 43 | 43 |
SuppressOutput: httputils.BoolValue(r, "q"), |
| ... | ... |
@@ -82,7 +81,7 @@ func newImageBuildOptions(ctx context.Context, r *http.Request) (*build.ImageBui |
| 82 | 82 |
if versions.GreaterThanOrEqualTo(version, "1.40") {
|
| 83 | 83 |
outputsJSON := r.FormValue("outputs")
|
| 84 | 84 |
if outputsJSON != "" {
|
| 85 |
- var outputs []build.ImageBuildOutput |
|
| 85 |
+ var outputs []buildbackend.BuildOutput |
|
| 86 | 86 |
if err := json.Unmarshal([]byte(outputsJSON), &outputs); err != nil {
|
| 87 | 87 |
return nil, invalidParam{errors.Wrap(err, "invalid outputs specified")}
|
| 88 | 88 |
} |
| ... | ... |
@@ -314,7 +313,7 @@ func (br *buildRouter) postBuild(ctx context.Context, w http.ResponseWriter, r * |
| 314 | 314 |
|
| 315 | 315 |
wantAux := versions.GreaterThanOrEqualTo(version, "1.30") |
| 316 | 316 |
|
| 317 |
- imgID, err := br.backend.Build(ctx, backend.BuildConfig{
|
|
| 317 |
+ imgID, err := br.backend.Build(ctx, buildbackend.BuildConfig{
|
|
| 318 | 318 |
Source: body, |
| 319 | 319 |
Options: buildOptions, |
| 320 | 320 |
ProgressWriter: buildProgressWriter(out, wantAux, createProgressReader), |
| ... | ... |
@@ -360,7 +359,7 @@ func (s *syncWriter) Write(b []byte) (int, error) {
|
| 360 | 360 |
return s.w.Write(b) |
| 361 | 361 |
} |
| 362 | 362 |
|
| 363 |
-func buildProgressWriter(out io.Writer, wantAux bool, createProgressReader func(io.ReadCloser) io.ReadCloser) backend.ProgressWriter {
|
|
| 363 |
+func buildProgressWriter(out io.Writer, wantAux bool, createProgressReader func(io.ReadCloser) io.ReadCloser) buildbackend.ProgressWriter {
|
|
| 364 | 364 |
// see https://github.com/moby/moby/pull/21406 |
| 365 | 365 |
out = &syncWriter{w: out}
|
| 366 | 366 |
|
| ... | ... |
@@ -369,7 +368,7 @@ func buildProgressWriter(out io.Writer, wantAux bool, createProgressReader func( |
| 369 | 369 |
aux = &streamformatter.AuxFormatter{Writer: out}
|
| 370 | 370 |
} |
| 371 | 371 |
|
| 372 |
- return backend.ProgressWriter{
|
|
| 372 |
+ return buildbackend.ProgressWriter{
|
|
| 373 | 373 |
Output: out, |
| 374 | 374 |
StdoutFormatter: streamformatter.NewStdoutWriter(out), |
| 375 | 375 |
StderrFormatter: streamformatter.NewStderrWriter(out), |
| ... | ... |
@@ -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 |
+} |