Skip to content
Snippets Groups Projects
Unverified Commit b7181fe3 authored by Tomasz Maczukin's avatar Tomasz Maczukin
Browse files

Add handling of non-existing images for Docker >= 17.07

parent 9d9d3402
Branches
Tags
No related merge requests found
...@@ -141,8 +141,9 @@ func (s *executor) pullDockerImage(imageName string, ac *types.AuthConfig) (*typ ...@@ -141,8 +141,9 @@ func (s *executor) pullDockerImage(imageName string, ac *types.AuthConfig) (*typ
options.RegistryAuth, _ = docker_helpers.EncodeAuthConfig(ac) options.RegistryAuth, _ = docker_helpers.EncodeAuthConfig(ac)
} }
errorRegexp := regexp.MustCompile("(repository does not exist|not found)")
if err := s.client.ImagePullBlocking(s.Context, ref, options); err != nil { if err := s.client.ImagePullBlocking(s.Context, ref, options); err != nil {
if strings.Contains(err.Error(), "not found") { if errorRegexp.MatchString(err.Error()) {
return nil, &common.BuildError{Inner: err} return nil, &common.BuildError{Inner: err}
} }
return nil, err return nil, err
......
...@@ -11,6 +11,7 @@ import ( ...@@ -11,6 +11,7 @@ import (
"testing" "testing"
"time" "time"
"github.com/hashicorp/go-version"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
...@@ -104,6 +105,23 @@ func TestDockerCommandWithAllowedImagesRun(t *testing.T) { ...@@ -104,6 +105,23 @@ func TestDockerCommandWithAllowedImagesRun(t *testing.T) {
assert.NoError(t, err) assert.NoError(t, err)
} }
func isDockerOlderThan17_07(t *testing.T) bool {
cmd := exec.Command("docker", "version")
output, err := cmd.Output()
require.NoError(t, err, "docker version should return output")
r := regexp.MustCompile(`(?ms)Server:\s*\n\s+Version:\s+([^\n]+)$`)
v := r.FindStringSubmatch(string(output))[1]
localVersion, err := version.NewVersion(v)
require.NoError(t, err)
checkedVersion, err := version.NewVersion("17.07.0-ce")
require.NoError(t, err)
return localVersion.LessThan(checkedVersion)
}
func TestDockerCommandMissingImage(t *testing.T) { func TestDockerCommandMissingImage(t *testing.T) {
if helpers.SkipIntegrationTests(t, "docker", "info") { if helpers.SkipIntegrationTests(t, "docker", "info") {
return return
...@@ -123,7 +141,13 @@ func TestDockerCommandMissingImage(t *testing.T) { ...@@ -123,7 +141,13 @@ func TestDockerCommandMissingImage(t *testing.T) {
err := build.Run(&common.Config{}, &common.Trace{Writer: os.Stdout}) err := build.Run(&common.Config{}, &common.Trace{Writer: os.Stdout})
require.Error(t, err) require.Error(t, err)
assert.IsType(t, &common.BuildError{}, err) assert.IsType(t, &common.BuildError{}, err)
assert.Contains(t, err.Error(), "not found")
contains := "repository does not exist"
if isDockerOlderThan17_07(t) {
contains = "not found"
}
assert.Contains(t, err.Error(), contains)
} }
func TestDockerCommandMissingTag(t *testing.T) { func TestDockerCommandMissingTag(t *testing.T) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment