diff --git a/builder/dockerfile/copy.go b/builder/dockerfile/copy.go index 7919c972fd..6370871f18 100644 --- a/builder/dockerfile/copy.go +++ b/builder/dockerfile/copy.go @@ -406,7 +406,7 @@ func downloadSource(output io.Writer, stdout io.Writer, srcURL string) (remote b tmpFileName = unnamedFilename } tmpFileName = filepath.Join(tmpDir, tmpFileName) - tmpFile, err := os.OpenFile(tmpFileName, os.O_RDWR|os.O_CREATE|os.O_EXCL, 0600) + tmpFile, err := os.OpenFile(tmpFileName, os.O_RDWR|os.O_CREATE|os.O_EXCL, 0o600) if err != nil { return } @@ -510,11 +510,11 @@ func copyFile(archiver *archive.Archiver, source, dest string, identity *idtools // modified for use on Windows to handle volume GUID paths. These paths // are of the form \\?\Volume{}\. An example would be: // \\?\Volume{dae8d3ac-b9a1-11e9-88eb-e8554b2ba1db}\bin\busybox.exe - if err := system.MkdirAll(filepath.Dir(dest), 0755); err != nil { + if err := system.MkdirAll(filepath.Dir(dest), 0o755); err != nil { return err } } else { - if err := idtools.MkdirAllAndChownNew(filepath.Dir(dest), 0755, *identity); err != nil { + if err := idtools.MkdirAllAndChownNew(filepath.Dir(dest), 0o755, *identity); err != nil { return errors.Wrapf(err, "failed to create new directory") } } diff --git a/builder/dockerfile/copy_test.go b/builder/dockerfile/copy_test.go index 5fce0bd4eb..91dda111f4 100644 --- a/builder/dockerfile/copy_test.go +++ b/builder/dockerfile/copy_test.go @@ -15,7 +15,7 @@ func TestIsExistingDirectory(t *testing.T) { tmpdir := fs.NewDir(t, "dir-exists-test") defer tmpdir.Remove() - var testcases = []struct { + testcases := []struct { doc string path string expected bool @@ -47,7 +47,7 @@ func TestIsExistingDirectory(t *testing.T) { } func TestGetFilenameForDownload(t *testing.T) { - var testcases = []struct { + testcases := []struct { path string disposition string expected string diff --git a/builder/dockerfile/dispatchers_test.go b/builder/dockerfile/dispatchers_test.go index 65a8279415..01626f3d02 100644 --- a/builder/dockerfile/dispatchers_test.go +++ b/builder/dockerfile/dispatchers_test.go @@ -430,7 +430,8 @@ func TestPrependEnvOnCmd(t *testing.T) { cmd := []string{"foo", "bar"} cmdWithEnv := prependEnvOnCmd(buildArgs, args, cmd) expected := strslice.StrSlice([]string{ - "|3", "NO_PROXY=YA", "args=not", "sorted=nope", "foo", "bar"}) + "|3", "NO_PROXY=YA", "args=not", "sorted=nope", "foo", "bar", + }) assert.Check(t, is.DeepEqual(expected, cmdWithEnv)) } diff --git a/builder/dockerfile/dispatchers_windows.go b/builder/dockerfile/dispatchers_windows.go index 88fa896f67..34cf93de16 100644 --- a/builder/dockerfile/dispatchers_windows.go +++ b/builder/dockerfile/dispatchers_windows.go @@ -108,7 +108,6 @@ func normalizeWorkdirWindows(current string, requested string) (string, error) { // // The commands when this function is called are RUN, ENTRYPOINT and CMD. func resolveCmdLine(cmd instructions.ShellDependantCmdLine, runConfig *container.Config, os, command, original string) ([]string, bool) { - // Make sure we return an empty array if there is no cmd.CmdLine if len(cmd.CmdLine) == 0 { return []string{}, runConfig.ArgsEscaped diff --git a/builder/dockerfile/evaluator_test.go b/builder/dockerfile/evaluator_test.go index 5c40fed558..bf31bd3bc5 100644 --- a/builder/dockerfile/evaluator_test.go +++ b/builder/dockerfile/evaluator_test.go @@ -104,11 +104,10 @@ func TestDispatch(t *testing.T) { defer cleanup() for filename, content := range tc.files { - createTestTempFile(t, contextDir, filename, content, 0777) + createTestTempFile(t, contextDir, filename, content, 0o777) } tarStream, err := archive.Tar(contextDir, archive.Uncompressed) - if err != nil { t.Fatalf("Error when creating tar stream: %s", err) } @@ -120,7 +119,6 @@ func TestDispatch(t *testing.T) { }() buildContext, err := remotecontext.FromArchive(tarStream) - if err != nil { t.Fatalf("Error when creating tar context: %s", err) } diff --git a/builder/dockerfile/internals_linux_test.go b/builder/dockerfile/internals_linux_test.go index 6f56d43afc..ae7e43283e 100644 --- a/builder/dockerfile/internals_linux_test.go +++ b/builder/dockerfile/internals_linux_test.go @@ -41,12 +41,12 @@ othergrp:x:6666: contextDir, cleanup := createTestTempDir(t, "", "builder-chown-parse-test") defer cleanup() - if err := os.Mkdir(filepath.Join(contextDir, "etc"), 0755); err != nil { + if err := os.Mkdir(filepath.Join(contextDir, "etc"), 0o755); err != nil { t.Fatalf("error creating test directory: %v", err) } for filename, content := range testFiles { - createTestTempFile(t, filepath.Join(contextDir, "etc"), filename, content, 0644) + createTestTempFile(t, filepath.Join(contextDir, "etc"), filename, content, 0o644) } // positive tests diff --git a/builder/dockerfile/internals_test.go b/builder/dockerfile/internals_test.go index f56c44b751..b46b112b4d 100644 --- a/builder/dockerfile/internals_test.go +++ b/builder/dockerfile/internals_test.go @@ -26,7 +26,7 @@ func TestEmptyDockerfile(t *testing.T) { contextDir, cleanup := createTestTempDir(t, "", "builder-dockerfile-test") defer cleanup() - createTestTempFile(t, contextDir, builder.DefaultDockerfileName, "", 0777) + createTestTempFile(t, contextDir, builder.DefaultDockerfileName, "", 0o777) readAndCheckDockerfile(t, "emptyDockerfile", contextDir, "", "the Dockerfile (Dockerfile) cannot be empty") } @@ -96,7 +96,7 @@ func TestCopyRunConfig(t *testing.T) { defaultEnv := []string{"foo=1"} defaultCmd := []string{"old"} - var testcases = []struct { + testcases := []struct { doc string modifiers []runConfigModifier expected *container.Config diff --git a/builder/dockerfile/internals_windows.go b/builder/dockerfile/internals_windows.go index 53c302c714..b21c7e8a8c 100644 --- a/builder/dockerfile/internals_windows.go +++ b/builder/dockerfile/internals_windows.go @@ -45,7 +45,6 @@ func getAccountIdentity(ctx context.Context, builder *Builder, accountName strin // Check if the account name is one unique to containers. if strings.EqualFold(accountName, "ContainerAdministrator") { return idtools.Identity{SID: idtools.ContainerAdministratorSidString}, nil - } else if strings.EqualFold(accountName, "ContainerUser") { return idtools.Identity{SID: idtools.ContainerUserSidString}, nil } @@ -56,7 +55,6 @@ func getAccountIdentity(ctx context.Context, builder *Builder, accountName strin } func lookupNTAccount(ctx context.Context, builder *Builder, accountName string, state *dispatchState) (idtools.Identity, error) { - source, _ := filepath.Split(os.Args[0]) target := "C:\\Docker" @@ -72,14 +70,15 @@ func lookupNTAccount(ctx context.Context, builder *Builder, accountName string, runConfig.Cmd = []string{targetExecutable, "getaccountsid", accountName} - hostConfig := &container.HostConfig{Mounts: []mount.Mount{ - { - Type: mount.TypeBind, - Source: source, - Target: target, - ReadOnly: true, + hostConfig := &container.HostConfig{ + Mounts: []mount.Mount{ + { + Type: mount.TypeBind, + Source: source, + Target: target, + ReadOnly: true, + }, }, - }, } container, err := builder.containerManager.Create(ctx, runConfig, hostConfig) diff --git a/builder/dockerfile/mockbackend_test.go b/builder/dockerfile/mockbackend_test.go index a9e43e9bd1..3e3c28b878 100644 --- a/builder/dockerfile/mockbackend_test.go +++ b/builder/dockerfile/mockbackend_test.go @@ -136,8 +136,7 @@ func (l *mockLayer) DiffID() layer.DiffID { return "abcdef" } -type mockRWLayer struct { -} +type mockRWLayer struct{} func (l *mockRWLayer) Release() error { return nil diff --git a/builder/dockerfile/utils_test.go b/builder/dockerfile/utils_test.go index 98bdda2a7e..38f93dab22 100644 --- a/builder/dockerfile/utils_test.go +++ b/builder/dockerfile/utils_test.go @@ -11,7 +11,6 @@ import ( // When an error occurs, it terminates the test. func createTestTempDir(t *testing.T, dir, prefix string) (string, func()) { path, err := os.MkdirTemp(dir, prefix) - if err != nil { t.Fatalf("Error when creating directory %s with prefix %s: %s", dir, prefix, err) } @@ -30,7 +29,6 @@ func createTestTempDir(t *testing.T, dir, prefix string) (string, func()) { func createTestTempFile(t *testing.T, dir, filename, contents string, perm os.FileMode) string { filePath := filepath.Join(dir, filename) err := os.WriteFile(filePath, []byte(contents), perm) - if err != nil { t.Fatalf("Error when creating %s file: %s", filename, err) }