mirror of
https://github.com/moby/moby.git
synced 2026-08-03 22:51:03 +00:00
api/types/build: move build options to client and backend
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
@@ -7,7 +7,7 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/moby/moby/api/types/build"
|
||||
"github.com/moby/moby/client"
|
||||
"github.com/moby/moby/client/pkg/jsonmessage"
|
||||
"github.com/moby/moby/v2/integration/internal/requirement"
|
||||
"github.com/moby/moby/v2/testutil"
|
||||
@@ -51,14 +51,12 @@ func testBuildWithCgroupNs(ctx context.Context, t *testing.T, daemonNsMode strin
|
||||
source := fakecontext.New(t, "", fakecontext.WithDockerfile(dockerfile))
|
||||
defer source.Close()
|
||||
|
||||
client := d.NewClientT(t)
|
||||
resp, err := client.ImageBuild(ctx,
|
||||
source.AsTarReader(t),
|
||||
build.ImageBuildOptions{
|
||||
Remove: true,
|
||||
ForceRemove: true,
|
||||
Tags: []string{"buildcgroupns"},
|
||||
})
|
||||
apiClient := d.NewClientT(t)
|
||||
resp, err := apiClient.ImageBuild(ctx, source.AsTarReader(t), client.ImageBuildOptions{
|
||||
Remove: true,
|
||||
ForceRemove: true,
|
||||
Tags: []string{"buildcgroupns"},
|
||||
})
|
||||
assert.NilError(t, err)
|
||||
defer resp.Body.Close()
|
||||
|
||||
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/moby/moby/api/pkg/stdcopy"
|
||||
"github.com/moby/moby/api/types/build"
|
||||
"github.com/moby/moby/client"
|
||||
"github.com/moby/moby/v2/integration/internal/container"
|
||||
"github.com/moby/moby/v2/testutil"
|
||||
@@ -51,13 +50,11 @@ func TestBuildSquashParent(t *testing.T) {
|
||||
defer source.Close()
|
||||
|
||||
name := strings.ToLower(t.Name())
|
||||
resp, err := apiClient.ImageBuild(ctx,
|
||||
source.AsTarReader(t),
|
||||
build.ImageBuildOptions{
|
||||
Remove: true,
|
||||
ForceRemove: true,
|
||||
Tags: []string{name},
|
||||
})
|
||||
resp, err := apiClient.ImageBuild(ctx, source.AsTarReader(t), client.ImageBuildOptions{
|
||||
Remove: true,
|
||||
ForceRemove: true,
|
||||
Tags: []string{name},
|
||||
})
|
||||
assert.NilError(t, err)
|
||||
_, err = io.Copy(io.Discard, resp.Body)
|
||||
resp.Body.Close()
|
||||
@@ -70,7 +67,7 @@ func TestBuildSquashParent(t *testing.T) {
|
||||
// build with squash
|
||||
resp, err = apiClient.ImageBuild(ctx,
|
||||
source.AsTarReader(t),
|
||||
build.ImageBuildOptions{
|
||||
client.ImageBuildOptions{
|
||||
Remove: true,
|
||||
ForceRemove: true,
|
||||
Squash: true,
|
||||
|
||||
@@ -110,7 +110,7 @@ func TestBuildWithRemoveAndForceRemove(t *testing.T) {
|
||||
_, err := tw.Write(dockerfile)
|
||||
assert.NilError(t, err)
|
||||
assert.NilError(t, tw.Close())
|
||||
resp, err := apiClient.ImageBuild(ctx, buff, build.ImageBuildOptions{Remove: tc.rm, ForceRemove: tc.forceRm, NoCache: true})
|
||||
resp, err := apiClient.ImageBuild(ctx, buff, client.ImageBuildOptions{Remove: tc.rm, ForceRemove: tc.forceRm, NoCache: true})
|
||||
assert.NilError(t, err)
|
||||
defer resp.Body.Close()
|
||||
filter, err := buildContainerIdsFilter(resp.Body)
|
||||
@@ -163,16 +163,12 @@ func TestBuildMultiStageCopy(t *testing.T) {
|
||||
t.Run(target, func(t *testing.T) {
|
||||
imgName := strings.ToLower(t.Name())
|
||||
|
||||
resp, err := apiclient.ImageBuild(
|
||||
ctx,
|
||||
source.AsTarReader(t),
|
||||
build.ImageBuildOptions{
|
||||
Remove: true,
|
||||
ForceRemove: true,
|
||||
Target: target,
|
||||
Tags: []string{imgName},
|
||||
},
|
||||
)
|
||||
resp, err := apiclient.ImageBuild(ctx, source.AsTarReader(t), client.ImageBuildOptions{
|
||||
Remove: true,
|
||||
ForceRemove: true,
|
||||
Target: target,
|
||||
Tags: []string{imgName},
|
||||
})
|
||||
assert.NilError(t, err)
|
||||
|
||||
out := bytes.NewBuffer(nil)
|
||||
@@ -213,13 +209,11 @@ func TestBuildMultiStageParentConfig(t *testing.T) {
|
||||
|
||||
apiclient := testEnv.APIClient()
|
||||
imgName := strings.ToLower(t.Name())
|
||||
resp, err := apiclient.ImageBuild(ctx,
|
||||
source.AsTarReader(t),
|
||||
build.ImageBuildOptions{
|
||||
Remove: true,
|
||||
ForceRemove: true,
|
||||
Tags: []string{imgName},
|
||||
})
|
||||
resp, err := apiclient.ImageBuild(ctx, source.AsTarReader(t), client.ImageBuildOptions{
|
||||
Remove: true,
|
||||
ForceRemove: true,
|
||||
Tags: []string{imgName},
|
||||
})
|
||||
assert.NilError(t, err)
|
||||
_, err = io.Copy(io.Discard, resp.Body)
|
||||
assert.Check(t, resp.Body.Close())
|
||||
@@ -260,15 +254,13 @@ func TestBuildLabelWithTargets(t *testing.T) {
|
||||
|
||||
apiclient := testEnv.APIClient()
|
||||
// For `target-a` build
|
||||
resp, err := apiclient.ImageBuild(ctx,
|
||||
source.AsTarReader(t),
|
||||
build.ImageBuildOptions{
|
||||
Remove: true,
|
||||
ForceRemove: true,
|
||||
Tags: []string{imgName},
|
||||
Labels: testLabels,
|
||||
Target: "target-a",
|
||||
})
|
||||
resp, err := apiclient.ImageBuild(ctx, source.AsTarReader(t), client.ImageBuildOptions{
|
||||
Remove: true,
|
||||
ForceRemove: true,
|
||||
Tags: []string{imgName},
|
||||
Labels: testLabels,
|
||||
Target: "target-a",
|
||||
})
|
||||
assert.NilError(t, err)
|
||||
_, err = io.Copy(io.Discard, resp.Body)
|
||||
assert.Check(t, resp.Body.Close())
|
||||
@@ -289,7 +281,7 @@ func TestBuildLabelWithTargets(t *testing.T) {
|
||||
delete(testLabels, "label-a")
|
||||
resp, err = apiclient.ImageBuild(ctx,
|
||||
source.AsTarReader(t),
|
||||
build.ImageBuildOptions{
|
||||
client.ImageBuildOptions{
|
||||
Remove: true,
|
||||
ForceRemove: true,
|
||||
Tags: []string{imgName},
|
||||
@@ -328,12 +320,10 @@ COPY 3/ /target/
|
||||
defer source.Close()
|
||||
|
||||
apiclient := testEnv.APIClient()
|
||||
resp, err := apiclient.ImageBuild(ctx,
|
||||
source.AsTarReader(t),
|
||||
build.ImageBuildOptions{
|
||||
Remove: true,
|
||||
ForceRemove: true,
|
||||
})
|
||||
resp, err := apiclient.ImageBuild(ctx, source.AsTarReader(t), client.ImageBuildOptions{
|
||||
Remove: true,
|
||||
ForceRemove: true,
|
||||
})
|
||||
assert.NilError(t, err)
|
||||
_, err = io.Copy(io.Discard, resp.Body)
|
||||
assert.Check(t, resp.Body.Close())
|
||||
@@ -364,12 +354,10 @@ RUN cat somefile`
|
||||
defer source.Close()
|
||||
|
||||
apiclient := testEnv.APIClient()
|
||||
resp, err := apiclient.ImageBuild(ctx,
|
||||
source.AsTarReader(t),
|
||||
build.ImageBuildOptions{
|
||||
Remove: true,
|
||||
ForceRemove: true,
|
||||
})
|
||||
resp, err := apiclient.ImageBuild(ctx, source.AsTarReader(t), client.ImageBuildOptions{
|
||||
Remove: true,
|
||||
ForceRemove: true,
|
||||
})
|
||||
|
||||
out := bytes.NewBuffer(nil)
|
||||
assert.NilError(t, err)
|
||||
@@ -410,12 +398,10 @@ COPY bar /
|
||||
assert.NilError(t, err)
|
||||
|
||||
apiclient := testEnv.APIClient()
|
||||
resp, err := apiclient.ImageBuild(ctx,
|
||||
buf,
|
||||
build.ImageBuildOptions{
|
||||
Remove: true,
|
||||
ForceRemove: true,
|
||||
})
|
||||
resp, err := apiclient.ImageBuild(ctx, buf, client.ImageBuildOptions{
|
||||
Remove: true,
|
||||
ForceRemove: true,
|
||||
})
|
||||
|
||||
out := bytes.NewBuffer(nil)
|
||||
assert.NilError(t, err)
|
||||
@@ -435,7 +421,7 @@ COPY bar /
|
||||
|
||||
resp, err = apiclient.ImageBuild(ctx,
|
||||
buf,
|
||||
build.ImageBuildOptions{
|
||||
client.ImageBuildOptions{
|
||||
Remove: true,
|
||||
ForceRemove: true,
|
||||
})
|
||||
@@ -472,12 +458,10 @@ RUN [ ! -f foo ]
|
||||
defer source.Close()
|
||||
|
||||
apiClient := testEnv.APIClient()
|
||||
resp, err := apiClient.ImageBuild(ctx,
|
||||
source.AsTarReader(t),
|
||||
build.ImageBuildOptions{
|
||||
Remove: true,
|
||||
ForceRemove: true,
|
||||
})
|
||||
resp, err := apiClient.ImageBuild(ctx, source.AsTarReader(t), client.ImageBuildOptions{
|
||||
Remove: true,
|
||||
ForceRemove: true,
|
||||
})
|
||||
|
||||
out := bytes.NewBuffer(nil)
|
||||
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
|
||||
assert.NilError(t, err)
|
||||
|
||||
apiClient := testEnv.APIClient()
|
||||
resp, err := apiClient.ImageBuild(ctx,
|
||||
buf,
|
||||
build.ImageBuildOptions{
|
||||
Remove: true,
|
||||
ForceRemove: true,
|
||||
})
|
||||
resp, err := apiClient.ImageBuild(ctx, buf, client.ImageBuildOptions{
|
||||
Remove: true,
|
||||
ForceRemove: true,
|
||||
})
|
||||
|
||||
out := bytes.NewBuffer(nil)
|
||||
assert.NilError(t, err)
|
||||
@@ -559,12 +541,10 @@ COPY --from=intermediate C:\\stuff C:\\stuff
|
||||
assert.NilError(t, err)
|
||||
|
||||
apiClient := testEnv.APIClient()
|
||||
resp, err := apiClient.ImageBuild(ctx,
|
||||
buf,
|
||||
build.ImageBuildOptions{
|
||||
Remove: true,
|
||||
ForceRemove: true,
|
||||
})
|
||||
resp, err := apiClient.ImageBuild(ctx, buf, client.ImageBuildOptions{
|
||||
Remove: true,
|
||||
ForceRemove: true,
|
||||
})
|
||||
|
||||
out := bytes.NewBuffer(nil)
|
||||
assert.NilError(t, err)
|
||||
@@ -626,7 +606,7 @@ func TestBuildWithEmptyDockerfile(t *testing.T) {
|
||||
|
||||
_, err = apiClient.ImageBuild(ctx,
|
||||
buf,
|
||||
build.ImageBuildOptions{
|
||||
client.ImageBuildOptions{
|
||||
Remove: true,
|
||||
ForceRemove: true,
|
||||
})
|
||||
@@ -653,15 +633,11 @@ func TestBuildPreserveOwnership(t *testing.T) {
|
||||
t.Run(target, func(t *testing.T) {
|
||||
ctx := testutil.StartSpan(ctx, t)
|
||||
|
||||
resp, err := apiClient.ImageBuild(
|
||||
ctx,
|
||||
source.AsTarReader(t),
|
||||
build.ImageBuildOptions{
|
||||
Remove: true,
|
||||
ForceRemove: true,
|
||||
Target: target,
|
||||
},
|
||||
)
|
||||
resp, err := apiClient.ImageBuild(ctx, source.AsTarReader(t), client.ImageBuildOptions{
|
||||
Remove: true,
|
||||
ForceRemove: true,
|
||||
Target: target,
|
||||
})
|
||||
assert.NilError(t, err)
|
||||
|
||||
out := bytes.NewBuffer(nil)
|
||||
@@ -684,7 +660,7 @@ func TestBuildPlatformInvalid(t *testing.T) {
|
||||
err := w.Close()
|
||||
assert.NilError(t, err)
|
||||
|
||||
_, err = testEnv.APIClient().ImageBuild(ctx, buf, build.ImageBuildOptions{
|
||||
_, err = testEnv.APIClient().ImageBuild(ctx, buf, client.ImageBuildOptions{
|
||||
Remove: true,
|
||||
ForceRemove: true,
|
||||
Platform: "foobar",
|
||||
@@ -713,7 +689,7 @@ func TestBuildWorkdirNoCacheMiss(t *testing.T) {
|
||||
apiClient := testEnv.APIClient()
|
||||
|
||||
buildAndGetID := func() string {
|
||||
resp, err := apiClient.ImageBuild(ctx, source.AsTarReader(t), build.ImageBuildOptions{
|
||||
resp, err := apiClient.ImageBuild(ctx, source.AsTarReader(t), client.ImageBuildOptions{
|
||||
Version: build.BuilderV1,
|
||||
})
|
||||
assert.NilError(t, err)
|
||||
@@ -752,7 +728,7 @@ func TestBuildEmitsImageCreateEvent(t *testing.T) {
|
||||
|
||||
since := time.Now()
|
||||
|
||||
resp, err := apiClient.ImageBuild(ctx, source.AsTarReader(t), build.ImageBuildOptions{
|
||||
resp, err := apiClient.ImageBuild(ctx, source.AsTarReader(t), client.ImageBuildOptions{
|
||||
Version: builderVersion,
|
||||
NoCache: true,
|
||||
})
|
||||
@@ -807,7 +783,7 @@ func TestBuildHistoryDoesNotPreventRemoval(t *testing.T) {
|
||||
apiClient := testEnv.APIClient()
|
||||
|
||||
buildImage := func(imgName string) error {
|
||||
resp, err := apiClient.ImageBuild(ctx, source.AsTarReader(t), build.ImageBuildOptions{
|
||||
resp, err := apiClient.ImageBuild(ctx, source.AsTarReader(t), client.ImageBuildOptions{
|
||||
Remove: true,
|
||||
ForceRemove: true,
|
||||
Tags: []string{imgName},
|
||||
|
||||
@@ -10,7 +10,6 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/moby/moby/api/pkg/stdcopy"
|
||||
"github.com/moby/moby/api/types/build"
|
||||
"github.com/moby/moby/client"
|
||||
"github.com/moby/moby/client/pkg/jsonmessage"
|
||||
"github.com/moby/moby/v2/integration/internal/container"
|
||||
@@ -64,11 +63,9 @@ func TestBuildUserNamespaceValidateCapabilitiesAreV2(t *testing.T) {
|
||||
source := fakecontext.New(t, "", fakecontext.WithDockerfile(dockerfile))
|
||||
defer source.Close()
|
||||
|
||||
resp, err := clientUserRemap.ImageBuild(ctx,
|
||||
source.AsTarReader(t),
|
||||
build.ImageBuildOptions{
|
||||
Tags: []string{imageTag},
|
||||
})
|
||||
resp, err := clientUserRemap.ImageBuild(ctx, source.AsTarReader(t), client.ImageBuildOptions{
|
||||
Tags: []string{imageTag},
|
||||
})
|
||||
assert.NilError(t, err)
|
||||
defer resp.Body.Close()
|
||||
|
||||
|
||||
@@ -7,9 +7,8 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/moby/moby/api/pkg/stdcopy"
|
||||
"github.com/moby/moby/api/types/build"
|
||||
containertypes "github.com/moby/moby/api/types/container"
|
||||
client2 "github.com/moby/moby/client"
|
||||
"github.com/moby/moby/client"
|
||||
"github.com/moby/moby/v2/integration/internal/container"
|
||||
"github.com/moby/moby/v2/testutil"
|
||||
"github.com/moby/moby/v2/testutil/fakecontext"
|
||||
@@ -32,14 +31,12 @@ func TestNoNewPrivileges(t *testing.T) {
|
||||
source := fakecontext.New(t, "", fakecontext.WithDockerfile(withFileCapability))
|
||||
defer source.Close()
|
||||
|
||||
client := testEnv.APIClient()
|
||||
apiClient := testEnv.APIClient()
|
||||
|
||||
// Build image
|
||||
resp, err := client.ImageBuild(ctx,
|
||||
source.AsTarReader(t),
|
||||
build.ImageBuildOptions{
|
||||
Tags: []string{imageTag},
|
||||
})
|
||||
resp, err := apiClient.ImageBuild(ctx, source.AsTarReader(t), client.ImageBuildOptions{
|
||||
Tags: []string{imageTag},
|
||||
})
|
||||
assert.NilError(t, err)
|
||||
_, err = io.Copy(io.Discard, resp.Body)
|
||||
assert.NilError(t, err)
|
||||
@@ -78,11 +75,11 @@ func TestNoNewPrivileges(t *testing.T) {
|
||||
container.WithCmd("/bin/cat", "/txt"),
|
||||
container.WithSecurityOpt("no-new-privileges=true"),
|
||||
)
|
||||
cid := container.Run(ctx, t, client, opts...)
|
||||
poll.WaitOn(t, container.IsInState(ctx, client, cid, containertypes.StateExited))
|
||||
cid := container.Run(ctx, t, apiClient, opts...)
|
||||
poll.WaitOn(t, container.IsInState(ctx, apiClient, cid, containertypes.StateExited))
|
||||
|
||||
// Assert on outputs
|
||||
logReader, err := client.ContainerLogs(ctx, cid, client2.ContainerLogsOptions{
|
||||
logReader, err := apiClient.ContainerLogs(ctx, cid, client.ContainerLogsOptions{
|
||||
ShowStdout: true,
|
||||
ShowStderr: true,
|
||||
})
|
||||
|
||||
@@ -213,7 +213,7 @@ func makeTestImage(ctx context.Context, t *testing.T) (imageID string) {
|
||||
`))
|
||||
defer buildCtx.Close()
|
||||
|
||||
resp, err := apiClient.ImageBuild(ctx, buildCtx.AsTarReader(t), build.ImageBuildOptions{})
|
||||
resp, err := apiClient.ImageBuild(ctx, buildCtx.AsTarReader(t), client.ImageBuildOptions{})
|
||||
assert.NilError(t, err)
|
||||
defer resp.Body.Close()
|
||||
|
||||
@@ -287,7 +287,7 @@ func TestCopyFromContainer(t *testing.T) {
|
||||
`))
|
||||
defer buildCtx.Close()
|
||||
|
||||
resp, err := apiClient.ImageBuild(ctx, buildCtx.AsTarReader(t), build.ImageBuildOptions{})
|
||||
resp, err := apiClient.ImageBuild(ctx, buildCtx.AsTarReader(t), client.ImageBuildOptions{})
|
||||
assert.NilError(t, err)
|
||||
defer resp.Body.Close()
|
||||
|
||||
|
||||
@@ -68,7 +68,7 @@ func TestAPIImageHistoryCrossPlatform(t *testing.T) {
|
||||
defer buildCtx.Close()
|
||||
|
||||
// Build the image for a non-native platform
|
||||
resp, err := apiClient.ImageBuild(ctx, buildCtx.AsTarReader(t), buildtypes.ImageBuildOptions{
|
||||
resp, err := apiClient.ImageBuild(ctx, buildCtx.AsTarReader(t), client.ImageBuildOptions{
|
||||
Version: buildtypes.BuilderBuildKit,
|
||||
Tags: []string{"cross-platform-test"},
|
||||
Platform: platforms.FormatAll(nonNativePlatform),
|
||||
|
||||
@@ -18,7 +18,7 @@ import (
|
||||
|
||||
// Do builds an image from the given context and returns the image ID.
|
||||
func Do(ctx context.Context, t *testing.T, apiClient client.APIClient, buildCtx *fakecontext.Fake) string {
|
||||
resp, err := apiClient.ImageBuild(ctx, buildCtx.AsTarReader(t), build.ImageBuildOptions{})
|
||||
resp, err := apiClient.ImageBuild(ctx, buildCtx.AsTarReader(t), client.ImageBuildOptions{})
|
||||
if resp.Body != nil {
|
||||
defer resp.Body.Close()
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/moby/moby/api/types/build"
|
||||
containertypes "github.com/moby/moby/api/types/container"
|
||||
"github.com/moby/moby/api/types/mount"
|
||||
"github.com/moby/moby/api/types/network"
|
||||
@@ -320,13 +319,11 @@ func setupTestImage(t *testing.T, ctx context.Context, apiClient client.APIClien
|
||||
)
|
||||
defer source.Close()
|
||||
|
||||
resp, err := apiClient.ImageBuild(ctx,
|
||||
source.AsTarReader(t),
|
||||
build.ImageBuildOptions{
|
||||
Remove: false,
|
||||
ForceRemove: false,
|
||||
Tags: []string{imgName},
|
||||
})
|
||||
resp, err := apiClient.ImageBuild(ctx, source.AsTarReader(t), client.ImageBuildOptions{
|
||||
Remove: false,
|
||||
ForceRemove: false,
|
||||
Tags: []string{imgName},
|
||||
})
|
||||
assert.NilError(t, err)
|
||||
|
||||
out := bytes.NewBuffer(nil)
|
||||
|
||||
Reference in New Issue
Block a user