From de05e57c746724aec3bbc9f28064181be37554aa Mon Sep 17 00:00:00 2001 From: kevin Date: Wed, 29 Jan 2025 11:48:14 +0800 Subject: [PATCH] chore: not using goproxy by default, and remove aliyun for docker registry, not working --- tools/goctl/Dockerfile | 3 +- tools/goctl/compare/compare.sh | 1 - tools/goctl/docker/docker.tpl | 4 +- .../rpc/multiple_rpc_service_generate.sh | 2 +- .../rpc/single_rpc_service_generate.sh | 2 +- tools/goctl/internal/version/version.go | 2 +- tools/goctl/migrate/proxy.go | 44 ---------------- tools/goctl/migrate/version.go | 50 +++++++++---------- tools/goctl/quickstart/run.go | 15 +----- .../test/integration/model/mongo/Dockerfile | 6 ++- .../goctl/test/integration/model/mongo/cmd.sh | 2 +- tools/goctl/upgrade/upgrade.go | 4 +- 12 files changed, 38 insertions(+), 97 deletions(-) delete mode 100644 tools/goctl/migrate/proxy.go diff --git a/tools/goctl/Dockerfile b/tools/goctl/Dockerfile index adae66597f41..f7f5de65e03f 100644 --- a/tools/goctl/Dockerfile +++ b/tools/goctl/Dockerfile @@ -3,7 +3,8 @@ FROM golang:alpine AS builder LABEL stage=gobuilder ENV CGO_ENABLED=0 -ENV GOPROXY=https://goproxy.cn,direct +# if you are in China, you can use the following command to speed up the download +# ENV GOPROXY=https://goproxy.cn,direct RUN apk update --no-cache && apk add --no-cache tzdata RUN go install google.golang.org/protobuf/cmd/protoc-gen-go@latest diff --git a/tools/goctl/compare/compare.sh b/tools/goctl/compare/compare.sh index cddbbfa1de48..6527078341d2 100644 --- a/tools/goctl/compare/compare.sh +++ b/tools/goctl/compare/compare.sh @@ -31,7 +31,6 @@ if [ -d $WD ]; then fi execute_command "mkdir -p $BIN $PROJECT_DIR $OLD_CODE $NEW_CODE" -execute_command 'export GOPROXY="https://goproxy.cn,direct"' execute_command "export GOBIN=$BIN" echo "=======================install goctl=============================" diff --git a/tools/goctl/docker/docker.tpl b/tools/goctl/docker/docker.tpl index b897b4056556..468f724daee1 100644 --- a/tools/goctl/docker/docker.tpl +++ b/tools/goctl/docker/docker.tpl @@ -3,10 +3,8 @@ FROM golang:{{.Version}}alpine AS builder LABEL stage=gobuilder ENV CGO_ENABLED 0 -{{if .Chinese}}ENV GOPROXY https://goproxy.cn,direct -RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories -{{- end}}{{if .HasTimezone}} +{{if .HasTimezone}} RUN apk update --no-cache && apk add --no-cache tzdata {{- end}} diff --git a/tools/goctl/example/rpc/multiple_rpc_service_generate.sh b/tools/goctl/example/rpc/multiple_rpc_service_generate.sh index a0cdf99c61a1..10b1fa968f84 100644 --- a/tools/goctl/example/rpc/multiple_rpc_service_generate.sh +++ b/tools/goctl/example/rpc/multiple_rpc_service_generate.sh @@ -12,7 +12,7 @@ if [ $? -ne 0 ]; then exit 1 fi -GOPROXY="https://goproxy.cn,direct" && go mod tidy +go mod tidy if [ $? -ne 0 ]; then echo "Tidy failed" diff --git a/tools/goctl/example/rpc/single_rpc_service_generate.sh b/tools/goctl/example/rpc/single_rpc_service_generate.sh index 4c4717de800c..c8e8316f6e8d 100644 --- a/tools/goctl/example/rpc/single_rpc_service_generate.sh +++ b/tools/goctl/example/rpc/single_rpc_service_generate.sh @@ -12,7 +12,7 @@ if [ $? -ne 0 ]; then exit 1 fi -GOPROXY="https://goproxy.cn,direct" && go mod tidy +go mod tidy if [ $? -ne 0 ]; then echo "Tidy failed" diff --git a/tools/goctl/internal/version/version.go b/tools/goctl/internal/version/version.go index 91716db6ab3c..64dbdaf16372 100644 --- a/tools/goctl/internal/version/version.go +++ b/tools/goctl/internal/version/version.go @@ -6,7 +6,7 @@ import ( ) // BuildVersion is the version of goctl. -const BuildVersion = "1.8.0" +const BuildVersion = "1.7.7" var tag = map[string]int{"pre-alpha": 0, "alpha": 1, "pre-bata": 2, "beta": 3, "released": 4, "": 5} diff --git a/tools/goctl/migrate/proxy.go b/tools/goctl/migrate/proxy.go deleted file mode 100644 index 610f2babef67..000000000000 --- a/tools/goctl/migrate/proxy.go +++ /dev/null @@ -1,44 +0,0 @@ -package migrate - -import ( - "net/url" - "os" - "strings" - - "github.com/zeromicro/go-zero/core/stringx" - "github.com/zeromicro/go-zero/tools/goctl/rpc/execx" -) - -var ( - defaultProxy = "https://goproxy.cn" - defaultProxies = []string{defaultProxy} -) - -func goProxy() []string { - wd, err := os.Getwd() - if err != nil { - return defaultProxies - } - - proxy, err := execx.Run("go env GOPROXY", wd) - if err != nil { - return defaultProxies - } - list := strings.FieldsFunc(proxy, func(r rune) bool { - return r == '|' || r == ',' - }) - var ret []string - for _, item := range list { - if len(item) == 0 { - continue - } - _, err = url.Parse(item) - if err == nil && !stringx.Contains(ret, item) { - ret = append(ret, item) - } - } - if !stringx.Contains(ret, defaultProxy) { - ret = append(ret, defaultProxy) - } - return ret -} diff --git a/tools/goctl/migrate/version.go b/tools/goctl/migrate/version.go index 37a4eec0e5cd..e02f124b6149 100644 --- a/tools/goctl/migrate/version.go +++ b/tools/goctl/migrate/version.go @@ -15,33 +15,29 @@ var client = http.Client{ } func getLatest(repo string, verbose bool) ([]string, error) { - proxies := goProxy() - for _, proxy := range proxies { - if verbose { - console.Info("use go proxy %q", proxy) - } - log := func(err error) { - console.Warning("get latest versions failed from proxy %q, error: %+v", proxy, err) - } - resp, err := client.Get(fmt.Sprintf("%s/%s/@v/list", proxy, repo)) - if err != nil { - log(err) - continue - } + log := func(err error) { + console.Warning("get latest versions failed, error: %+v", err) + } + resp, err := client.Get(fmt.Sprintf("%s/@v/list", repo)) + if err != nil { + log(err) + return nil, err + } - if resp.StatusCode != http.StatusOK { - log(fmt.Errorf("%s", resp.Status)) - continue - } - defer resp.Body.Close() - data, err := io.ReadAll(resp.Body) - if err != nil { - log(err) - continue - } - versionStr := string(data) - versions := strings.Fields(versionStr) - return versions, nil + if resp.StatusCode != http.StatusOK { + err = fmt.Errorf("%s", resp.Status) + log(err) + return nil, err } - return []string{}, nil + defer resp.Body.Close() + + data, err := io.ReadAll(resp.Body) + if err != nil { + log(err) + return nil, err + } + + versionStr := string(data) + versions := strings.Fields(versionStr) + return versions, nil } diff --git a/tools/goctl/quickstart/run.go b/tools/goctl/quickstart/run.go index 09896af28894..135d4d3078f4 100644 --- a/tools/goctl/quickstart/run.go +++ b/tools/goctl/quickstart/run.go @@ -5,19 +5,16 @@ import ( "os/exec" "runtime" - "github.com/zeromicro/go-zero/tools/goctl/util/env" "github.com/zeromicro/go-zero/tools/goctl/vars" ) -const goproxy = "GOPROXY=https://goproxy.cn,direct" - func goStart(dir string) { - execCommand(dir, "go run .", prepareGoProxyEnv()...) + execCommand(dir, "go run .") } func goModTidy(dir string) int { log.Debug(">> go mod tidy") - return execCommand(dir, "go mod tidy", prepareGoProxyEnv()...) + return execCommand(dir, "go mod tidy") } func execCommand(dir, arg string, envArgs ...string) int { @@ -34,11 +31,3 @@ func execCommand(dir, arg string, envArgs ...string) int { _ = cmd.Run() return cmd.ProcessState.ExitCode() } - -func prepareGoProxyEnv(envArgs ...string) []string { - if env.InChina() { - return append(envArgs, goproxy) - } - - return envArgs -} diff --git a/tools/goctl/test/integration/model/mongo/Dockerfile b/tools/goctl/test/integration/model/mongo/Dockerfile index fe629b137663..b4772c57b5a8 100644 --- a/tools/goctl/test/integration/model/mongo/Dockerfile +++ b/tools/goctl/test/integration/model/mongo/Dockerfile @@ -1,7 +1,9 @@ FROM golang:1.22-alpine -ENV TZ Asia/Shanghai -ENV GOPROXY https://goproxy.cn,direct +# set timezone if you need +# ENV TZ Asia/Shanghai +# if you are in China, you can use the following command to speed up the download +# ENV GOPROXY https://goproxy.cn,direct WORKDIR /app COPY goctl /usr/bin/ diff --git a/tools/goctl/test/integration/model/mongo/cmd.sh b/tools/goctl/test/integration/model/mongo/cmd.sh index c8ba2edb6965..e76ecfbf05ec 100644 --- a/tools/goctl/test/integration/model/mongo/cmd.sh +++ b/tools/goctl/test/integration/model/mongo/cmd.sh @@ -23,7 +23,7 @@ if [ $? -ne 0 ]; then fi # go mod tidy -GOPROXY=https://goproxy.cn && go mod tidy +go mod tidy # code inspection go test -race ./... diff --git a/tools/goctl/upgrade/upgrade.go b/tools/goctl/upgrade/upgrade.go index 7d96bf0f936d..61be29ad6205 100644 --- a/tools/goctl/upgrade/upgrade.go +++ b/tools/goctl/upgrade/upgrade.go @@ -11,9 +11,9 @@ import ( // upgrade gets the latest goctl by // go install github.com/zeromicro/go-zero/tools/goctl@latest func upgrade(_ *cobra.Command, _ []string) error { - cmd := `GO111MODULE=on GOPROXY=https://goproxy.cn/,direct go install github.com/zeromicro/go-zero/tools/goctl@latest` + cmd := `go install github.com/zeromicro/go-zero/tools/goctl@latest` if runtime.GOOS == "windows" { - cmd = `set GOPROXY=https://goproxy.cn,direct && go install github.com/zeromicro/go-zero/tools/goctl@latest` + cmd = `go install github.com/zeromicro/go-zero/tools/goctl@latest` } info, err := execx.Run(cmd, "") if err != nil {