mirror of https://github.com/docker/cli.git
Merge pull request #990 from vdemeester/e2e-iddfile-from-moby
Import TestBuildIidFileSquash from moby to cli
This commit is contained in:
commit
ed335aba8c
|
@ -119,5 +119,12 @@ shellcheck: build_shell_validate_image
|
|||
docker run -ti --rm $(ENVVARS) $(MOUNTS) $(VALIDATE_IMAGE_NAME) make shellcheck
|
||||
|
||||
.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)
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
version: '2.1'
|
||||
|
||||
services:
|
||||
engine:
|
||||
command: ["--insecure-registry=registry:5000", "--experimental"]
|
||||
|
|
@ -2,11 +2,16 @@ package image
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/docker/cli/e2e/internal/fixtures"
|
||||
"github.com/docker/cli/internal/test/environment"
|
||||
"github.com/docker/cli/internal/test/output"
|
||||
"gotest.tools/assert"
|
||||
is "gotest.tools/assert/cmp"
|
||||
"gotest.tools/fs"
|
||||
"gotest.tools/icmd"
|
||||
"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) {
|
||||
return func(cmd *icmd.Cmd) {
|
||||
cmd.Dir = dir.Path()
|
||||
|
|
|
@ -1,12 +1,17 @@
|
|||
package environment
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/docker/docker/client"
|
||||
"github.com/pkg/errors"
|
||||
"gotest.tools/assert"
|
||||
"gotest.tools/poll"
|
||||
"gotest.tools/skip"
|
||||
)
|
||||
|
||||
// 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
|
||||
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")
|
||||
}
|
||||
|
|
|
@ -15,7 +15,10 @@ function fetch_images {
|
|||
|
||||
function setup {
|
||||
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"
|
||||
# TODO: only run if inside a container
|
||||
|
|
|
@ -5,7 +5,6 @@ set -eu -o pipefail
|
|||
engine_host=$(./scripts/test/e2e/run setup)
|
||||
testexit=0
|
||||
|
||||
|
||||
test_cmd="test"
|
||||
if [[ -n "${TEST_DEBUG-}" ]]; then
|
||||
test_cmd="shell"
|
||||
|
|
Loading…
Reference in New Issue