diff --git a/.go-tools b/.go-tools index b07a8f13..e35a3b33 100644 --- a/.go-tools +++ b/.go-tools @@ -1,2 +1,3 @@ github.com/oligot/go-mod-upgrade@v0.6.2 gotest.tools/gotestsum@v1.7.0 +github.com/segmentio/golines@v0.7.0 diff --git a/.golangci.yml b/.golangci.yml index 948aa5a3..6ba33546 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -17,7 +17,7 @@ linters: - gocritic - gocyclo - godot - - gofmt + - gofumpt - gosec - gosimple - govet @@ -54,6 +54,16 @@ linters-settings: check-error-free-encoding: true gci: local-prefixes: github.com/mesosphere/mindthegap + gocritic: + enabled-tags: + - diagnostic + - experimental + - opinionated + - performance + - style + gofumpt: + lang-version: "1.17" + extra-rules: true lll: line-length: 120 diff --git a/archive/archive_test.go b/archive/archive_test.go index 7e9b627a..b403e0b1 100644 --- a/archive/archive_test.go +++ b/archive/archive_test.go @@ -59,8 +59,11 @@ func TestArchiveDirectorySuccess(t *testing.T) { } var buf bytes.Buffer _, err = io.CopyN(&buf, tr, 1024) - require.Condition(t, - func() (success bool) { return err == nil || err == io.EOF }, "error reading content from tarball") + require.Condition( + t, + func() (success bool) { return err == nil || err == io.EOF }, + "error reading content from tarball", + ) archivedContents[hdr.Name] = buf.String() } @@ -70,24 +73,36 @@ func TestArchiveDirectorySuccess(t *testing.T) { func TestArchiveDirectoryDestDirNotWritable(t *testing.T) { tmpDir := t.TempDir() notWriteable := filepath.Join(tmpDir, "notwritable") - require.NoError(t, os.Mkdir(notWriteable, 0500), "error creating not writable directory") + require.NoError(t, os.Mkdir(notWriteable, 0o500), "error creating not writable directory") outputFile := filepath.Join(notWriteable, "out.tar.gz") - require.Error(t, archive.ArchiveDirectory("testdata", outputFile), "expected error archiving directory") + require.Error( + t, + archive.ArchiveDirectory("testdata", outputFile), + "expected error archiving directory", + ) } func TestArchiveDirectoryDestFileExists(t *testing.T) { tmpDir := t.TempDir() outputFile := filepath.Join(tmpDir, "out.tar.gz") - f, err := os.OpenFile(outputFile, os.O_CREATE, 0400) + f, err := os.OpenFile(outputFile, os.O_CREATE, 0o400) require.NoError(t, err, "error creating dummy file") require.NoError(t, f.Close(), "error closing dummy file") - require.NoError(t, archive.ArchiveDirectory("testdata", outputFile), "unexpected error archiving directory") + require.NoError( + t, + archive.ArchiveDirectory("testdata", outputFile), + "unexpected error archiving directory", + ) } func TestArchiveDirectoryUnreadableSource(t *testing.T) { tmpDir := t.TempDir() unreadable := filepath.Join(tmpDir, "unreadable") - require.NoError(t, os.Mkdir(unreadable, 0100), "error creating unreadable directory") + require.NoError(t, os.Mkdir(unreadable, 0o100), "error creating unreadable directory") outputFile := filepath.Join(tmpDir, "out.tar.gz") - require.Error(t, archive.ArchiveDirectory(unreadable, outputFile), "expected error archiving directory") + require.Error( + t, + archive.ArchiveDirectory(unreadable, outputFile), + "expected error archiving directory", + ) } diff --git a/cmd/create/imagebundle/image_bundle.go b/cmd/create/imagebundle/image_bundle.go index 72f30c19..dfeeafa4 100644 --- a/cmd/create/imagebundle/image_bundle.go +++ b/cmd/create/imagebundle/image_bundle.go @@ -38,10 +38,17 @@ func NewCommand(out output.Output) *cobra.Command { switch { case err == nil: out.EndOperation(false) - return fmt.Errorf("%s already exists: specify --overwrite to overwrite existing file", outputFile) + return fmt.Errorf( + "%s already exists: specify --overwrite to overwrite existing file", + outputFile, + ) case !errors.Is(err, os.ErrNotExist): out.EndOperation(false) - return fmt.Errorf("failed to check if output file %s already exists: %w", outputFile, err) + return fmt.Errorf( + "failed to check if output file %s already exists: %w", + outputFile, + err, + ) default: out.EndOperation(true) } @@ -60,7 +67,10 @@ func NewCommand(out output.Output) *cobra.Command { outputFileAbs, err := filepath.Abs(outputFile) if err != nil { out.EndOperation(false) - return fmt.Errorf("failed to determine where to create temporary directory: %w", err) + return fmt.Errorf( + "failed to determine where to create temporary directory: %w", + err, + ) } cleaner := cleanup.NewCleaner() @@ -100,7 +110,10 @@ func NewCommand(out output.Output) *cobra.Command { if registryConfig.Credentials != nil && registryConfig.Credentials.Username != "" { skopeoOpts = append( skopeoOpts, - skopeo.SrcCredentials(registryConfig.Credentials.Username, registryConfig.Credentials.Password), + skopeo.SrcCredentials( + registryConfig.Credentials.Username, + registryConfig.Credentials.Password, + ), ) } else { skopeoStdout, skopeoStderr, err := skopeoRunner.AttemptToLoginToRegistry(context.TODO(), registryName) @@ -121,7 +134,8 @@ func NewCommand(out output.Output) *cobra.Command { ) srcImageManifestList, skopeoStdout, skopeoStderr, err := skopeoRunner.InspectManifest( - context.TODO(), fmt.Sprintf("docker://%s", srcImageName), + context.TODO(), + fmt.Sprintf("docker://%s", srcImageName), ) if err != nil { out.EndOperation(false) @@ -131,9 +145,15 @@ func NewCommand(out output.Output) *cobra.Command { } out.V(4).Infof("---skopeo stdout---:\n%s", skopeoStdout) out.V(4).Infof("---skopeo stderr---:\n%s", skopeoStderr) - destImageManifestList := manifestlist.ManifestList{Versioned: srcImageManifestList.Versioned} - platformManifests := make(map[string]manifestlist.ManifestDescriptor, len(srcImageManifestList.Manifests)) - for _, m := range srcImageManifestList.Manifests { + destImageManifestList := manifestlist.ManifestList{ + Versioned: srcImageManifestList.Versioned, + } + platformManifests := make( + map[string]manifestlist.ManifestDescriptor, + len(srcImageManifestList.Manifests), + ) + for i := range srcImageManifestList.Manifests { + m := srcImageManifestList.Manifests[i] srcManifestPlatform := m.Platform.OS + "/" + m.Platform.Architecture if m.Platform.Variant != "" { srcManifestPlatform += "/" + m.Platform.Variant @@ -150,16 +170,34 @@ func NewCommand(out output.Output) *cobra.Command { platformManifest, ok = platformManifests[p.String()] if !ok { out.EndOperation(false) - return fmt.Errorf("could not find platform %s for image %s", p, srcImageName) + return fmt.Errorf( + "could not find platform %s for image %s", + p, + srcImageName, + ) } } - skopeoStdout, skopeoStderr, err := skopeoRunner.Copy(context.TODO(), - fmt.Sprintf("docker://%s/%s@%s", registryName, imageName, platformManifest.Digest), - fmt.Sprintf("docker://%s/%s@%s", reg.Address(), imageName, platformManifest.Digest), + skopeoStdout, skopeoStderr, err := skopeoRunner.Copy( + context.TODO(), + fmt.Sprintf( + "docker://%s/%s@%s", + registryName, + imageName, + platformManifest.Digest, + ), + fmt.Sprintf( + "docker://%s/%s@%s", + reg.Address(), + imageName, + platformManifest.Digest, + ), append( skopeoOpts, - skopeo.DisableDestTLSVerify(), skopeo.OS(p.os), skopeo.Arch(p.arch), skopeo.Variant(p.variant), + skopeo.DisableDestTLSVerify(), + skopeo.OS(p.os), + skopeo.Arch(p.arch), + skopeo.Variant(p.variant), )..., ) if err != nil { @@ -171,7 +209,10 @@ func NewCommand(out output.Output) *cobra.Command { out.V(4).Infof("---skopeo stdout---:\n%s", skopeoStdout) out.V(4).Infof("---skopeo stderr---:\n%s", skopeoStderr) - destImageManifestList.Manifests = append(destImageManifestList.Manifests, platformManifest) + destImageManifestList.Manifests = append( + destImageManifestList.Manifests, + platformManifest, + ) } skopeoStdout, skopeoStderr, err = skopeoRunner.CopyManifest(context.TODO(), destImageManifestList, @@ -212,10 +253,13 @@ func NewCommand(out output.Output) *cobra.Command { cmd.Flags().StringVar(&configFile, "images-file", "", "File containing list of images to create bundle from, either as YAML configuration or a simple list of images") _ = cmd.MarkFlagRequired("images-file") - cmd.Flags().Var(newPlatformSlicesValue([]platform{{os: "linux", arch: "amd64"}}, &platforms), "platform", - "platforms to download images (required format: /[/])") - cmd.Flags().StringVar(&outputFile, "output-file", "images.tar.gz", "Output file to write image bundle to") - cmd.Flags().BoolVar(&overwrite, "overwrite", false, "Overwrite image bundle file if it already exists") + cmd.Flags(). + Var(newPlatformSlicesValue([]platform{{os: "linux", arch: "amd64"}}, &platforms), "platform", + "platforms to download images (required format: /[/])") + cmd.Flags(). + StringVar(&outputFile, "output-file", "images.tar.gz", "Output file to write image bundle to") + cmd.Flags(). + BoolVar(&overwrite, "overwrite", false, "Overwrite image bundle file if it already exists") return cmd } diff --git a/cmd/create/imagebundle/platforms_flag.go b/cmd/create/imagebundle/platforms_flag.go index 038f9c81..29aa1288 100644 --- a/cmd/create/imagebundle/platforms_flag.go +++ b/cmd/create/imagebundle/platforms_flag.go @@ -90,7 +90,10 @@ func writePlatformsAsCSV(vals []platform) (string, error) { func parsePlatformString(s string) (platform, error) { splitVal := strings.Split(s, "/") if len(splitVal) < 2 || len(splitVal) > 3 { - return platform{}, fmt.Errorf("invalid platform specification: %s (required format: /[/]", s) + return platform{}, fmt.Errorf( + "invalid platform specification: %s (required format: /[/]", + s, + ) } p := platform{os: splitVal[0], arch: splitVal[1]} if len(splitVal) == 3 { diff --git a/cmd/create/imagebundle/platforms_flag_test.go b/cmd/create/imagebundle/platforms_flag_test.go index de0e7ac2..e23ce404 100644 --- a/cmd/create/imagebundle/platforms_flag_test.go +++ b/cmd/create/imagebundle/platforms_flag_test.go @@ -231,7 +231,11 @@ func TestSSWithComma(t *testing.T) { values := f.Lookup("ps").Value.(*platformSliceValue) if len(expected) != len(*values.value) { - t.Fatalf("expected number of values to be %d but got: %d", len(expected), len(*values.value)) + t.Fatalf( + "expected number of values to be %d but got: %d", + len(expected), + len(*values.value), + ) } for i, v := range *values.value { if expected[i] != v { @@ -256,7 +260,12 @@ func TestPSAsSliceValue(t *testing.T) { } }) expectedPlatform := platform{os: "windows", arch: "arm", variant: "v7"} - require.ElementsMatch(t, []platform{expectedPlatform}, ps, "Expected ps to be overwritten with 'windows/arm/v7'") + require.ElementsMatch( + t, + []platform{expectedPlatform}, + ps, + "Expected ps to be overwritten with 'windows/arm/v7'", + ) } func TestPSGetSlice(t *testing.T) { @@ -286,7 +295,11 @@ func TestPSAppend(t *testing.T) { arg2 := fmt.Sprintf(argfmt, in[1]) require.NoError(t, f.Parse([]string{arg1, arg2}), "error parsing flags") - require.NoError(t, f.Lookup("ps").Value.(pflag.SliceValue).Append("windows/i386"), "error appending to platforms") + require.NoError( + t, + f.Lookup("ps").Value.(pflag.SliceValue).Append("windows/i386"), + "error appending to platforms", + ) require.ElementsMatch(t, append(in, "windows/i386"), f.Lookup("ps").Value.(pflag.SliceValue).GetSlice(), diff --git a/cmd/importcmd/imagebundle/image_bundle.go b/cmd/importcmd/imagebundle/image_bundle.go index cadf7654..053ab204 100644 --- a/cmd/importcmd/imagebundle/image_bundle.go +++ b/cmd/importcmd/imagebundle/image_bundle.go @@ -58,7 +58,9 @@ func NewCommand(out output.Output) *cobra.Command { out.EndOperation(true) out.StartOperation("Starting temporary Docker registry") - reg, err := registry.NewRegistry(registry.Config{StorageDirectory: tempDir, ReadOnly: true}) + reg, err := registry.NewRegistry( + registry.Config{StorageDirectory: tempDir, ReadOnly: true}, + ) if err != nil { out.EndOperation(false) return fmt.Errorf("failed to create local Docker registry: %w", err) @@ -95,7 +97,8 @@ func NewCommand(out output.Output) *cobra.Command { }, } - cmd.Flags().StringVar(&imageBundleFile, "image-bundle", "", "Tarball containing list of images to push") + cmd.Flags(). + StringVar(&imageBundleFile, "image-bundle", "", "Tarball containing list of images to push") _ = cmd.MarkFlagRequired("image-bundle") cmd.Flags().StringVar(&containerdNamespace, "containerd-namespace", "k8s.io", "Containerd namespace to import images into") diff --git a/cmd/push/imagebundle/image_bundle.go b/cmd/push/imagebundle/image_bundle.go index 364863b7..c5d7d091 100644 --- a/cmd/push/imagebundle/image_bundle.go +++ b/cmd/push/imagebundle/image_bundle.go @@ -59,7 +59,9 @@ func NewCommand(out output.Output) *cobra.Command { out.EndOperation(true) out.StartOperation("Starting temporary Docker registry") - reg, err := registry.NewRegistry(registry.Config{StorageDirectory: tempDir, ReadOnly: true}) + reg, err := registry.NewRegistry( + registry.Config{StorageDirectory: tempDir, ReadOnly: true}, + ) if err != nil { out.EndOperation(false) return fmt.Errorf("failed to create local Docker registry: %w", err) @@ -75,7 +77,10 @@ func NewCommand(out output.Output) *cobra.Command { skopeoRunner, skopeoCleanup := skopeo.NewRunner() cleaner.AddCleanupFn(func() { _ = skopeoCleanup() }) - skopeoStdout, skopeoStderr, err := skopeoRunner.AttemptToLoginToRegistry(context.TODO(), destRegistry) + skopeoStdout, skopeoStderr, err := skopeoRunner.AttemptToLoginToRegistry( + context.TODO(), + destRegistry, + ) if err != nil { out.Infof("---skopeo stdout---:\n%s", skopeoStdout) out.Infof("---skopeo stderr---:\n%s", skopeoStderr) @@ -119,7 +124,8 @@ func NewCommand(out output.Output) *cobra.Command { }, } - cmd.Flags().StringVar(&imageBundleFile, "image-bundle", "", "Tarball containing list of images to push") + cmd.Flags(). + StringVar(&imageBundleFile, "image-bundle", "", "Tarball containing list of images to push") _ = cmd.MarkFlagRequired("image-bundle") cmd.Flags().StringVar(&destRegistry, "to-registry", "", "Registry to push images to") _ = cmd.MarkFlagRequired("to-registry") diff --git a/cmd/serve/imagebundle/image_bundle.go b/cmd/serve/imagebundle/image_bundle.go index bc66402f..3dcba083 100644 --- a/cmd/serve/imagebundle/image_bundle.go +++ b/cmd/serve/imagebundle/image_bundle.go @@ -73,10 +73,12 @@ func NewCommand(out output.Output) *cobra.Command { }, } - cmd.Flags().StringVar(&imageBundleFile, "image-bundle", "", "Tarball containing list of images to push") + cmd.Flags(). + StringVar(&imageBundleFile, "image-bundle", "", "Tarball containing list of images to push") _ = cmd.MarkFlagRequired("image-bundle") cmd.Flags().StringVar(&listenAddress, "listen-address", "localhost", "Address to list on") - cmd.Flags().Uint16Var(&listenPort, "listen-port", 0, "Port to listen on (0 means use any free port)") + cmd.Flags(). + Uint16Var(&listenPort, "listen-port", 0, "Port to listen on (0 means use any free port)") cmd.Flags().StringVar(&tlsCertificate, "tls-cert-file", "", "TLS certificate file") cmd.Flags().StringVar(&tlsKey, "tls-private-key-file", "", "TLS private key file") diff --git a/config/config_test.go b/config/config_test.go index d31c14a6..5844ce93 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -124,7 +124,9 @@ func TestParseFile(t *testing.T) { if strings.HasSuffix(tt.name, "in plain text file") { ext = "txt" } - got, err := ParseFile(filepath.Join("testdata", strings.ReplaceAll(tt.name, " ", "_")+"."+ext)) + got, err := ParseFile( + filepath.Join("testdata", strings.ReplaceAll(tt.name, " ", "_")+"."+ext), + ) if (err != nil) != tt.wantErr { t.Errorf("ParseFile() error = %v, wantErr %v", err, tt.wantErr) return diff --git a/containerd/ctr.go b/containerd/ctr.go index 1a59793f..5b2d959a 100644 --- a/containerd/ctr.go +++ b/containerd/ctr.go @@ -14,7 +14,10 @@ type CtrOption func() string func ImportImage(ctx context.Context, src, tag, containerdNamespace string) ([]byte, error) { baseArgs := []string{"-n", containerdNamespace} //nolint:gosec // Args are fine. - cmd := exec.CommandContext(ctx, "ctr", append(baseArgs, []string{"images", "pull", "--plain-http", src}...)...) + cmd := exec.CommandContext( + ctx, + "ctr", + append(baseArgs, []string{"images", "pull", "--plain-http", src}...)...) cmdOutput, err := cmd.CombinedOutput() if err != nil { return cmdOutput, fmt.Errorf("failed to pull image from temporary docker registry: %w", err) @@ -22,7 +25,10 @@ func ImportImage(ctx context.Context, src, tag, containerdNamespace string) ([]b if tag != "" { //nolint:gosec // Args are fine. - cmd = exec.CommandContext(ctx, "ctr", append(baseArgs, []string{"images", "tag", "--force", src, tag}...)...) + cmd = exec.CommandContext( + ctx, + "ctr", + append(baseArgs, []string{"images", "tag", "--force", src, tag}...)...) tagOutput, err := cmd.CombinedOutput() cmdOutput = append(cmdOutput, tagOutput...) if err != nil { diff --git a/make/go.mk b/make/go.mk index bf7877be..0718930a 100644 --- a/make/go.mk +++ b/make/go.mk @@ -86,9 +86,9 @@ endif .PHONY: lint.% lint.%: ## Runs golangci-lint for a specific module -lint.%: install-tool.go.golangci-lint; $(info $(M) running golangci-lint for $* module) +lint.%: install-tool.go.golangci-lint install-tool.go.golines; $(info $(M) linting $* module) + $(if $(filter-out root,$*),cd $* && )golines -w . $(if $(filter-out root,$*),cd $* && )golangci-lint run --fix --config=$(GOLANGCI_CONFIG_FILE) - $(if $(filter-out root,$*),cd $* && )go fmt ./... $(if $(filter-out root,$*),cd $* && )go fix ./... .PHONY: mod-tidy diff --git a/skopeo/skopeo.go b/skopeo/skopeo.go index fb31c982..111dbf34 100644 --- a/skopeo/skopeo.go +++ b/skopeo/skopeo.go @@ -46,9 +46,9 @@ func AllImages() SkopeoOption { } } -func OS(os string) SkopeoOption { +func OS(opsys string) SkopeoOption { return func() string { - return "--override-os=" + os + return "--override-os=" + opsys } } @@ -109,17 +109,21 @@ func (r *Runner) mustUnpack() { panic(err) } r.unpackedSkopeoPath = filepath.Join(tempDir, "skopeo") - //nolint:gosec // Binary must be executable - if err = os.WriteFile(r.unpackedSkopeoPath, skopeoBinary, 0700); err != nil { + //nolint:gosec // Binary must be executable. + if err = os.WriteFile(r.unpackedSkopeoPath, skopeoBinary, 0o700); err != nil { panic(err) } r.unpackedSkopeoPolicyPath = filepath.Join(tempDir, "policy.json") - if err = os.WriteFile(r.unpackedSkopeoPolicyPath, defaultSkopeoPolicy, 0400); err != nil { + if err = os.WriteFile(r.unpackedSkopeoPolicyPath, defaultSkopeoPolicy, 0o400); err != nil { panic(err) } } -func (r *Runner) Copy(ctx context.Context, src, dest string, opts ...SkopeoOption) (stdout, stderr []byte, err error) { +func (r *Runner) Copy( + ctx context.Context, + src, dest string, + opts ...SkopeoOption, +) (stdout, stderr []byte, err error) { copyArgs := []string{ "copy", "--policy", r.unpackedSkopeoPolicyPath, @@ -142,7 +146,10 @@ func (r *Runner) InspectManifest( rawStdout, rawStderr, err := r.run(ctx, inspectArgs, opts...) if err != nil { - return manifestlist.ManifestList{}, rawStdout, rawStderr, fmt.Errorf("failed to read image manifest: %w", err) + return manifestlist.ManifestList{}, rawStdout, rawStderr, fmt.Errorf( + "failed to read image manifest: %w", + err, + ) } var ml manifestlist.ManifestList @@ -156,7 +163,10 @@ func (r *Runner) InspectManifest( dec = json.NewDecoder(bytes.NewReader(rawStdout)) dec.DisallowUnknownFields() if err := dec.Decode(&m); err != nil { - return manifestlist.ManifestList{}, rawStdout, rawStderr, fmt.Errorf("failed to deserialize manifest: %w", err) + return manifestlist.ManifestList{}, rawStdout, rawStderr, fmt.Errorf( + "failed to deserialize manifest: %w", + err, + ) } inspectArgs = []string{ @@ -166,7 +176,10 @@ func (r *Runner) InspectManifest( inspectStdout, inspectStderr, err := r.run(ctx, inspectArgs, opts...) if err != nil { - return manifestlist.ManifestList{}, inspectStdout, inspectStderr, fmt.Errorf("failed to read image manifest: %w", err) + return manifestlist.ManifestList{}, inspectStdout, inspectStderr, fmt.Errorf( + "failed to read image manifest: %w", + err, + ) } var i inspect.Output @@ -213,10 +226,18 @@ func (r *Runner) CopyManifest( // for details _ = json.NewEncoder(mf).Encode(manifest) - return r.Copy(ctx, "dir:"+td, dest, append(opts, func() string { return "--multi-arch=index-only" })...) + return r.Copy( + ctx, + "dir:"+td, + dest, + append(opts, func() string { return "--multi-arch=index-only" })...) } -func (r *Runner) run(ctx context.Context, baseArgs []string, opts ...SkopeoOption) (stdout, stderr []byte, err error) { +func (r *Runner) run( + ctx context.Context, + baseArgs []string, + opts ...SkopeoOption, +) (stdout, stderr []byte, err error) { r.unpacked.Do(r.mustUnpack) skopeoArgs := make([]string, 0, len(baseArgs)+len(opts)) @@ -238,14 +259,25 @@ func (r *Runner) run(ctx context.Context, baseArgs []string, opts ...SkopeoOptio return stdout, stderrBuf.Bytes(), err } -func (r *Runner) AttemptToLoginToRegistry(ctx context.Context, registryName string) (stdout, stderr []byte, err error) { +func (r *Runner) AttemptToLoginToRegistry( + ctx context.Context, + registryName string, +) (stdout, stderr []byte, err error) { var skopeoOpts []SkopeoOption - getLoginStdout, getLoginStderr, err := r.run(ctx, []string{"login", "--get-login", registryName}, skopeoOpts...) + getLoginStdout, getLoginStderr, err := r.run( + ctx, + []string{"login", "--get-login", registryName}, + skopeoOpts...) if err == nil { return getLoginStdout, getLoginStderr, nil } - if err != nil && !strings.Contains(string(getLoginStderr), fmt.Sprintf("not logged into %s", registryName)) { - return getLoginStdout, getLoginStderr, fmt.Errorf("failed to check if already logged in to %s: %w", registryName, err) + if err != nil && + !strings.Contains(string(getLoginStderr), fmt.Sprintf("not logged into %s", registryName)) { + return getLoginStdout, getLoginStderr, fmt.Errorf( + "failed to check if already logged in to %s: %w", + registryName, + err, + ) } stdoutBuf := bytes.NewBuffer(getLoginStdout) @@ -261,11 +293,23 @@ func (r *Runner) AttemptToLoginToRegistry(ctx context.Context, registryName stri for _, reg := range registryNamesToTry { authConfig, err := configFile.GetAuthConfig(reg) if err != nil { - return getLoginStdout, getLoginStderr, fmt.Errorf("failed to get auth config for %s: %w", registryName, err) + return getLoginStdout, getLoginStderr, fmt.Errorf( + "failed to get auth config for %s: %w", + registryName, + err, + ) } if authConfig.Username != "" && authConfig.Password != "" { - loginStdout, loginStderr, err := r.run(ctx, - []string{"login", registryName, "--username", authConfig.Username, "--password", authConfig.Password}, + loginStdout, loginStderr, err := r.run( + ctx, + []string{ + "login", + registryName, + "--username", + authConfig.Username, + "--password", + authConfig.Password, + }, skopeoOpts..., ) _, _ = stdoutBuf.Write(loginStdout) @@ -273,7 +317,11 @@ func (r *Runner) AttemptToLoginToRegistry(ctx context.Context, registryName stri if err == nil { return stdoutBuf.Bytes(), stderrBuf.Bytes(), nil } - return stdoutBuf.Bytes(), stderrBuf.Bytes(), fmt.Errorf("failed to login to %s: %w", registryName, err) + return stdoutBuf.Bytes(), stderrBuf.Bytes(), fmt.Errorf( + "failed to login to %s: %w", + registryName, + err, + ) } }