mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-08-15 16:25:54 +08:00
Compare commits
7 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
c513d34049 | ||
![]() |
d455c07331 | ||
![]() |
5ac3b4c4b6 | ||
![]() |
b1440b07f2 | ||
![]() |
a3286a0ab1 | ||
![]() |
b79345c63e | ||
![]() |
23eb3c3ccd |
@@ -465,8 +465,19 @@ func toSolveOpt(ctx context.Context, node builder.Node, multiDriver bool, opt Op
|
||||
so.FrontendAttrs[k] = v
|
||||
}
|
||||
}
|
||||
|
||||
if _, ok := opt.Attests["attest:provenance"]; !ok && supportsAttestations {
|
||||
so.FrontendAttrs["attest:provenance"] = "mode=min,inline-only=true"
|
||||
const noAttestEnv = "BUILDX_NO_DEFAULT_ATTESTATIONS"
|
||||
var noProv bool
|
||||
if v, ok := os.LookupEnv(noAttestEnv); ok {
|
||||
noProv, err = strconv.ParseBool(v)
|
||||
if err != nil {
|
||||
return nil, nil, errors.Wrap(err, "invalid "+noAttestEnv)
|
||||
}
|
||||
}
|
||||
if !noProv {
|
||||
so.FrontendAttrs["attest:provenance"] = "mode=min,inline-only=true"
|
||||
}
|
||||
}
|
||||
|
||||
switch len(opt.Exports) {
|
||||
|
@@ -67,7 +67,13 @@ func getGitAttributes(ctx context.Context, contextPath string, dockerfilePath st
|
||||
if sha, err := gitc.FullCommit(); err != nil && !gitutil.IsUnknownRevision(err) {
|
||||
return res, errors.Wrapf(err, "buildx: failed to get git commit")
|
||||
} else if sha != "" {
|
||||
if gitc.IsDirty() {
|
||||
checkDirty := false
|
||||
if v, ok := os.LookupEnv("BUILDX_GIT_CHECK_DIRTY"); ok {
|
||||
if v, err := strconv.ParseBool(v); err == nil {
|
||||
checkDirty = v
|
||||
}
|
||||
}
|
||||
if checkDirty && gitc.IsDirty() {
|
||||
sha += "-dirty"
|
||||
}
|
||||
if setGitLabels {
|
||||
|
@@ -131,6 +131,7 @@ func TestGetGitAttributes(t *testing.T) {
|
||||
|
||||
func TestGetGitAttributesDirty(t *testing.T) {
|
||||
setupTest(t)
|
||||
t.Setenv("BUILDX_GIT_CHECK_DIRTY", "true")
|
||||
|
||||
// make a change to test dirty flag
|
||||
df := []byte("FROM alpine:edge\n")
|
||||
|
@@ -414,8 +414,13 @@ The `registry` exporter is a shortcut for `type=image,push=true`.
|
||||
|
||||
Set the target platform for the build. All `FROM` commands inside the Dockerfile
|
||||
without their own `--platform` flag will pull base images for this platform and
|
||||
this value will also be the platform of the resulting image. The default value
|
||||
will be the current platform of the buildkit daemon.
|
||||
this value will also be the platform of the resulting image.
|
||||
|
||||
The default value is the platform of the BuildKit daemon where the build runs.
|
||||
The value takes the form of `os/arch` or `os/arch/variant`. For example,
|
||||
`linux/amd64` or `linux/arm/v7`. Additionally, the `--platform` flag also supports
|
||||
a special `local` value, which tells BuildKit to use the platform of the BuildKit
|
||||
client that invokes the build.
|
||||
|
||||
When using `docker-container` driver with `buildx`, this flag can accept multiple
|
||||
values as an input separated by a comma. With multiple values the result will be
|
||||
|
@@ -3,6 +3,7 @@ package gitutil
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"net/url"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
@@ -70,11 +71,11 @@ func (c *Git) RootDir() (string, error) {
|
||||
func (c *Git) RemoteURL() (string, error) {
|
||||
// Try to get the remote URL from the origin remote first
|
||||
if ru, err := c.clean(c.run("remote", "get-url", "origin")); err == nil && ru != "" {
|
||||
return ru, nil
|
||||
return stripCredentials(ru), nil
|
||||
}
|
||||
// If that fails, try to get the remote URL from the upstream remote
|
||||
if ru, err := c.clean(c.run("remote", "get-url", "upstream")); err == nil && ru != "" {
|
||||
return ru, nil
|
||||
return stripCredentials(ru), nil
|
||||
}
|
||||
return "", errors.New("no remote URL found for either origin or upstream")
|
||||
}
|
||||
@@ -147,3 +148,16 @@ func IsUnknownRevision(err error) bool {
|
||||
errMsg := strings.ToLower(err.Error())
|
||||
return strings.Contains(errMsg, "unknown revision or path not in the working tree") || strings.Contains(errMsg, "bad revision")
|
||||
}
|
||||
|
||||
// stripCredentials takes a URL and strips username and password from it.
|
||||
// e.g. "https://user:password@host.tld/path.git" will be changed to
|
||||
// "https://host.tld/path.git".
|
||||
// TODO: remove this function once fix from BuildKit is vendored here
|
||||
func stripCredentials(s string) string {
|
||||
ru, err := url.Parse(s)
|
||||
if err != nil {
|
||||
return s // string is not a URL, just return it
|
||||
}
|
||||
ru.User = nil
|
||||
return ru.String()
|
||||
}
|
||||
|
@@ -189,3 +189,45 @@ func TestGitRemoteURL(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestStripCredentials(t *testing.T) {
|
||||
cases := []struct {
|
||||
name string
|
||||
url string
|
||||
want string
|
||||
}{
|
||||
{
|
||||
name: "non-blank Password",
|
||||
url: "https://user:password@host.tld/this:that",
|
||||
want: "https://host.tld/this:that",
|
||||
},
|
||||
{
|
||||
name: "blank Password",
|
||||
url: "https://user@host.tld/this:that",
|
||||
want: "https://host.tld/this:that",
|
||||
},
|
||||
{
|
||||
name: "blank Username",
|
||||
url: "https://:password@host.tld/this:that",
|
||||
want: "https://host.tld/this:that",
|
||||
},
|
||||
{
|
||||
name: "blank Username, blank Password",
|
||||
url: "https://host.tld/this:that",
|
||||
want: "https://host.tld/this:that",
|
||||
},
|
||||
{
|
||||
name: "invalid URL",
|
||||
url: "1https://foo.com",
|
||||
want: "1https://foo.com",
|
||||
},
|
||||
}
|
||||
for _, tt := range cases {
|
||||
tt := tt
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if g, w := stripCredentials(tt.url), tt.want; g != w {
|
||||
t.Fatalf("got: %q\nwant: %q", g, w)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user