From 5d70a97b1fff8286220d2bef9ceb248401f046d1 Mon Sep 17 00:00:00 2001 From: Srini Brahmaroutu Date: Thu, 26 Feb 2015 19:20:32 +0000 Subject: [PATCH 1/2] Fix the TestPullImageFromCentralRegistry to skip and add local v1 registry test when net=none Closes #10966 Signed-off-by: Srini Brahmaroutu --- Dockerfile | 3 ++ hack/make/.ensure-registry | 10 ++++++ hack/make/.integration-daemon-start | 1 + hack/make/test-integration-cli | 1 + integration-cli/docker_cli_pull_test.go | 29 +++++++++++++++ integration-cli/docker_test_vars.go | 3 +- integration-cli/registry.go | 47 +++++++++++++++++++++++++ 7 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 hack/make/.ensure-registry diff --git a/Dockerfile b/Dockerfile index b064076137..7d14be8242 100644 --- a/Dockerfile +++ b/Dockerfile @@ -164,6 +164,9 @@ RUN set -x \ && (cd /go/src/github.com/BurntSushi/toml && git checkout -q $TOMLV_COMMIT) \ && go install -v github.com/BurntSushi/toml/cmd/tomlv +COPY contrib/download-frozen-image.sh /go/src/github.com/docker/docker/contrib/ +RUN ./contrib/download-frozen-image.sh ./integration-cli/registry registry + # Wrap all commands in the "docker-in-docker" script to allow nested containers ENTRYPOINT ["hack/dind"] diff --git a/hack/make/.ensure-registry b/hack/make/.ensure-registry new file mode 100644 index 0000000000..f4dec2ee45 --- /dev/null +++ b/hack/make/.ensure-registry @@ -0,0 +1,10 @@ +#!/bin/bash +set -e + +if ! docker inspect registry > /dev/null; then + if [ -d /docker-registry ]; then + ( set -x; docker build -t registry /docker-registry ) + else + ( set -x; tar -cC integration-cli/registry . | docker load & ) + fi +fi diff --git a/hack/make/.integration-daemon-start b/hack/make/.integration-daemon-start index 570c6c7a9a..e4f9762aa9 100644 --- a/hack/make/.integration-daemon-start +++ b/hack/make/.integration-daemon-start @@ -19,6 +19,7 @@ if [ -z "$DOCKER_TEST_HOST" ]; then export DOCKER_HOST="unix://$(cd "$DEST" && pwd)/docker.sock" # "pwd" tricks to make sure $DEST is an absolute path, not a relative one ( set -x; exec \ docker --daemon --debug \ + --insecure-registry 0.0.0.0:5000 \ --host "$DOCKER_HOST" \ --storage-driver "$DOCKER_GRAPHDRIVER" \ --exec-driver "$DOCKER_EXECDRIVER" \ diff --git a/hack/make/test-integration-cli b/hack/make/test-integration-cli index 3ef41d919e..23058ccfd9 100644 --- a/hack/make/test-integration-cli +++ b/hack/make/test-integration-cli @@ -18,6 +18,7 @@ bundle_test_integration_cli() { if ! { source "$(dirname "$BASH_SOURCE")/.ensure-frozen-images" source "$(dirname "$BASH_SOURCE")/.ensure-httpserver" + source "$(dirname "$BASH_SOURCE")/.ensure-registry" source "$(dirname "$BASH_SOURCE")/.ensure-emptyfs" bundle_test_integration_cli diff --git a/integration-cli/docker_cli_pull_test.go b/integration-cli/docker_cli_pull_test.go index 39b0eae3ff..efecbdf017 100644 --- a/integration-cli/docker_cli_pull_test.go +++ b/integration-cli/docker_cli_pull_test.go @@ -85,6 +85,8 @@ func TestPullVerified(t *testing.T) { // pulling an image from the central registry should work func TestPullImageFromCentralRegistry(t *testing.T) { + testRequires(t, Network) + defer deleteImages("hello-world") pullCmd := exec.Command(dockerBinary, "pull", "hello-world") @@ -94,6 +96,33 @@ func TestPullImageFromCentralRegistry(t *testing.T) { logDone("pull - pull hello-world") } +// pulling an image from the local registry should work +func TestPullImageFromlocalRegistry(t *testing.T) { + defer deleteAllContainers() + + if err := startRegistryV1(); err != nil { + t.Fatal(err) + } + repoName := privateV1RegistryURL + defer deleteImages(repoName) + + repo := fmt.Sprintf("%v/%v:%v", repoName, "busybox", "latest") + if out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "tag", "busybox", repo)); err != nil { + t.Fatalf("Failed to tag image %v: error %v, output %q", repo, err, out) + } + defer deleteImages(repo) + + if out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "push", repo)); err != nil { + t.Fatalf("Failed to push image %v: error %v, output %q", repo, err, string(out)) + } + + pullCmd := exec.Command(dockerBinary, "pull", repo) + if out, _, err := runCommandWithOutput(pullCmd); err != nil { + t.Fatalf("pulling the hello-world image from the registry has failed: %s, %v", out, err) + } + logDone("pull - pull local hello-world") +} + // pulling a non-existing image from the central registry should return a non-zero exit code func TestPullNonExistingImage(t *testing.T) { pullCmd := exec.Command(dockerBinary, "pull", "fooblahblah1234") diff --git a/integration-cli/docker_test_vars.go b/integration-cli/docker_test_vars.go index ff2ec74063..a46b2ce642 100644 --- a/integration-cli/docker_test_vars.go +++ b/integration-cli/docker_test_vars.go @@ -14,7 +14,8 @@ var ( registryImageName = "registry" // the private registry to use for tests - privateRegistryURL = "127.0.0.1:5000" + privateRegistryURL = "127.0.0.1:5000" + privateV1RegistryURL = "0.0.0.0:5000" dockerBasePath = "/var/lib/docker" execDriverPath = dockerBasePath + "/execdriver/native" diff --git a/integration-cli/registry.go b/integration-cli/registry.go index 8290e710fd..32ed5a7b8e 100644 --- a/integration-cli/registry.go +++ b/integration-cli/registry.go @@ -7,7 +7,9 @@ import ( "os" "os/exec" "path/filepath" + "strings" "testing" + "time" ) const v2binary = "registry-v2" @@ -69,3 +71,48 @@ func (r *testRegistryV2) Close() { r.cmd.Process.Kill() os.RemoveAll(r.dir) } + +func pingV1(ip string) error { + // We always ping through HTTP for our test registry. + resp, err := http.Get(fmt.Sprintf("http://%s/v1/search", ip)) + if err != nil { + return err + } + if resp.StatusCode != 200 { + return fmt.Errorf("registry ping replied with an unexpected status code %d", resp.StatusCode) + } + return nil +} + +func startRegistryV1() error { + //wait for registry image to be available + for i := 0; i < 10; i++ { + imagesCmd := exec.Command(dockerBinary, "images") + out, _, err := runCommandWithOutput(imagesCmd) + if err != nil { + return err + } + if strings.Contains(out, "registry") { + break + } + time.Sleep(60000 * time.Millisecond) + if i == 10 { + fmt.Errorf("No registry image is found to start the regictry V1 services") + } + } + + if out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "--name", "regserver", "-d", "-p", "5000:5000", "registry", "docker-registry")); err != nil { + fmt.Errorf("Failed to start registry: error %v, output %q", err, out) + } + ip := privateV1RegistryURL + //wait until registry server is available + for i := 0; i < 10; i++ { + if err := pingV1(ip); err == nil { + return nil + } else if i == 10 && err != nil { + return err + } + time.Sleep(2000 * time.Millisecond) + } + return nil +} From 8900ae2928cea8f4b5d52ff68253cad2504edd6c Mon Sep 17 00:00:00 2001 From: Arnaud Porterie Date: Tue, 24 Mar 2015 16:27:35 -0700 Subject: [PATCH 2/2] Revert all but TestPullImageFromCentralRegistry changes Signed-off-by: Arnaud Porterie --- Dockerfile | 3 -- hack/make/.ensure-registry | 10 ------ hack/make/.integration-daemon-start | 1 - hack/make/test-integration-cli | 1 - integration-cli/docker_cli_pull_test.go | 27 -------------- integration-cli/docker_test_vars.go | 3 +- integration-cli/registry.go | 47 ------------------------- 7 files changed, 1 insertion(+), 91 deletions(-) delete mode 100644 hack/make/.ensure-registry diff --git a/Dockerfile b/Dockerfile index 7d14be8242..b064076137 100644 --- a/Dockerfile +++ b/Dockerfile @@ -164,9 +164,6 @@ RUN set -x \ && (cd /go/src/github.com/BurntSushi/toml && git checkout -q $TOMLV_COMMIT) \ && go install -v github.com/BurntSushi/toml/cmd/tomlv -COPY contrib/download-frozen-image.sh /go/src/github.com/docker/docker/contrib/ -RUN ./contrib/download-frozen-image.sh ./integration-cli/registry registry - # Wrap all commands in the "docker-in-docker" script to allow nested containers ENTRYPOINT ["hack/dind"] diff --git a/hack/make/.ensure-registry b/hack/make/.ensure-registry deleted file mode 100644 index f4dec2ee45..0000000000 --- a/hack/make/.ensure-registry +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash -set -e - -if ! docker inspect registry > /dev/null; then - if [ -d /docker-registry ]; then - ( set -x; docker build -t registry /docker-registry ) - else - ( set -x; tar -cC integration-cli/registry . | docker load & ) - fi -fi diff --git a/hack/make/.integration-daemon-start b/hack/make/.integration-daemon-start index e4f9762aa9..570c6c7a9a 100644 --- a/hack/make/.integration-daemon-start +++ b/hack/make/.integration-daemon-start @@ -19,7 +19,6 @@ if [ -z "$DOCKER_TEST_HOST" ]; then export DOCKER_HOST="unix://$(cd "$DEST" && pwd)/docker.sock" # "pwd" tricks to make sure $DEST is an absolute path, not a relative one ( set -x; exec \ docker --daemon --debug \ - --insecure-registry 0.0.0.0:5000 \ --host "$DOCKER_HOST" \ --storage-driver "$DOCKER_GRAPHDRIVER" \ --exec-driver "$DOCKER_EXECDRIVER" \ diff --git a/hack/make/test-integration-cli b/hack/make/test-integration-cli index 23058ccfd9..3ef41d919e 100644 --- a/hack/make/test-integration-cli +++ b/hack/make/test-integration-cli @@ -18,7 +18,6 @@ bundle_test_integration_cli() { if ! { source "$(dirname "$BASH_SOURCE")/.ensure-frozen-images" source "$(dirname "$BASH_SOURCE")/.ensure-httpserver" - source "$(dirname "$BASH_SOURCE")/.ensure-registry" source "$(dirname "$BASH_SOURCE")/.ensure-emptyfs" bundle_test_integration_cli diff --git a/integration-cli/docker_cli_pull_test.go b/integration-cli/docker_cli_pull_test.go index efecbdf017..6e5ddb8408 100644 --- a/integration-cli/docker_cli_pull_test.go +++ b/integration-cli/docker_cli_pull_test.go @@ -96,33 +96,6 @@ func TestPullImageFromCentralRegistry(t *testing.T) { logDone("pull - pull hello-world") } -// pulling an image from the local registry should work -func TestPullImageFromlocalRegistry(t *testing.T) { - defer deleteAllContainers() - - if err := startRegistryV1(); err != nil { - t.Fatal(err) - } - repoName := privateV1RegistryURL - defer deleteImages(repoName) - - repo := fmt.Sprintf("%v/%v:%v", repoName, "busybox", "latest") - if out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "tag", "busybox", repo)); err != nil { - t.Fatalf("Failed to tag image %v: error %v, output %q", repo, err, out) - } - defer deleteImages(repo) - - if out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "push", repo)); err != nil { - t.Fatalf("Failed to push image %v: error %v, output %q", repo, err, string(out)) - } - - pullCmd := exec.Command(dockerBinary, "pull", repo) - if out, _, err := runCommandWithOutput(pullCmd); err != nil { - t.Fatalf("pulling the hello-world image from the registry has failed: %s, %v", out, err) - } - logDone("pull - pull local hello-world") -} - // pulling a non-existing image from the central registry should return a non-zero exit code func TestPullNonExistingImage(t *testing.T) { pullCmd := exec.Command(dockerBinary, "pull", "fooblahblah1234") diff --git a/integration-cli/docker_test_vars.go b/integration-cli/docker_test_vars.go index a46b2ce642..ff2ec74063 100644 --- a/integration-cli/docker_test_vars.go +++ b/integration-cli/docker_test_vars.go @@ -14,8 +14,7 @@ var ( registryImageName = "registry" // the private registry to use for tests - privateRegistryURL = "127.0.0.1:5000" - privateV1RegistryURL = "0.0.0.0:5000" + privateRegistryURL = "127.0.0.1:5000" dockerBasePath = "/var/lib/docker" execDriverPath = dockerBasePath + "/execdriver/native" diff --git a/integration-cli/registry.go b/integration-cli/registry.go index 32ed5a7b8e..8290e710fd 100644 --- a/integration-cli/registry.go +++ b/integration-cli/registry.go @@ -7,9 +7,7 @@ import ( "os" "os/exec" "path/filepath" - "strings" "testing" - "time" ) const v2binary = "registry-v2" @@ -71,48 +69,3 @@ func (r *testRegistryV2) Close() { r.cmd.Process.Kill() os.RemoveAll(r.dir) } - -func pingV1(ip string) error { - // We always ping through HTTP for our test registry. - resp, err := http.Get(fmt.Sprintf("http://%s/v1/search", ip)) - if err != nil { - return err - } - if resp.StatusCode != 200 { - return fmt.Errorf("registry ping replied with an unexpected status code %d", resp.StatusCode) - } - return nil -} - -func startRegistryV1() error { - //wait for registry image to be available - for i := 0; i < 10; i++ { - imagesCmd := exec.Command(dockerBinary, "images") - out, _, err := runCommandWithOutput(imagesCmd) - if err != nil { - return err - } - if strings.Contains(out, "registry") { - break - } - time.Sleep(60000 * time.Millisecond) - if i == 10 { - fmt.Errorf("No registry image is found to start the regictry V1 services") - } - } - - if out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "--name", "regserver", "-d", "-p", "5000:5000", "registry", "docker-registry")); err != nil { - fmt.Errorf("Failed to start registry: error %v, output %q", err, out) - } - ip := privateV1RegistryURL - //wait until registry server is available - for i := 0; i < 10; i++ { - if err := pingV1(ip); err == nil { - return nil - } else if i == 10 && err != nil { - return err - } - time.Sleep(2000 * time.Millisecond) - } - return nil -}