Merge pull request #909 from masarakki/update-docker-image

always update docker image
This commit is contained in:
Brad Rydzewski 2015-03-08 22:01:22 -07:00
commit ea3ea059e0
2 changed files with 25 additions and 2 deletions

View file

@ -234,8 +234,8 @@ func (b *Builder) setup() error {
log.Info("creating build image") log.Info("creating build image")
// check for build container (ie bradrydzewski/go:1.2) // check for build container (ie bradrydzewski/go:1.2)
// and download if it doesn't already exist // 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 { 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 // download the image if it doesn't exist
if err := b.dockerClient.Images.Pull(b.Build.Image); err != nil { 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) return fmt.Errorf("Error: Unable to pull image %s. %s", b.Build.Image, err)

View file

@ -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 // TestSetupErrorBuild will test our ability to handle a failure
// when creating a Docker image with the injected build script, // when creating a Docker image with the injected build script,
// ssh keys, etc. // ssh keys, etc.