mirror of https://github.com/docker/buildx.git
lint: modernize fix
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
This commit is contained in:
parent
09b824b9dc
commit
1383aa30c1
19
bake/bake.go
19
bake/bake.go
|
@ -483,8 +483,7 @@ func (c Config) expandTargets(pattern string) ([]string, error) {
|
|||
func (c Config) loadLinks(name string, t *Target, m map[string]*Target, o map[string]map[string]Override, visited []string, ent *EntitlementConf) error {
|
||||
visited = append(visited, name)
|
||||
for _, v := range t.Contexts {
|
||||
if strings.HasPrefix(v, "target:") {
|
||||
target := strings.TrimPrefix(v, "target:")
|
||||
if target, ok := strings.CutPrefix(v, "target:"); ok {
|
||||
if target == name {
|
||||
return errors.Errorf("target %s cannot link to itself", target)
|
||||
}
|
||||
|
@ -1275,8 +1274,8 @@ func collectLocalPaths(t build.Inputs) []string {
|
|||
if v, ok := isLocalPath(t.DockerfilePath); ok {
|
||||
out = append(out, v)
|
||||
}
|
||||
} else if strings.HasPrefix(t.ContextPath, "cwd://") {
|
||||
out = append(out, strings.TrimPrefix(t.ContextPath, "cwd://"))
|
||||
} else if v, ok := strings.CutPrefix(t.ContextPath, "cwd://"); ok {
|
||||
out = append(out, v)
|
||||
}
|
||||
for _, v := range t.NamedContexts {
|
||||
if v.State != nil {
|
||||
|
@ -1328,11 +1327,11 @@ func toBuildOpt(t *Target, inp *Input) (*build.Options, error) {
|
|||
bi.DockerfileInline = *t.DockerfileInline
|
||||
}
|
||||
updateContext(&bi, inp)
|
||||
if strings.HasPrefix(bi.DockerfilePath, "cwd://") {
|
||||
if v, ok := strings.CutPrefix(bi.DockerfilePath, "cwd://"); ok {
|
||||
// If Dockerfile is local for a remote invocation, we first check if
|
||||
// it's not outside the working directory and then resolve it to an
|
||||
// absolute path.
|
||||
bi.DockerfilePath = path.Clean(strings.TrimPrefix(bi.DockerfilePath, "cwd://"))
|
||||
bi.DockerfilePath = path.Clean(v)
|
||||
var err error
|
||||
bi.DockerfilePath, err = filepath.Abs(bi.DockerfilePath)
|
||||
if err != nil {
|
||||
|
@ -1357,15 +1356,15 @@ func toBuildOpt(t *Target, inp *Input) (*build.Options, error) {
|
|||
return nil, errors.Errorf("reading a dockerfile for a remote build invocation is currently not supported")
|
||||
}
|
||||
}
|
||||
if strings.HasPrefix(bi.ContextPath, "cwd://") {
|
||||
bi.ContextPath = path.Clean(strings.TrimPrefix(bi.ContextPath, "cwd://"))
|
||||
if v, ok := strings.CutPrefix(bi.ContextPath, "cwd://"); ok {
|
||||
bi.ContextPath = path.Clean(v)
|
||||
}
|
||||
if !build.IsRemoteURL(bi.ContextPath) && bi.ContextState == nil && !filepath.IsAbs(bi.DockerfilePath) {
|
||||
bi.DockerfilePath = filepath.Join(bi.ContextPath, bi.DockerfilePath)
|
||||
}
|
||||
for k, v := range bi.NamedContexts {
|
||||
if strings.HasPrefix(v.Path, "cwd://") {
|
||||
bi.NamedContexts[k] = build.NamedContext{Path: path.Clean(strings.TrimPrefix(v.Path, "cwd://"))}
|
||||
if v, ok := strings.CutPrefix(v.Path, "cwd://"); ok {
|
||||
bi.NamedContexts[k] = build.NamedContext{Path: path.Clean(v)}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1381,7 +1381,6 @@ target "d" {
|
|||
},
|
||||
}
|
||||
for _, tt := range cases {
|
||||
tt := tt
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
m, g, err := ReadTargets(ctx, []File{f}, []string{"d"}, tt.overrides, nil, &EntitlementConf{})
|
||||
require.NoError(t, err)
|
||||
|
@ -1454,7 +1453,6 @@ group "default" {
|
|||
},
|
||||
}
|
||||
for _, tt := range cases {
|
||||
tt := tt
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
m, g, err := ReadTargets(ctx, []File{f}, []string{"default"}, tt.overrides, nil, &EntitlementConf{})
|
||||
require.NoError(t, err)
|
||||
|
@ -1509,7 +1507,6 @@ func TestTargetName(t *testing.T) {
|
|||
},
|
||||
}
|
||||
for _, tt := range cases {
|
||||
tt := tt
|
||||
t.Run(tt.target, func(t *testing.T) {
|
||||
_, _, err := ReadTargets(ctx, []File{{
|
||||
Name: "docker-bake.hcl",
|
||||
|
@ -1600,7 +1597,6 @@ target "f" {
|
|||
},
|
||||
}
|
||||
for _, tt := range cases {
|
||||
tt := tt
|
||||
t.Run(strings.Join(tt.names, "+"), func(t *testing.T) {
|
||||
m, g, err := ReadTargets(ctx, []File{f}, tt.names, nil, nil, &EntitlementConf{})
|
||||
require.NoError(t, err)
|
||||
|
|
|
@ -62,7 +62,6 @@ func ParseCompose(cfgs []composetypes.ConfigFile, envs map[string]string) (*Conf
|
|||
g := &Group{Name: "default"}
|
||||
|
||||
for _, s := range cfg.Services {
|
||||
s := s
|
||||
if s.Build == nil {
|
||||
continue
|
||||
}
|
||||
|
@ -144,7 +143,6 @@ func ParseCompose(cfgs []composetypes.ConfigFile, envs map[string]string) (*Conf
|
|||
// compose does not support nil values for labels
|
||||
labels := map[string]*string{}
|
||||
for k, v := range s.Build.Labels {
|
||||
v := v
|
||||
labels[k] = &v
|
||||
}
|
||||
|
||||
|
|
|
@ -518,7 +518,6 @@ func TestServiceName(t *testing.T) {
|
|||
},
|
||||
}
|
||||
for _, tt := range cases {
|
||||
tt := tt
|
||||
t.Run(tt.svc, func(t *testing.T) {
|
||||
_, err := ParseCompose([]composetypes.ConfigFile{{Content: []byte(`
|
||||
services:
|
||||
|
@ -589,7 +588,6 @@ services:
|
|||
},
|
||||
}
|
||||
for _, tt := range cases {
|
||||
tt := tt
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
_, err := ParseCompose([]composetypes.ConfigFile{{Content: tt.dt}}, nil)
|
||||
if tt.wantErr {
|
||||
|
@ -665,7 +663,6 @@ target "default" {
|
|||
},
|
||||
}
|
||||
for _, tt := range cases {
|
||||
tt := tt
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
isCompose, err := validateComposeFile(tt.dt, tt.fn)
|
||||
assert.Equal(t, tt.isCompose, isCompose)
|
||||
|
|
|
@ -781,7 +781,6 @@ func Parse(b hcl.Body, opt Opt, val any) (*ParseMeta, hcl.Diagnostics) {
|
|||
}
|
||||
|
||||
for _, a := range content.Attributes {
|
||||
a := a
|
||||
return nil, hcl.Diagnostics{
|
||||
&hcl.Diagnostic{
|
||||
Severity: hcl.DiagError,
|
||||
|
@ -834,7 +833,6 @@ func Parse(b hcl.Body, opt Opt, val any) (*ParseMeta, hcl.Diagnostics) {
|
|||
context = subject
|
||||
} else {
|
||||
for _, block := range blocks.Blocks {
|
||||
block := block
|
||||
if block.Type == "function" && len(block.Labels) == 1 && block.Labels[0] == k {
|
||||
subject = block.LabelRanges[0].Ptr()
|
||||
context = block.DefRange.Ptr()
|
||||
|
@ -903,7 +901,6 @@ func Parse(b hcl.Body, opt Opt, val any) (*ParseMeta, hcl.Diagnostics) {
|
|||
|
||||
diags = hcl.Diagnostics{}
|
||||
for _, b := range content.Blocks {
|
||||
b := b
|
||||
v := reflect.ValueOf(val)
|
||||
|
||||
err := p.resolveBlock(b, nil)
|
||||
|
|
|
@ -383,7 +383,6 @@ func BuildWithResultHandler(ctx context.Context, nodes []builder.Node, opts map[
|
|||
wg.Add(1)
|
||||
sharedSessionsWG[node.Name] = wg
|
||||
for _, s := range sessions {
|
||||
s := s
|
||||
eg.Go(func() error {
|
||||
return s.Run(baseCtx, c.Dialer())
|
||||
})
|
||||
|
|
|
@ -109,7 +109,6 @@ func TestGetGitAttributes(t *testing.T) {
|
|||
},
|
||||
}
|
||||
for _, tt := range cases {
|
||||
tt := tt
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
setupTest(t)
|
||||
if tt.envGitLabels != "" {
|
||||
|
|
|
@ -503,8 +503,7 @@ func loadInputs(ctx context.Context, d *driver.DriverHandle, inp *Inputs, pw pro
|
|||
}
|
||||
|
||||
// handle OCI layout
|
||||
if strings.HasPrefix(v.Path, "oci-layout://") {
|
||||
localPath := strings.TrimPrefix(v.Path, "oci-layout://")
|
||||
if localPath, ok := strings.CutPrefix(v.Path, "oci-layout://"); ok {
|
||||
localPath, dig, hasDigest := strings.Cut(localPath, "@")
|
||||
localPath, tag, hasTag := strings.Cut(localPath, ":")
|
||||
if !hasTag {
|
||||
|
|
|
@ -92,7 +92,6 @@ func fetchProvenance(ctx context.Context, c *client.Client, ref string, mode con
|
|||
})
|
||||
} else if ev.Record.Results != nil {
|
||||
for platform, res := range ev.Record.Results {
|
||||
platform := platform
|
||||
desc := lookupProvenance(res)
|
||||
if desc == nil {
|
||||
continue
|
||||
|
|
|
@ -130,7 +130,6 @@ func TestToBuildkitExtraHosts(t *testing.T) {
|
|||
}
|
||||
|
||||
for _, tc := range tests {
|
||||
tc := tc
|
||||
if tc.expectedOut == "" {
|
||||
tc.expectedOut = strings.Join(tc.input, ",")
|
||||
}
|
||||
|
|
|
@ -190,7 +190,6 @@ foo = "bar"
|
|||
},
|
||||
}
|
||||
for _, tt := range testCases {
|
||||
tt := tt
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
flags, err := parseBuildkitdFlags(tt.flags, tt.driver, tt.driverOpts, tt.buildkitdConfigFile)
|
||||
if tt.wantErr {
|
||||
|
|
|
@ -559,8 +559,7 @@ func readBakeFiles(ctx context.Context, nodes []builder.Node, url string, names
|
|||
var rnames []string // remote
|
||||
var anames []string // both
|
||||
for _, v := range names {
|
||||
if strings.HasPrefix(v, "cwd://") {
|
||||
tname := strings.TrimPrefix(v, "cwd://")
|
||||
if tname, ok := strings.CutPrefix(v, "cwd://"); ok {
|
||||
lnames = append(lnames, tname)
|
||||
anames = append(anames, tname)
|
||||
} else {
|
||||
|
|
|
@ -869,9 +869,9 @@ func printTable(w io.Writer, kvs []keyValueOutput, title string) {
|
|||
func readKeyValues(attrs map[string]string, prefix string) []keyValueOutput {
|
||||
var out []keyValueOutput
|
||||
for k, v := range attrs {
|
||||
if strings.HasPrefix(k, prefix) {
|
||||
if name, ok := strings.CutPrefix(k, prefix); ok {
|
||||
out = append(out, keyValueOutput{
|
||||
Name: strings.TrimPrefix(k, prefix),
|
||||
Name: name,
|
||||
Value: v,
|
||||
})
|
||||
}
|
||||
|
|
|
@ -43,7 +43,6 @@ func runRm(ctx context.Context, dockerCli command.Cli, opts rmOptions) error {
|
|||
|
||||
eg, ctx := errgroup.WithContext(ctx)
|
||||
for i, node := range nodes {
|
||||
node := node
|
||||
eg.Go(func() error {
|
||||
if node.Driver == nil {
|
||||
return nil
|
||||
|
|
|
@ -139,7 +139,6 @@ func queryRecords(ctx context.Context, ref string, nodes []builder.Node, opts *q
|
|||
|
||||
eg, ctx := errgroup.WithContext(ctx)
|
||||
for _, node := range nodes {
|
||||
node := node
|
||||
eg.Go(func() error {
|
||||
if node.Driver == nil {
|
||||
return nil
|
||||
|
|
|
@ -184,7 +184,6 @@ func runCreate(ctx context.Context, dockerCli command.Cli, in createOptions, arg
|
|||
pw := progress.WithPrefix(printer, "internal", true)
|
||||
|
||||
for _, t := range tags {
|
||||
t := t
|
||||
eg.Go(func() error {
|
||||
return progress.Wrap(fmt.Sprintf("pushing %s", t.String()), pw.Write, func(sub progress.SubLogger) error {
|
||||
eg2, _ := errgroup.WithContext(ctx)
|
||||
|
|
|
@ -164,7 +164,6 @@ func TestTruncPlatforms(t *testing.T) {
|
|||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
tt := tt
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
tpfs := truncPlatforms(tt.platforms, tt.max)
|
||||
assert.Equal(t, tt.expectedList, tpfs.List())
|
||||
|
|
|
@ -70,9 +70,8 @@ func ResolveOptionPaths(options *Options) (_ *Options, err error) {
|
|||
for k, v := range options.NamedContexts {
|
||||
if isRemoteURL(v) || strings.HasPrefix(v, "docker-image://") {
|
||||
// url prefix, this is a remote path
|
||||
} else if strings.HasPrefix(v, "oci-layout://") {
|
||||
} else if p, ok := strings.CutPrefix(v, "oci-layout://"); ok {
|
||||
// oci layout prefix, this is a local path
|
||||
p := strings.TrimPrefix(v, "oci-layout://")
|
||||
p, err = filepath.Abs(p)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
@ -240,7 +240,6 @@ func TestResolvePaths(t *testing.T) {
|
|||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
tt := tt
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got, err := ResolveOptionPaths(tt.options)
|
||||
require.NoError(t, err)
|
||||
|
|
|
@ -9,7 +9,6 @@ import (
|
|||
|
||||
func TestConstraint(t *testing.T) {
|
||||
for _, tt := range mobyBuildkitVersions {
|
||||
tt := tt
|
||||
t.Run(tt.MobyVersionConstraint, func(t *testing.T) {
|
||||
_, err := semver.NewConstraint(tt.MobyVersionConstraint)
|
||||
require.NoError(t, err)
|
||||
|
@ -121,7 +120,6 @@ func TestResolveBuildKitVersion(t *testing.T) {
|
|||
},
|
||||
}
|
||||
for _, tt := range cases {
|
||||
tt := tt
|
||||
t.Run(tt.mobyVersion, func(t *testing.T) {
|
||||
bkVersion, err := resolveBuildKitVersion(tt.mobyVersion)
|
||||
if tt.err {
|
||||
|
|
|
@ -36,7 +36,6 @@ func testLs(t *testing.T, sb integration.Sandbox) {
|
|||
|
||||
sbDriver, _, _ := driverName(sb.Name())
|
||||
for _, tt := range tests {
|
||||
tt := tt
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
out, err := lsCmd(sb, withArgs(tt.args...))
|
||||
require.NoError(t, err, out)
|
||||
|
|
|
@ -49,7 +49,6 @@ func TestIsSubPath(t *testing.T) {
|
|||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
tt := tt
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
ok, err := isSubPath(tt.basePath, tt.subPath)
|
||||
require.NoError(t, err)
|
||||
|
|
|
@ -17,7 +17,6 @@ func fromReader(l progress.SubLogger, rc io.ReadCloser) error {
|
|||
|
||||
defer func() {
|
||||
for _, st := range started {
|
||||
st := st
|
||||
if st.Completed == nil {
|
||||
now := time.Now()
|
||||
st.Completed = &now
|
||||
|
|
|
@ -35,7 +35,6 @@ func TestStripCredentials(t *testing.T) {
|
|||
},
|
||||
}
|
||||
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)
|
||||
|
|
|
@ -200,7 +200,6 @@ func TestGitRemoteURL(t *testing.T) {
|
|||
},
|
||||
}
|
||||
for _, tt := range cases {
|
||||
tt := tt
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
gittestutil.Mktmp(t)
|
||||
c, err := gitutil.New()
|
||||
|
|
|
@ -225,7 +225,6 @@ func (l *loader) fetch(ctx context.Context, fetcher remotes.Fetcher, desc ocispe
|
|||
|
||||
eg, ctx := errgroup.WithContext(ctx)
|
||||
for _, d := range idx.Manifests {
|
||||
d := d
|
||||
eg.Go(func() error {
|
||||
return l.fetch(ctx, fetcher, d, r)
|
||||
})
|
||||
|
|
|
@ -145,7 +145,6 @@ func TestAsAttributeKeyValue(t *testing.T) {
|
|||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
tt := tt
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
kv := keyValue{
|
||||
Key: "key",
|
||||
|
|
Loading…
Reference in New Issue