diff --git a/shared/build/build.go b/shared/build/build.go index 1ebb4998..850a2d57 100644 --- a/shared/build/build.go +++ b/shared/build/build.go @@ -234,8 +234,8 @@ func (b *Builder) setup() error { log.Info("creating build image") // check for build container (ie bradrydzewski/go:1.2) - // and download if it doesn't already exist - if _, err := b.dockerClient.Images.Inspect(b.Build.Image); err == docker.ErrNotFound { + // and download if it doesn't already exist or it's :latest tag + if _, err := b.dockerClient.Images.Inspect(b.Build.Image); err == docker.ErrNotFound || strings.HasSuffix(b.Build.Image, ":latest") { // download the image if it doesn't exist if err := b.dockerClient.Images.Pull(b.Build.Image); err != nil { return fmt.Errorf("Error: Unable to pull image %s. %s", b.Build.Image, err) diff --git a/shared/build/build_test.go b/shared/build/build_test.go index 079a7b63..636fff44 100644 --- a/shared/build/build_test.go +++ b/shared/build/build_test.go @@ -224,6 +224,29 @@ func TestSetupErrorImagePull(t *testing.T) { } } +// TestSetupErrorUpdate will test our ability to handle a +// failure when the build image cannot be updated +func TestSetupErrorUpdate(t *testing.T) { + setup() + defer teardown() + + mux.HandleFunc("/v1.9/images/create", func(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(http.StatusBadRequest) + }) + + b := Builder{} + b.Repo = &repo.Repo{} + b.Repo.Path = "git://github.com/drone/drone.git" + b.Build = &script.Build{} + b.Build.Image = "bradrydzewski/go:latest" + b.dockerClient = client + + var got, want = b.setup(), fmt.Errorf("Error: Unable to pull image bradrydzewski/go:latest. %s", docker.ErrBadRequest) + if got == nil || got.Error() != want.Error() { + t.Errorf("Expected error %s, got %s", want, got) + } +} + // TestSetupErrorBuild will test our ability to handle a failure // when creating a Docker image with the injected build script, // ssh keys, etc.