diff --git a/.golangci.yml b/.golangci.yml index 48ca9cf9..a5d7b286 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -6,12 +6,10 @@ linters: enable-all: false disable-all: true enable: - - deadcode - errcheck - gocyclo - gofmt - goimports - - revive - gosimple - govet - ineffassign @@ -19,17 +17,17 @@ linters: - misspell - nakedret - staticcheck - - structcheck - typecheck - unconvert - unparam - unused - - varcheck linters-settings: gocyclo: min-complexity: 16 lll: line-length: 200 + goimports: + local-prefixes: github.com/docker/compose-cli issues: # golangci hides some golint warnings (the warning about exported things # withtout documentation for example), this will make it show them anyway. diff --git a/aci/backend_test.go b/aci/backend_test.go index 90917165..72eae16c 100644 --- a/aci/backend_test.go +++ b/aci/backend_test.go @@ -23,9 +23,10 @@ import ( "github.com/stretchr/testify/mock" "gotest.tools/v3/assert" + "golang.org/x/oauth2" + "github.com/docker/compose-cli/aci/login" "github.com/docker/compose-cli/api/containers" - "golang.org/x/oauth2" ) func TestGetContainerName(t *testing.T) { diff --git a/aci/compose.go b/aci/compose.go index 828dcb09..bdafe80c 100644 --- a/aci/compose.go +++ b/aci/compose.go @@ -22,11 +22,12 @@ import ( "net/http" "github.com/compose-spec/compose-go/types" - "github.com/docker/compose-cli/utils" "github.com/docker/compose/v2/pkg/api" "github.com/docker/compose/v2/pkg/progress" "github.com/sirupsen/logrus" + "github.com/docker/compose-cli/utils" + "github.com/docker/compose-cli/aci/convert" "github.com/docker/compose-cli/aci/login" "github.com/docker/compose-cli/api/context/store" diff --git a/aci/convert/convert.go b/aci/convert/convert.go index a890dc0e..9ce5f0e5 100644 --- a/aci/convert/convert.go +++ b/aci/convert/convert.go @@ -218,7 +218,7 @@ func (s serviceConfigAciHelper) getResourceRequestsLimits() (*containerinstance. } if hasCPURequest() { - cpuRequest, err = strconv.ParseFloat(s.Deploy.Resources.Reservations.NanoCPUs, 0) + cpuRequest, err = strconv.ParseFloat(s.Deploy.Resources.Reservations.NanoCPUs, 64) if err != nil { return nil, err } @@ -233,7 +233,7 @@ func (s serviceConfigAciHelper) getResourceRequestsLimits() (*containerinstance. } } if s.Deploy.Resources.Limits.NanoCPUs != "" { - cpuLimit, err = strconv.ParseFloat(s.Deploy.Resources.Limits.NanoCPUs, 0) + cpuLimit, err = strconv.ParseFloat(s.Deploy.Resources.Limits.NanoCPUs, 64) if err != nil { return nil, err } diff --git a/aci/convert/registry_credentials.go b/aci/convert/registry_credentials.go index 2ffbfe61..abe5af47 100644 --- a/aci/convert/registry_credentials.go +++ b/aci/convert/registry_credentials.go @@ -19,7 +19,7 @@ package convert import ( "encoding/json" "fmt" - "io/ioutil" + "io" "net/http" "net/url" "os" @@ -165,7 +165,7 @@ func (c cliRegistryHelper) autoLoginAcr(registry string, loginService login.Azur if err != nil { return errors.Wrap(err, "could not query ACR token") } - bits, err := ioutil.ReadAll(res.Body) + bits, err := io.ReadAll(res.Body) if err != nil { return errors.Wrap(err, "could not read response body") } diff --git a/aci/convert/registry_credentials_test.go b/aci/convert/registry_credentials_test.go index 78ca7556..29b4df34 100644 --- a/aci/convert/registry_credentials_test.go +++ b/aci/convert/registry_credentials_test.go @@ -25,10 +25,11 @@ import ( "github.com/Azure/go-autorest/autorest/to" "github.com/compose-spec/compose-go/types" cliconfigtypes "github.com/docker/cli/cli/config/types" - "github.com/docker/compose-cli/aci/login" "github.com/stretchr/testify/mock" "gotest.tools/v3/assert" is "gotest.tools/v3/assert/cmp" + + "github.com/docker/compose-cli/aci/login" ) const getAllCredentials = "getAllRegistryCredentials" diff --git a/aci/convert/secrets.go b/aci/convert/secrets.go index 494a5dbc..bcde4f92 100644 --- a/aci/convert/secrets.go +++ b/aci/convert/secrets.go @@ -19,7 +19,7 @@ package convert import ( "encoding/base64" "fmt" - "io/ioutil" + "os" "path" "strings" @@ -43,7 +43,7 @@ func (p projectAciHelper) getAciSecretVolumes() ([]containerinstance.Volume, err for _, svc := range p.Services { squashedTargetVolumes := make(map[string]containerinstance.Volume) for _, scr := range svc.Secrets { - data, err := ioutil.ReadFile(p.Secrets[scr.Source].File) + data, err := os.ReadFile(p.Secrets[scr.Source].File) if err != nil { return secretVolumes, err } diff --git a/aci/convert/secrets_test.go b/aci/convert/secrets_test.go index 75f4e9b8..3dbd6c21 100644 --- a/aci/convert/secrets_test.go +++ b/aci/convert/secrets_test.go @@ -18,7 +18,6 @@ package convert import ( "fmt" - "io/ioutil" "os" "path" "testing" @@ -31,7 +30,7 @@ func TestConvertSecrets(t *testing.T) { serviceName := "testservice" secretName := "testsecret" absBasePath := "/home/user" - tmpFile, err := ioutil.TempFile(os.TempDir(), "TestConvertProjectSecrets-") + tmpFile, err := os.CreateTemp(os.TempDir(), "TestConvertProjectSecrets-") assert.NilError(t, err) _, err = tmpFile.Write([]byte("test content")) assert.NilError(t, err) diff --git a/aci/e2e/aci-demo/web/dispatcher.go b/aci/e2e/aci-demo/web/dispatcher.go index c69ae7c2..54a8a647 100644 --- a/aci/e2e/aci-demo/web/dispatcher.go +++ b/aci/e2e/aci-demo/web/dispatcher.go @@ -18,7 +18,7 @@ package main import ( "fmt" - "io/ioutil" + "io" "log" "math/rand" "net" @@ -75,7 +75,7 @@ func copy(url, ip string, w http.ResponseWriter) error { w.Header().Set("source", ip) - buf, err := ioutil.ReadAll(resp.Body) + buf, err := io.ReadAll(resp.Body) if err != nil { return err } diff --git a/aci/e2e/e2e-aci_test.go b/aci/e2e/e2e-aci_test.go index 75d6de5a..45bfd0db 100644 --- a/aci/e2e/e2e-aci_test.go +++ b/aci/e2e/e2e-aci_test.go @@ -22,7 +22,6 @@ import ( "encoding/json" "errors" "fmt" - "io/ioutil" "math/rand" "net/http" "net/url" @@ -533,10 +532,10 @@ func TestContainerRunAttached(t *testing.T) { } func overwriteFileStorageAccount(t *testing.T, absComposefileName string, storageAccount string) { - data, err := ioutil.ReadFile(absComposefileName) + data, err := os.ReadFile(absComposefileName) assert.NilError(t, err) override := strings.Replace(string(data), "dockertestvolumeaccount", storageAccount, 1) - err = ioutil.WriteFile(absComposefileName, []byte(override), 0644) + err = os.WriteFile(absComposefileName, []byte(override), 0644) assert.NilError(t, err) } diff --git a/aci/etchosts/hosts_test.go b/aci/etchosts/hosts_test.go index d3da7edc..39a59a1d 100644 --- a/aci/etchosts/hosts_test.go +++ b/aci/etchosts/hosts_test.go @@ -17,7 +17,6 @@ package etchosts import ( - "io/ioutil" "os" "path/filepath" "testing" @@ -35,7 +34,7 @@ func TestSetDomain(t *testing.T) { err := SetHostNames(f, "foo", "bar", "zot") assert.NilError(t, err) - got, err := ioutil.ReadFile(f) + got, err := os.ReadFile(f) assert.NilError(t, err) golden.Assert(t, string(got), "etchosts.golden") } diff --git a/aci/login/client_test.go b/aci/login/client_test.go index 4c77eec1..27c3d040 100644 --- a/aci/login/client_test.go +++ b/aci/login/client_test.go @@ -17,7 +17,6 @@ package login import ( - "io/ioutil" "os" "path/filepath" "testing" @@ -26,7 +25,7 @@ import ( ) func TestClearErrorMessageIfNotAlreadyLoggedIn(t *testing.T) { - dir, err := ioutil.TempDir("", "test_store") + dir, err := os.MkdirTemp("", "test_store") assert.NilError(t, err) t.Cleanup(func() { _ = os.RemoveAll(dir) diff --git a/aci/login/cloud_environment.go b/aci/login/cloud_environment.go index d02bef6f..2be5f0fd 100644 --- a/aci/login/cloud_environment.go +++ b/aci/login/cloud_environment.go @@ -19,7 +19,7 @@ package login import ( "encoding/json" "fmt" - "io/ioutil" + "io" "net/http" "net/url" "os" @@ -110,7 +110,7 @@ func (ces *cloudEnvironmentService) Get(name string) (CloudEnvironment, error) { return CloudEnvironment{}, errors.Errorf("Cloud metadata retrieval from '%s' failed: server response was '%s'", ces.cloudMetadataURL, res.Status) } - bytes, err := ioutil.ReadAll(res.Body) + bytes, err := io.ReadAll(res.Body) if err != nil { return CloudEnvironment{}, fmt.Errorf("Cloud metadata retrieval from '%s' failed: %w", ces.cloudMetadataURL, err) } diff --git a/aci/login/helper.go b/aci/login/helper.go index dd44b11e..bf93bff4 100644 --- a/aci/login/helper.go +++ b/aci/login/helper.go @@ -20,10 +20,11 @@ import ( "context" "encoding/json" "fmt" - "io/ioutil" + "io" "math/rand" "net/http" "net/url" + "os" "os/exec" "runtime" "strings" @@ -74,7 +75,7 @@ func (helper azureAPIHelper) queryAPIWithHeader(ctx context.Context, authorizati if err != nil { return nil, 0, err } - bits, err := ioutil.ReadAll(res.Body) + bits, err := io.ReadAll(res.Body) if err != nil { return nil, 0, err } @@ -89,7 +90,7 @@ func (helper azureAPIHelper) queryToken(ce CloudEnvironment, data url.Values, te if res.StatusCode != 200 { return azureToken{}, errors.Errorf("error while renewing access token, status : %s", res.Status) } - bits, err := ioutil.ReadAll(res.Body) + bits, err := io.ReadAll(res.Body) if err != nil { return azureToken{}, err } @@ -117,7 +118,7 @@ func openbrowser(address string) error { } func isWsl() bool { - b, err := ioutil.ReadFile("/proc/version") + b, err := os.ReadFile("/proc/version") if err != nil { return false } diff --git a/aci/login/login_test.go b/aci/login/login_test.go index 3388945a..fcb3ae00 100644 --- a/aci/login/login_test.go +++ b/aci/login/login_test.go @@ -19,7 +19,6 @@ package login import ( "context" "errors" - "io/ioutil" "net/http" "net/http/httptest" "net/url" @@ -39,7 +38,7 @@ import ( ) func testLoginService(t *testing.T, apiHelperMock *MockAzureHelper, cloudEnvironmentSvc CloudEnvironmentService) (*azureLoginService, error) { - dir, err := ioutil.TempDir("", "test_store") + dir, err := os.MkdirTemp("", "test_store") if err != nil { return nil, err } diff --git a/aci/login/token_store.go b/aci/login/token_store.go index 13100688..56f7be09 100644 --- a/aci/login/token_store.go +++ b/aci/login/token_store.go @@ -19,7 +19,6 @@ package login import ( "encoding/json" "errors" - "io/ioutil" "os" "path/filepath" @@ -71,11 +70,11 @@ func (store tokenStore) writeLoginInfo(info TokenInfo) error { if err != nil { return err } - return ioutil.WriteFile(store.filePath, bytes, 0644) + return os.WriteFile(store.filePath, bytes, 0644) } func (store tokenStore) readToken() (TokenInfo, error) { - bytes, err := ioutil.ReadFile(store.filePath) + bytes, err := os.ReadFile(store.filePath) if err != nil { return TokenInfo{}, err } diff --git a/aci/login/token_store_test.go b/aci/login/token_store_test.go index 4eef8d76..1b5033e8 100644 --- a/aci/login/token_store_test.go +++ b/aci/login/token_store_test.go @@ -17,7 +17,6 @@ package login import ( - "io/ioutil" "os" "path/filepath" "testing" @@ -26,7 +25,7 @@ import ( ) func TestCreateStoreFromExistingFolder(t *testing.T) { - existingDir, err := ioutil.TempDir("", "test_store") + existingDir, err := os.MkdirTemp("", "test_store") assert.NilError(t, err) storePath := filepath.Join(existingDir, tokenStoreFilename) @@ -36,7 +35,7 @@ func TestCreateStoreFromExistingFolder(t *testing.T) { } func TestCreateStoreFromNonExistingFolder(t *testing.T) { - existingDir, err := ioutil.TempDir("", "test_store") + existingDir, err := os.MkdirTemp("", "test_store") assert.NilError(t, err) storePath := filepath.Join(existingDir, "new", tokenStoreFilename) @@ -50,7 +49,7 @@ func TestCreateStoreFromNonExistingFolder(t *testing.T) { } func TestErrorIfParentFolderIsAFile(t *testing.T) { - existingDir, err := ioutil.TempFile("", "test_store") + existingDir, err := os.CreateTemp("", "test_store") assert.NilError(t, err) storePath := filepath.Join(existingDir.Name(), tokenStoreFilename) diff --git a/api/config/config.go b/api/config/config.go index 1bef3ae7..80265a90 100644 --- a/api/config/config.go +++ b/api/config/config.go @@ -18,7 +18,6 @@ package config import ( "encoding/json" - "io/ioutil" "os" "path/filepath" @@ -78,12 +77,12 @@ func writeFile(path string, content map[string]interface{}) error { if err != nil { return errors.Wrap(err, "unable to marshal config") } - err = ioutil.WriteFile(path, d, 0644) + err = os.WriteFile(path, d, 0644) return errors.Wrap(err, "unable to write config file") } func loadFile(path string, dest interface{}) error { - data, err := ioutil.ReadFile(path) + data, err := os.ReadFile(path) if err != nil { if os.IsNotExist(err) { // Not an error if there is no config, we're just using defaults diff --git a/api/config/config_test.go b/api/config/config_test.go index 3986c6f0..11486dfa 100644 --- a/api/config/config_test.go +++ b/api/config/config_test.go @@ -17,7 +17,6 @@ package config import ( - "io/ioutil" "os" "path/filepath" "testing" @@ -31,7 +30,7 @@ var sampleConfig = []byte(`{ }`) func testConfigDir(t *testing.T) string { - d, _ := ioutil.TempDir("", "") + d, _ := os.MkdirTemp("", "") t.Cleanup(func() { _ = os.RemoveAll(d) }) @@ -39,7 +38,7 @@ func testConfigDir(t *testing.T) string { } func writeSampleConfig(t *testing.T, d string) { - err := ioutil.WriteFile(filepath.Join(d, ConfigFileName), sampleConfig, 0644) + err := os.WriteFile(filepath.Join(d, ConfigFileName), sampleConfig, 0644) assert.NilError(t, err) } @@ -77,7 +76,7 @@ func TestWriteDefaultContextToEmptyConfig(t *testing.T) { d := testConfigDir(t) err := WriteCurrentContext(d, "default") assert.NilError(t, err) - c, err := ioutil.ReadFile(filepath.Join(d, ConfigFileName)) + c, err := os.ReadFile(filepath.Join(d, ConfigFileName)) assert.NilError(t, err) assert.Equal(t, string(c), "{}") } diff --git a/api/context/store/store.go b/api/context/store/store.go index e2291c09..0032f279 100644 --- a/api/context/store/store.go +++ b/api/context/store/store.go @@ -19,7 +19,6 @@ package store import ( "encoding/json" "fmt" - "io/ioutil" "os" "path/filepath" "reflect" @@ -160,7 +159,7 @@ func (s *store) GetEndpoint(name string, data interface{}) error { } func read(meta string) (*DockerContext, error) { - bytes, err := ioutil.ReadFile(meta) + bytes, err := os.ReadFile(meta) if err != nil { return nil, err } @@ -246,12 +245,12 @@ func (s *store) Create(name string, contextType string, description string, data return err } - return ioutil.WriteFile(filepath.Join(metaDir, metaFile), bytes, 0644) + return os.WriteFile(filepath.Join(metaDir, metaFile), bytes, 0644) } func (s *store) List() ([]*DockerContext, error) { root := filepath.Join(s.root, contextsDir, metadataDir) - c, err := ioutil.ReadDir(root) + c, err := os.ReadDir(root) if err != nil { return nil, err } diff --git a/api/context/store/store_test.go b/api/context/store/store_test.go index 7ea385f6..5bd4fa9c 100644 --- a/api/context/store/store_test.go +++ b/api/context/store/store_test.go @@ -18,7 +18,6 @@ package store import ( _ "crypto/sha256" - "io/ioutil" "os" "testing" @@ -29,7 +28,7 @@ import ( ) func testStore(t *testing.T) Store { - d, err := ioutil.TempDir("", "store") + d, err := os.MkdirTemp("", "store") assert.NilError(t, err) t.Cleanup(func() { diff --git a/cli/cmd/context/context.go b/cli/cmd/context/context.go index 53feffaa..12d86a7d 100644 --- a/cli/cmd/context/context.go +++ b/cli/cmd/context/context.go @@ -17,8 +17,9 @@ package context import ( - "github.com/docker/compose-cli/cli/mobycli" "github.com/spf13/cobra" + + "github.com/docker/compose-cli/cli/mobycli" ) // Command manages contexts diff --git a/cli/cmd/context/rm.go b/cli/cmd/context/rm.go index d6fcfe44..d8362d89 100644 --- a/cli/cmd/context/rm.go +++ b/cli/cmd/context/rm.go @@ -17,8 +17,9 @@ package context import ( - "github.com/docker/compose-cli/cli/mobycli" "github.com/spf13/cobra" + + "github.com/docker/compose-cli/cli/mobycli" ) type removeOpts struct { diff --git a/cli/cmd/secrets.go b/cli/cmd/secrets.go index 96d877fc..b119c43b 100644 --- a/cli/cmd/secrets.go +++ b/cli/cmd/secrets.go @@ -19,7 +19,6 @@ package cmd import ( "fmt" "io" - "io/ioutil" "os" "github.com/docker/compose/v2/cmd/formatter" @@ -73,7 +72,7 @@ func createSecret() *cobra.Command { } defer func() { _ = in.Close() }() } - content, err := ioutil.ReadAll(in) + content, err := io.ReadAll(in) if err != nil { return fmt.Errorf("failed to read content from %q: %v", file, err) } diff --git a/cli/config/flags_test.go b/cli/config/flags_test.go index 3e689021..4919a284 100644 --- a/cli/config/flags_test.go +++ b/cli/config/flags_test.go @@ -17,7 +17,6 @@ package config import ( - "io/ioutil" "os" "path/filepath" "testing" @@ -32,11 +31,11 @@ var contextSetConfig = []byte(`{ }`) func TestDetermineCurrentContext(t *testing.T) { - d, err := ioutil.TempDir("", "") + d, err := os.MkdirTemp("", "") // nolint errcheck defer os.RemoveAll(d) assert.NilError(t, err) - err = ioutil.WriteFile(filepath.Join(d, config.ConfigFileName), contextSetConfig, 0644) + err = os.WriteFile(filepath.Join(d, config.ConfigFileName), contextSetConfig, 0644) assert.NilError(t, err) // If nothing set, fallback to default diff --git a/cli/metrics/client.go b/cli/metrics/client.go index 46103e0a..66119ad6 100644 --- a/cli/metrics/client.go +++ b/cli/metrics/client.go @@ -32,8 +32,7 @@ type client struct { } type cliversion struct { - version string - f func() string + f func() string } // Command is a command diff --git a/cli/metrics/metadata/build.go b/cli/metrics/metadata/build.go index bcf42b0e..f54c5f56 100644 --- a/cli/metrics/metadata/build.go +++ b/cli/metrics/metadata/build.go @@ -21,7 +21,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "os" "path" "path/filepath" @@ -115,7 +114,7 @@ func buildxDriver(dockercfg *configfile.ConfigFile, buildArgs []string) string { // "Name": "builder", // "Global": false // } - rawCurrent, err := ioutil.ReadFile(fileCurrent) + rawCurrent, err := os.ReadFile(fileCurrent) if err != nil { return driver } @@ -167,7 +166,7 @@ func buildxDriver(dockercfg *configfile.ConfigFile, buildArgs []string) string { // ], // "Dynamic": false // } - rawBuilder, err := ioutil.ReadFile(fileBuilder) + rawBuilder, err := os.ReadFile(fileBuilder) if err != nil { return driver } diff --git a/cli/metrics/metrics.go b/cli/metrics/metrics.go index 247e55be..82edfd2c 100644 --- a/cli/metrics/metrics.go +++ b/cli/metrics/metrics.go @@ -20,8 +20,9 @@ import ( "os" "strings" - "github.com/docker/compose-cli/cli/metrics/metadata" "github.com/docker/compose/v2/pkg/utils" + + "github.com/docker/compose-cli/cli/metrics/metadata" ) func (c *client) Track(context string, args []string, status string) { diff --git a/cli/mobycli/exec.go b/cli/mobycli/exec.go index 8307289a..98d8cc68 100644 --- a/cli/mobycli/exec.go +++ b/cli/mobycli/exec.go @@ -28,13 +28,14 @@ import ( "runtime" "strings" + "github.com/docker/compose/v2/pkg/compose" + "github.com/google/shlex" + "github.com/spf13/cobra" + apicontext "github.com/docker/compose-cli/api/context" "github.com/docker/compose-cli/api/context/store" "github.com/docker/compose-cli/cli/metrics" "github.com/docker/compose-cli/cli/mobycli/resolvepath" - "github.com/docker/compose/v2/pkg/compose" - "github.com/google/shlex" - "github.com/spf13/cobra" ) var delegatedContextTypes = []string{store.DefaultContextType} diff --git a/cli/mobycli/exec_test.go b/cli/mobycli/exec_test.go index b9109306..62acf00a 100644 --- a/cli/mobycli/exec_test.go +++ b/cli/mobycli/exec_test.go @@ -23,8 +23,9 @@ import ( "gotest.tools/v3/assert" - "github.com/docker/compose-cli/api/context/store" "github.com/stretchr/testify/require" + + "github.com/docker/compose-cli/api/context/store" ) func TestDelegateContextTypeToMoby(t *testing.T) { diff --git a/cli/server/interceptor_test.go b/cli/server/interceptor_test.go index 3bc401a5..58716bb7 100644 --- a/cli/server/interceptor_test.go +++ b/cli/server/interceptor_test.go @@ -18,7 +18,6 @@ package server import ( "context" - "io/ioutil" "os" "path" "testing" @@ -33,7 +32,7 @@ import ( ) func testContext(t *testing.T) context.Context { - dir, err := ioutil.TempDir("", "example") + dir, err := os.MkdirTemp("", "example") assert.NilError(t, err) t.Cleanup(func() { @@ -42,7 +41,7 @@ func testContext(t *testing.T) context.Context { ctx := context.Background() config.WithDir(dir) - err = ioutil.WriteFile(path.Join(dir, "config.json"), []byte(`{"currentContext": "default"}`), 0644) + err = os.WriteFile(path.Join(dir, "config.json"), []byte(`{"currentContext": "default"}`), 0644) assert.NilError(t, err) return ctx diff --git a/cli/server/protos/containers/v1/containers.pb.go b/cli/server/protos/containers/v1/containers.pb.go index 20cce325..7b1dda2c 100644 --- a/cli/server/protos/containers/v1/containers.pb.go +++ b/cli/server/protos/containers/v1/containers.pb.go @@ -23,13 +23,14 @@ package v1 import ( context "context" + reflect "reflect" + sync "sync" + grpc "google.golang.org/grpc" codes "google.golang.org/grpc/codes" status "google.golang.org/grpc/status" protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoimpl "google.golang.org/protobuf/runtime/protoimpl" - reflect "reflect" - sync "sync" ) const ( diff --git a/cli/server/protos/contexts/v1/contexts.pb.go b/cli/server/protos/contexts/v1/contexts.pb.go index 19763701..71c37f95 100644 --- a/cli/server/protos/contexts/v1/contexts.pb.go +++ b/cli/server/protos/contexts/v1/contexts.pb.go @@ -23,13 +23,14 @@ package v1 import ( context "context" + reflect "reflect" + sync "sync" + grpc "google.golang.org/grpc" codes "google.golang.org/grpc/codes" status "google.golang.org/grpc/status" protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoimpl "google.golang.org/protobuf/runtime/protoimpl" - reflect "reflect" - sync "sync" ) const ( diff --git a/cli/server/protos/streams/v1/streams.pb.go b/cli/server/protos/streams/v1/streams.pb.go index 4d8474a8..0ded64a9 100644 --- a/cli/server/protos/streams/v1/streams.pb.go +++ b/cli/server/protos/streams/v1/streams.pb.go @@ -23,14 +23,15 @@ package v1 import ( context "context" + reflect "reflect" + sync "sync" + grpc "google.golang.org/grpc" codes "google.golang.org/grpc/codes" status "google.golang.org/grpc/status" protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoimpl "google.golang.org/protobuf/runtime/protoimpl" anypb "google.golang.org/protobuf/types/known/anypb" - reflect "reflect" - sync "sync" ) const ( diff --git a/cli/server/protos/volumes/v1/volumes.pb.go b/cli/server/protos/volumes/v1/volumes.pb.go index 2711c86e..6ebeb4d1 100644 --- a/cli/server/protos/volumes/v1/volumes.pb.go +++ b/cli/server/protos/volumes/v1/volumes.pb.go @@ -23,14 +23,15 @@ package v1 import ( context "context" + reflect "reflect" + sync "sync" + grpc "google.golang.org/grpc" codes "google.golang.org/grpc/codes" status "google.golang.org/grpc/status" protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoimpl "google.golang.org/protobuf/runtime/protoimpl" _ "google.golang.org/protobuf/types/known/anypb" - reflect "reflect" - sync "sync" ) const ( diff --git a/docs/yaml/main/generate.go b/docs/yaml/main/generate.go index 40d29417..1ebb186d 100644 --- a/docs/yaml/main/generate.go +++ b/docs/yaml/main/generate.go @@ -18,7 +18,6 @@ package main import ( "fmt" - "io/ioutil" "log" "os" "path/filepath" @@ -82,7 +81,7 @@ func loadLongDescription(cmd *cobra.Command, path ...string) error { continue } - content, err := ioutil.ReadFile(fullpath) + content, err := os.ReadFile(fullpath) if err != nil { return err } diff --git a/ecs/cloudformation.go b/ecs/cloudformation.go index 8b673510..774724a9 100644 --- a/ecs/cloudformation.go +++ b/ecs/cloudformation.go @@ -19,7 +19,7 @@ package ecs import ( "context" "fmt" - "io/ioutil" + "os" "regexp" "strings" @@ -38,12 +38,13 @@ import ( "github.com/compose-spec/compose-go/types" "github.com/distribution/distribution/v3/reference" cliconfig "github.com/docker/cli/cli/config" - "github.com/docker/compose-cli/api/config" - "github.com/docker/compose-cli/utils" "github.com/docker/compose/v2/pkg/api" "github.com/opencontainers/go-digest" "sigs.k8s.io/kustomize/kyaml/yaml" "sigs.k8s.io/kustomize/kyaml/yaml/merge2" + + "github.com/docker/compose-cli/api/config" + "github.com/docker/compose-cli/utils" ) func (b *ecsAPIService) Convert(ctx context.Context, project *types.Project, options api.ConvertOptions) ([]byte, error) { @@ -297,7 +298,7 @@ func (b *ecsAPIService) createSecret(project *types.Project, name string, s type if s.External.External { return nil } - sensitiveData, err := ioutil.ReadFile(s.File) + sensitiveData, err := os.ReadFile(s.File) if err != nil { return err } @@ -543,5 +544,6 @@ func volumeResourceName(service string) string { } func normalizeResourceName(s string) string { + //nolint:staticcheck // Preserving for compatibility return strings.Title(regexp.MustCompile("[^a-zA-Z0-9]+").ReplaceAllString(s, "")) } diff --git a/ecs/cloudformation_test.go b/ecs/cloudformation_test.go index a957a5bc..8f33c08a 100644 --- a/ecs/cloudformation_test.go +++ b/ecs/cloudformation_test.go @@ -20,7 +20,7 @@ import ( "context" "errors" "fmt" - "io/ioutil" + "os" "reflect" "testing" @@ -41,7 +41,7 @@ import ( ) func TestSimpleConvert(t *testing.T) { - bytes, err := ioutil.ReadFile("testdata/input/simple-single-service.yaml") + bytes, err := os.ReadFile("testdata/input/simple-single-service.yaml") assert.NilError(t, err) template := convertYaml(t, string(bytes), nil, useDefaultVPC) resultAsJSON, err := marshall(template, "yaml") diff --git a/ecs/convert.go b/ecs/convert.go index b24420b0..be1deedc 100644 --- a/ecs/convert.go +++ b/ecs/convert.go @@ -499,7 +499,7 @@ func toLinuxParameters(service types.ServiceConfig) *ecs.TaskDefinition_LinuxPar } func toTmpfs(tmpfs types.StringList) []ecs.TaskDefinition_Tmpfs { - if tmpfs == nil || len(tmpfs) == 0 { + if len(tmpfs) == 0 { return nil } o := []ecs.TaskDefinition_Tmpfs{} @@ -549,7 +549,7 @@ func durationToInt(interval *types.Duration) int { } func toHostEntryPtr(hosts types.HostsList) []ecs.TaskDefinition_HostEntry { - if hosts == nil || len(hosts) == 0 { + if len(hosts) == 0 { return nil } e := []ecs.TaskDefinition_HostEntry{} diff --git a/ecs/down.go b/ecs/down.go index c80a01aa..3a73dac6 100644 --- a/ecs/down.go +++ b/ecs/down.go @@ -19,9 +19,10 @@ package ecs import ( "context" - "github.com/docker/compose-cli/utils" "github.com/docker/compose/v2/pkg/api" "github.com/docker/compose/v2/pkg/progress" + + "github.com/docker/compose-cli/utils" ) func (b *ecsAPIService) Down(ctx context.Context, projectName string, options api.DownOptions) error { diff --git a/ecs/e2e/ecs/e2e-ecs_test.go b/ecs/e2e/ecs/e2e-ecs_test.go index a806d90b..406dd3c7 100644 --- a/ecs/e2e/ecs/e2e-ecs_test.go +++ b/ecs/e2e/ecs/e2e-ecs_test.go @@ -18,7 +18,6 @@ package main import ( "fmt" - "io/ioutil" "net/http" "os" "path/filepath" @@ -54,7 +53,7 @@ func TestSecrets(t *testing.T) { t.Run("create secret", func(t *testing.T) { secretFile := filepath.Join(cmd.BinDir, "secret.txt") - err := ioutil.WriteFile(secretFile, []byte("pass1"), 0644) + err := os.WriteFile(secretFile, []byte("pass1"), 0644) assert.Check(t, err == nil) res := cmd.RunDockerCmd("secret", "create", secretName, secretFile) assert.Check(t, strings.Contains(res.Stdout(), secretName), res.Stdout()) diff --git a/ecs/list.go b/ecs/list.go index 4cc84f09..d6f1604f 100644 --- a/ecs/list.go +++ b/ecs/list.go @@ -20,8 +20,9 @@ import ( "context" "fmt" - "github.com/docker/compose-cli/utils" "github.com/docker/compose/v2/pkg/api" + + "github.com/docker/compose-cli/utils" ) func (b *ecsAPIService) List(ctx context.Context, opts api.ListOptions) ([]api.Stack, error) { diff --git a/ecs/ps.go b/ecs/ps.go index a21f9517..af4d4e20 100644 --- a/ecs/ps.go +++ b/ecs/ps.go @@ -19,8 +19,9 @@ package ecs import ( "context" - "github.com/docker/compose-cli/utils" "github.com/docker/compose/v2/pkg/api" + + "github.com/docker/compose-cli/utils" ) func (b *ecsAPIService) Ps(ctx context.Context, projectName string, options api.PsOptions) ([]api.ContainerSummary, error) { diff --git a/ecs/resolv/resolv_test.go b/ecs/resolv/resolv_test.go index 2dd37e32..c027039f 100644 --- a/ecs/resolv/resolv_test.go +++ b/ecs/resolv/resolv_test.go @@ -17,7 +17,6 @@ package resolv import ( - "io/ioutil" "os" "path/filepath" "testing" @@ -35,7 +34,7 @@ func TestSetDomain(t *testing.T) { err := SetSearchDomains(f, "foo", "bar", "zot") assert.NilError(t, err) - got, err := ioutil.ReadFile(f) + got, err := os.ReadFile(f) assert.NilError(t, err) golden.Assert(t, string(got), "resolv.conf.golden") } diff --git a/ecs/sdk.go b/ecs/sdk.go index 3fa18ef9..72c2a3f0 100644 --- a/ecs/sdk.go +++ b/ecs/sdk.go @@ -938,7 +938,8 @@ func (s sdk) DescribeServiceTasks(ctx context.Context, cluster string, project s Name: id.Resource, Project: project, Service: service, - State: strings.Title(strings.ToLower(aws.StringValue(t.LastStatus))), + //nolint:staticcheck // Preserving for compatibility + State: strings.Title(strings.ToLower(aws.StringValue(t.LastStatus))), }) } diff --git a/ecs/secrets/init.go b/ecs/secrets/init.go index dd0c5874..21be68b7 100644 --- a/ecs/secrets/init.go +++ b/ecs/secrets/init.go @@ -19,7 +19,6 @@ package secrets import ( "encoding/json" "fmt" - "io/ioutil" "os" "path/filepath" ) @@ -42,7 +41,7 @@ func CreateSecretFiles(secret Secret, path string) error { if len(secret.Keys) == 0 { // raw Secret fmt.Printf("inject Secret %q info %s\n", secret.Name, secrets) - return ioutil.WriteFile(secrets, []byte(value), 0444) + return os.WriteFile(secrets, []byte(value), 0444) } var unmarshalled interface{} @@ -87,7 +86,7 @@ func CreateSecretFiles(secret Secret, path string) error { } } - err = ioutil.WriteFile(path, raw, 0444) + err = os.WriteFile(path, raw, 0444) if err != nil { return err } diff --git a/ecs/secrets/init_test.go b/ecs/secrets/init_test.go index 57623a9b..369b7515 100644 --- a/ecs/secrets/init_test.go +++ b/ecs/secrets/init_test.go @@ -17,7 +17,6 @@ package secrets import ( - "io/ioutil" "os" "path/filepath" "testing" @@ -37,7 +36,7 @@ func TestRawSecret(t *testing.T) { Keys: nil, }, dir) assert.NilError(t, err) - file, err := ioutil.ReadFile(filepath.Join(dir, "raw")) + file, err := os.ReadFile(filepath.Join(dir, "raw")) assert.NilError(t, err) content := string(file) assert.Equal(t, content, "something_secret") @@ -58,7 +57,7 @@ func TestSelectedKeysSecret(t *testing.T) { Keys: []string{"foo"}, }, dir) assert.NilError(t, err) - file, err := ioutil.ReadFile(filepath.Join(dir, "json", "foo")) + file, err := os.ReadFile(filepath.Join(dir, "json", "foo")) assert.NilError(t, err) content := string(file) assert.Equal(t, content, "bar") @@ -82,12 +81,12 @@ func TestAllKeysSecret(t *testing.T) { Keys: []string{"*"}, }, dir) assert.NilError(t, err) - file, err := ioutil.ReadFile(filepath.Join(dir, "json", "foo")) + file, err := os.ReadFile(filepath.Join(dir, "json", "foo")) assert.NilError(t, err) content := string(file) assert.Equal(t, content, "bar") - file, err = ioutil.ReadFile(filepath.Join(dir, "json", "zot")) + file, err = os.ReadFile(filepath.Join(dir, "json", "zot")) assert.NilError(t, err) content = string(file) assert.Equal(t, content, "qix") diff --git a/ecs/up.go b/ecs/up.go index 60183d76..295a30bc 100644 --- a/ecs/up.go +++ b/ecs/up.go @@ -24,10 +24,11 @@ import ( "syscall" "github.com/compose-spec/compose-go/types" - "github.com/docker/compose-cli/utils" "github.com/docker/compose/v2/pkg/api" "github.com/docker/compose/v2/pkg/progress" "github.com/sirupsen/logrus" + + "github.com/docker/compose-cli/utils" ) func (b *ecsAPIService) Up(ctx context.Context, project *types.Project, options api.UpOptions) error { diff --git a/kube/helm/chart.go b/kube/helm/chart.go index e297c969..78518996 100644 --- a/kube/helm/chart.go +++ b/kube/helm/chart.go @@ -28,10 +28,11 @@ import ( "strings" "github.com/compose-spec/compose-go/types" - "github.com/docker/compose-cli/kube/resources" "github.com/pkg/errors" "gopkg.in/yaml.v3" + "github.com/docker/compose-cli/kube/resources" + chart "helm.sh/helm/v3/pkg/chart" loader "helm.sh/helm/v3/pkg/chart/loader" "k8s.io/apimachinery/pkg/runtime" diff --git a/kube/resources/context.go b/kube/resources/context.go index 617ae5e5..c56ab25e 100644 --- a/kube/resources/context.go +++ b/kube/resources/context.go @@ -23,10 +23,11 @@ import ( "fmt" "os" - "github.com/docker/compose-cli/api/context/store" "k8s.io/cli-runtime/pkg/genericclioptions" "k8s.io/client-go/tools/clientcmd" "k8s.io/client-go/tools/clientcmd/api" + + "github.com/docker/compose-cli/api/context/store" ) // ListAvailableKubeConfigContexts list kube contexts diff --git a/kube/resources/secrets.go b/kube/resources/secrets.go index 88a960d5..bf900009 100644 --- a/kube/resources/secrets.go +++ b/kube/resources/secrets.go @@ -20,7 +20,7 @@ package resources import ( - "io/ioutil" + "os" "strings" "github.com/compose-spec/compose-go/types" @@ -37,7 +37,7 @@ func toSecretSpecs(project *types.Project) ([]corev1.Secret, error) { } name := strings.ReplaceAll(s.Name, "_", "-") // load secret file content - sensitiveData, err := ioutil.ReadFile(s.File) + sensitiveData, err := os.ReadFile(s.File) if err != nil { return nil, err } diff --git a/local/e2e/cli-only/e2e_test.go b/local/e2e/cli-only/e2e_test.go index ad6075ca..325c51a4 100644 --- a/local/e2e/cli-only/e2e_test.go +++ b/local/e2e/cli-only/e2e_test.go @@ -18,7 +18,6 @@ package main import ( "fmt" - "io/ioutil" "os" "path/filepath" "runtime" @@ -326,13 +325,13 @@ func TestLoginCommandDelegation(t *testing.T) { func TestMissingExistingCLI(t *testing.T) { t.Parallel() - home, err := ioutil.TempDir("", "") + home, err := os.MkdirTemp("", "") assert.NilError(t, err) t.Cleanup(func() { _ = os.RemoveAll(home) }) - bin, err := ioutil.TempDir("", "") + bin, err := os.MkdirTemp("", "") assert.NilError(t, err) t.Cleanup(func() { _ = os.RemoveAll(bin) diff --git a/local/e2e/container/skip_win_ci_test.go b/local/e2e/container/skip_win_ci_test.go index 96b8f45c..89b6dceb 100644 --- a/local/e2e/container/skip_win_ci_test.go +++ b/local/e2e/container/skip_win_ci_test.go @@ -17,7 +17,6 @@ package e2e import ( - "io/ioutil" "os" "path/filepath" "runtime" @@ -71,12 +70,12 @@ func TestKillChildProcess(t *testing.T) { } func writeDockerfile(t *testing.T) string { - d, err := ioutil.TempDir("", "") + d, err := os.MkdirTemp("", "") assert.NilError(t, err) t.Cleanup(func() { _ = os.RemoveAll(d) }) - err = ioutil.WriteFile(filepath.Join(d, "Dockerfile"), []byte(`FROM alpine:3.10 + err = os.WriteFile(filepath.Join(d, "Dockerfile"), []byte(`FROM alpine:3.10 RUN sleep 100`), 0644) assert.NilError(t, err) return d diff --git a/utils/check.go b/utils/check.go index 376647c0..6b94b12d 100644 --- a/utils/check.go +++ b/utils/check.go @@ -21,10 +21,11 @@ import ( "fmt" "strings" - "github.com/docker/compose-cli/api/config" "github.com/docker/compose/v2/pkg/api" "github.com/hashicorp/go-multierror" "github.com/pkg/errors" + + "github.com/docker/compose-cli/api/config" ) // CheckUnsupported checks if a flag was used when it shouldn't and adds an error in case diff --git a/utils/e2e/framework.go b/utils/e2e/framework.go index 9d1d93c3..72bdb59e 100644 --- a/utils/e2e/framework.go +++ b/utils/e2e/framework.go @@ -19,7 +19,6 @@ package e2e import ( "fmt" "io" - "io/ioutil" "net/http" "os" "os/exec" @@ -70,12 +69,12 @@ func NewE2eCLI(t *testing.T, binDir string) *E2eCLI { } func newE2eCLI(t *testing.T, binDir string) *E2eCLI { - d, err := ioutil.TempDir("", "") + d, err := os.MkdirTemp("", "") assert.Check(t, is.Nil(err)) t.Cleanup(func() { if t.Failed() { - conf, _ := ioutil.ReadFile(filepath.Join(d, "config.json")) + conf, _ := os.ReadFile(filepath.Join(d, "config.json")) t.Errorf("Config: %s\n", string(conf)) t.Error("Contents of config dir:") for _, p := range dirContents(d) { @@ -124,7 +123,7 @@ func SetupExistingCLI() (string, func(), error) { } } - d, err := ioutil.TempDir("", "") + d, err := os.MkdirTemp("", "") if err != nil { return "", nil, err } @@ -315,7 +314,7 @@ func HTTPGetWithRetry(t *testing.T, endpoint string, expectedStatus int, retryDe } poll.WaitOn(t, checkUp, poll.WithDelay(retryDelay), poll.WithTimeout(timeout)) if r != nil { - b, err := ioutil.ReadAll(r.Body) + b, err := io.ReadAll(r.Body) assert.NilError(t, err) return string(b) } diff --git a/utils/e2e/mockmetrics.go b/utils/e2e/mockmetrics.go index 681d9799..d3798a59 100644 --- a/utils/e2e/mockmetrics.go +++ b/utils/e2e/mockmetrics.go @@ -17,7 +17,7 @@ package e2e import ( - "io/ioutil" + "io" "log" "net" "net/http" @@ -42,7 +42,7 @@ func NewMetricsServer(socket string) *MockMetricsServer { } func (s *MockMetricsServer) handlePostUsage(c echo.Context) error { - body, error := ioutil.ReadAll(c.Request().Body) + body, error := io.ReadAll(c.Request().Body) if error != nil { return error }