Merge pull request #990 from vdemeester/e2e-iddfile-from-moby

Import TestBuildIidFileSquash from moby to cli
This commit is contained in:
Sebastiaan van Stijn 2018-07-30 11:37:36 +02:00 committed by GitHub
commit ed335aba8c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 72 additions and 3 deletions

View File

@ -119,5 +119,12 @@ shellcheck: build_shell_validate_image
docker run -ti --rm $(ENVVARS) $(MOUNTS) $(VALIDATE_IMAGE_NAME) make shellcheck docker run -ti --rm $(ENVVARS) $(MOUNTS) $(VALIDATE_IMAGE_NAME) make shellcheck
.PHONY: test-e2e .PHONY: test-e2e
test-e2e: build_e2e_image test-e2e: test-e2e-non-experimental test-e2e-experimental
.PHONY: test-e2e-experimental
test-e2e-experimental: build_e2e_image
docker run -e DOCKERD_EXPERIMENTAL=1 --rm -v /var/run/docker.sock:/var/run/docker.sock $(E2E_IMAGE_NAME)
.PHONY: test-e2e-non-experimental
test-e2e-non-experimental: build_e2e_image
docker run --rm -v /var/run/docker.sock:/var/run/docker.sock $(E2E_IMAGE_NAME) docker run --rm -v /var/run/docker.sock:/var/run/docker.sock $(E2E_IMAGE_NAME)

View File

@ -0,0 +1,6 @@
version: '2.1'
services:
engine:
command: ["--insecure-registry=registry:5000", "--experimental"]

View File

@ -2,11 +2,16 @@ package image
import ( import (
"fmt" "fmt"
"io/ioutil"
"path/filepath"
"strings"
"testing" "testing"
"github.com/docker/cli/e2e/internal/fixtures" "github.com/docker/cli/e2e/internal/fixtures"
"github.com/docker/cli/internal/test/environment" "github.com/docker/cli/internal/test/environment"
"github.com/docker/cli/internal/test/output" "github.com/docker/cli/internal/test/output"
"gotest.tools/assert"
is "gotest.tools/assert/cmp"
"gotest.tools/fs" "gotest.tools/fs"
"gotest.tools/icmd" "gotest.tools/icmd"
"gotest.tools/skip" "gotest.tools/skip"
@ -103,6 +108,34 @@ func TestTrustedBuildUntrustedImage(t *testing.T) {
}) })
} }
func TestBuildIidFileSquash(t *testing.T) {
environment.SkipIfNotExperimentalDaemon(t)
dir := fs.NewDir(t, "test-iidfile-squash")
defer dir.Remove()
iidfile := filepath.Join(dir.Path(), "idsquash")
buildDir := fs.NewDir(t, "test-iidfile-squash-build",
fs.WithFile("Dockerfile", fmt.Sprintf(`
FROM %s
ENV FOO FOO
ENV BAR BAR
RUN touch /fiip
RUN touch /foop`, fixtures.AlpineImage)),
)
defer buildDir.Remove()
imageTag := "testbuildiidfilesquash"
result := icmd.RunCmd(
icmd.Command("docker", "build", "--iidfile", iidfile, "--squash", "-t", imageTag, "."),
withWorkingDir(buildDir),
)
result.Assert(t, icmd.Success)
id, err := ioutil.ReadFile(iidfile)
assert.NilError(t, err)
result = icmd.RunCommand("docker", "image", "inspect", "-f", "{{.Id}}", imageTag)
result.Assert(t, icmd.Success)
assert.Check(t, is.Equal(string(id), strings.TrimSpace(result.Combined())))
}
func withWorkingDir(dir *fs.Dir) func(*icmd.Cmd) { func withWorkingDir(dir *fs.Dir) func(*icmd.Cmd) {
return func(cmd *icmd.Cmd) { return func(cmd *icmd.Cmd) {
cmd.Dir = dir.Path() cmd.Dir = dir.Path()

View File

@ -1,12 +1,17 @@
package environment package environment
import ( import (
"context"
"os" "os"
"strings" "strings"
"testing"
"time" "time"
"github.com/docker/docker/client"
"github.com/pkg/errors" "github.com/pkg/errors"
"gotest.tools/assert"
"gotest.tools/poll" "gotest.tools/poll"
"gotest.tools/skip"
) )
// Setup a new environment // Setup a new environment
@ -74,5 +79,21 @@ func boolFromString(val string) bool {
} }
} }
func dockerClient(t *testing.T) client.APIClient {
t.Helper()
c, err := client.NewClientWithOpts(client.FromEnv, client.WithVersion("1.37"))
assert.NilError(t, err)
return c
}
// DefaultPollSettings used with gotestyourself/poll // DefaultPollSettings used with gotestyourself/poll
var DefaultPollSettings = poll.WithDelay(100 * time.Millisecond) var DefaultPollSettings = poll.WithDelay(100 * time.Millisecond)
// SkipIfNotExperimentalDaemon returns whether the test docker daemon is in experimental mode
func SkipIfNotExperimentalDaemon(t *testing.T) {
t.Helper()
c := dockerClient(t)
info, err := c.Info(context.Background())
assert.NilError(t, err)
skip.If(t, !info.ExperimentalBuild, "running against a non-experimental daemon")
}

View File

@ -15,7 +15,10 @@ function fetch_images {
function setup { function setup {
local project=$1 local project=$1
COMPOSE_PROJECT_NAME=$1 COMPOSE_FILE=$2 docker-compose up --build -d >&2 local file=$2
test "${DOCKERD_EXPERIMENTAL:-}" -eq "1" && file="${file}:./e2e/compose-env.experimental.yaml"
COMPOSE_PROJECT_NAME=$project COMPOSE_FILE=$file docker-compose up --build -d >&2
local network="${project}_default" local network="${project}_default"
# TODO: only run if inside a container # TODO: only run if inside a container

View File

@ -5,7 +5,6 @@ set -eu -o pipefail
engine_host=$(./scripts/test/e2e/run setup) engine_host=$(./scripts/test/e2e/run setup)
testexit=0 testexit=0
test_cmd="test" test_cmd="test"
if [[ -n "${TEST_DEBUG-}" ]]; then if [[ -n "${TEST_DEBUG-}" ]]; then
test_cmd="shell" test_cmd="shell"