From 4789d2219c43f28f98f2ead0d44bb3be40d87e32 Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Mon, 30 Jan 2023 14:33:16 +0100 Subject: [PATCH 1/2] build: silently fail if git remote not found Signed-off-by: CrazyMax --- build/git.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/build/git.go b/build/git.go index 93325269..60b52936 100644 --- a/build/git.go +++ b/build/git.go @@ -78,9 +78,7 @@ func getGitAttributes(ctx context.Context, contextPath string, dockerfilePath st } } - if rurl, err := gitc.RemoteURL(); err != nil { - return res, errors.Wrapf(err, "failed to get git remote url") - } else if rurl != "" { + if rurl, err := gitc.RemoteURL(); err == nil && rurl != "" { if setGitLabels { res["label:"+specs.AnnotationSource] = rurl } From 6db696748b7141d44c6bbacb91e42b2cd6513431 Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Mon, 30 Jan 2023 14:54:07 +0100 Subject: [PATCH 2/2] build: better message output for git provenance Signed-off-by: CrazyMax --- build/git.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/build/git.go b/build/git.go index 60b52936..47f3fc1c 100644 --- a/build/git.go +++ b/build/git.go @@ -52,20 +52,20 @@ func getGitAttributes(ctx context.Context, contextPath string, dockerfilePath st gitc, err := gitutil.New(gitutil.WithContext(ctx), gitutil.WithWorkingDir(wd)) if err != nil { if st, err := os.Stat(path.Join(wd, ".git")); err == nil && st.IsDir() { - return res, errors.New("git was not found in the system. Current commit information was not captured by the build") + return res, errors.New("buildx: git was not found in the system. Current commit information was not captured by the build") } return } if !gitc.IsInsideWorkTree() { if st, err := os.Stat(path.Join(wd, ".git")); err == nil && st.IsDir() { - return res, errors.New("failed to read current commit information with git rev-parse --is-inside-work-tree") + return res, errors.New("buildx: failed to read current commit information with git rev-parse --is-inside-work-tree") } return res, nil } if sha, err := gitc.FullCommit(); err != nil { - return res, errors.Wrapf(err, "failed to get git commit") + return res, errors.Wrapf(err, "buildx: failed to get git commit") } else if sha != "" { if gitc.IsDirty() { sha += "-dirty" @@ -89,7 +89,7 @@ func getGitAttributes(ctx context.Context, contextPath string, dockerfilePath st if setGitLabels { if root, err := gitc.RootDir(); err != nil { - return res, errors.Wrapf(err, "failed to get git root dir") + return res, errors.Wrapf(err, "buildx: failed to get git root dir") } else if root != "" { if dockerfilePath == "" { dockerfilePath = filepath.Join(wd, "Dockerfile")