diff --git a/auth/auth.go b/auth/auth.go index 5a5987ace8..c94d2cfaed 100644 --- a/auth/auth.go +++ b/auth/auth.go @@ -33,6 +33,13 @@ func NewAuthConfig(username, password, email, rootPath string) *AuthConfig { } } +func IndexServerAddress() string { + if os.Getenv("DOCKER_INDEX_URL") != "" { + return os.Getenv("DOCKER_INDEX_URL") + } + return INDEX_SERVER +} + // create a base64 encoded auth string to store in config func EncodeAuth(authConfig *AuthConfig) string { authStr := authConfig.Username + ":" + authConfig.Password diff --git a/registry.go b/registry.go index b8a3e10599..3138e9fbf8 100644 --- a/registry.go +++ b/registry.go @@ -15,8 +15,7 @@ import ( "strings" ) -//FIXME: Set the endpoint in a conf file or via commandline -const INDEX_ENDPOINT = auth.INDEX_SERVER + "/v1" +var INDEX_ENDPOINT = auth.IndexServerAddress() + "/v1" // Build an Image object from raw json data func NewImgJson(src []byte) (*Image, error) { diff --git a/registry_test.go b/registry_test.go new file mode 100644 index 0000000000..aa92836e08 --- /dev/null +++ b/registry_test.go @@ -0,0 +1,64 @@ +package docker + +import ( + "os" + "testing" +) + +func TestPull(t* testing.T) { + runtime, err := newTestRuntime() + if err != nil { + t.Fatal(err) + } + defer nuke(runtime) + + err = runtime.graph.PullRepository(os.Stdout, "busybox", "", runtime.repositories, nil) + if err != nil { + t.Fatal(err) + } + img, err := runtime.repositories.LookupImage("busybox") + if err != nil { + t.Fatal(err) + } + + // Try to run something on this image to make sure the layer's been downloaded properly. + config, err := ParseRun([]string{img.Id, "echo", "Hello World"}, os.Stdout, runtime.capabilities) + if err != nil { + t.Fatal(err) + } + + b := NewBuilder(runtime) + container, err := b.Create(config) + if err != nil { + t.Fatal(err) + } + if err := container.Start(); err != nil { + t.Fatal(err) + } + + if status := container.Wait(); status != 0 { + t.Fatalf("Expected status code 0, found %d instead", status) + } +} + +func TestPullTag(t* testing.T) { + runtime, err := newTestRuntime() + if err != nil { + t.Fatal(err) + } + defer nuke(runtime) + + err = runtime.graph.PullRepository(os.Stdout, "ubuntu", "12.04", runtime.repositories, nil) + if err != nil { + t.Fatal(err) + } + _, err = runtime.repositories.LookupImage("ubuntu:12.04") + if err != nil { + t.Fatal(err) + } + + img2, err := runtime.repositories.LookupImage("ubuntu:12.10") + if img2 != nil { + t.Fatalf("Expected nil image but found %v instead", img2.Id) + } +} \ No newline at end of file