mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-03-17 20:47:50 +02:00
feat: add context info to docker build errors (#3920)
its too hard to debug docker build issues... sometimes is just a typo in the binary name, and you might end debugging it for way too long... this prints the full path to the build context (so, locally at least, you can cd into it) and also all the files available there when the error seems to be one of the "file not found" kind. Hopefully this helps fixing things easier :) closes #3912 Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>
This commit is contained in:
parent
8a6de5cc55
commit
d5a413f9f4
@ -2,6 +2,7 @@ package docker
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
@ -198,6 +199,26 @@ 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") {
|
||||
var files []string
|
||||
_ = filepath.Walk(tmp, func(path string, info fs.FileInfo, err error) error {
|
||||
if info.IsDir() {
|
||||
return nil
|
||||
}
|
||||
files = append(files, info.Name())
|
||||
return nil
|
||||
})
|
||||
return fmt.Errorf(`seems like you tried to copy a file that is not available in the build context.
|
||||
|
||||
Here's more information about the build context:
|
||||
|
||||
dir: %q
|
||||
files in that dir:
|
||||
%s
|
||||
|
||||
Previous error:
|
||||
%w`, tmp, strings.Join(files, "\n "), err)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -436,6 +436,20 @@ func TestRunPipe(t *testing.T) {
|
||||
pubAssertError: shouldNotErr,
|
||||
manifestAssertError: shouldNotErr,
|
||||
},
|
||||
"wrong binary name": {
|
||||
dockers: []config.Docker{
|
||||
{
|
||||
ImageTemplates: []string{
|
||||
registry + "goreleaser/wrong_bin_name:v1",
|
||||
},
|
||||
Goos: "linux",
|
||||
Goarch: "amd64",
|
||||
Dockerfile: "testdata/Dockerfile.wrongbin",
|
||||
},
|
||||
},
|
||||
assertError: shouldErr("seems like you tried to copy a file that is not available in the build context"),
|
||||
assertImageLabels: noLabels,
|
||||
},
|
||||
"templated-dockerfile-invalid": {
|
||||
dockers: []config.Docker{
|
||||
{
|
||||
|
3
internal/pipe/docker/testdata/Dockerfile.wrongbin
vendored
Normal file
3
internal/pipe/docker/testdata/Dockerfile.wrongbin
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
FROM alpine
|
||||
# a typo:
|
||||
ADD mybyn /
|
Loading…
x
Reference in New Issue
Block a user