diff --git a/internal/pipe/docker/docker.go b/internal/pipe/docker/docker.go index 29462641e..4fca657c3 100644 --- a/internal/pipe/docker/docker.go +++ b/internal/pipe/docker/docker.go @@ -199,7 +199,7 @@ func process(ctx *context.Context, docker config.Docker, artifacts []*artifact.A log.Info("building docker image") if err := imagers[docker.Use].Build(ctx, tmp, images, buildFlags); err != nil { - if strings.Contains(err.Error(), "file not found") || strings.Contains(err.Error(), "not found: not found") { + if isFileNotFoundError(err.Error()) { var files []string _ = filepath.Walk(tmp, func(path string, info fs.FileInfo, err error) error { if info.IsDir() { @@ -238,6 +238,14 @@ Previous error: return nil } +func isFileNotFoundError(out string) bool { + if strings.Contains(out, `executable file not found in $PATH`) { + return false + } + return strings.Contains(out, "file not found") || + strings.Contains(out, "not found: not found") +} + func processImageTemplates(ctx *context.Context, docker config.Docker) ([]string, error) { // nolint:prealloc var images []string diff --git a/internal/pipe/docker/docker_test.go b/internal/pipe/docker/docker_test.go index 1d692b9a4..39426214b 100644 --- a/internal/pipe/docker/docker_test.go +++ b/internal/pipe/docker/docker_test.go @@ -1428,3 +1428,14 @@ func TestDependencies(t *testing.T) { require.Equal(t, []string{"docker", "docker"}, Pipe{}.Dependencies(ctx)) require.Equal(t, []string{"docker", "docker"}, ManifestPipe{}.Dependencies(ctx)) } + +func TestIsFileNotFoundError(t *testing.T) { + t.Run("executable not in path", func(t *testing.T) { + require.False(t, isFileNotFoundError(`error getting credentials - err: exec: "docker-credential-desktop": executable file not found in $PATH, out:`)) + }) + + t.Run("file not found", func(t *testing.T) { + require.True(t, isFileNotFoundError(`./foo: file not found`)) + require.True(t, isFileNotFoundError(`./foo: not found: not found`)) + }) +}