mirror of
https://github.com/zeromicro/go-zero.git
synced 2026-05-11 00:40:00 +08:00
chore: not using goproxy by default (#4613)
This commit is contained in:
@@ -3,7 +3,8 @@ FROM golang:alpine AS builder
|
|||||||
LABEL stage=gobuilder
|
LABEL stage=gobuilder
|
||||||
|
|
||||||
ENV CGO_ENABLED=0
|
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 apk update --no-cache && apk add --no-cache tzdata
|
||||||
RUN go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
|
RUN go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
|
||||||
|
|||||||
@@ -31,7 +31,6 @@ if [ -d $WD ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
execute_command "mkdir -p $BIN $PROJECT_DIR $OLD_CODE $NEW_CODE"
|
execute_command "mkdir -p $BIN $PROJECT_DIR $OLD_CODE $NEW_CODE"
|
||||||
execute_command 'export GOPROXY="https://goproxy.cn,direct"'
|
|
||||||
execute_command "export GOBIN=$BIN"
|
execute_command "export GOBIN=$BIN"
|
||||||
|
|
||||||
echo "=======================install goctl============================="
|
echo "=======================install goctl============================="
|
||||||
|
|||||||
@@ -3,10 +3,8 @@ FROM golang:{{.Version}}alpine AS builder
|
|||||||
LABEL stage=gobuilder
|
LABEL stage=gobuilder
|
||||||
|
|
||||||
ENV CGO_ENABLED 0
|
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
|
{{if .HasTimezone}}
|
||||||
{{- end}}{{if .HasTimezone}}
|
|
||||||
RUN apk update --no-cache && apk add --no-cache tzdata
|
RUN apk update --no-cache && apk add --no-cache tzdata
|
||||||
{{- end}}
|
{{- end}}
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ if [ $? -ne 0 ]; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
GOPROXY="https://goproxy.cn,direct" && go mod tidy
|
go mod tidy
|
||||||
|
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
echo "Tidy failed"
|
echo "Tidy failed"
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ if [ $? -ne 0 ]; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
GOPROXY="https://goproxy.cn,direct" && go mod tidy
|
go mod tidy
|
||||||
|
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
echo "Tidy failed"
|
echo "Tidy failed"
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// BuildVersion is the version of goctl.
|
// 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}
|
var tag = map[string]int{"pre-alpha": 0, "alpha": 1, "pre-bata": 2, "beta": 3, "released": 4, "": 5}
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
|
||||||
}
|
|
||||||
@@ -15,33 +15,29 @@ var client = http.Client{
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getLatest(repo string, verbose bool) ([]string, error) {
|
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) {
|
log := func(err error) {
|
||||||
console.Warning("get latest versions failed from proxy %q, error: %+v", proxy, err)
|
console.Warning("get latest versions failed, error: %+v", err)
|
||||||
}
|
}
|
||||||
resp, err := client.Get(fmt.Sprintf("%s/%s/@v/list", proxy, repo))
|
resp, err := client.Get(fmt.Sprintf("%s/@v/list", repo))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log(err)
|
log(err)
|
||||||
continue
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if resp.StatusCode != http.StatusOK {
|
if resp.StatusCode != http.StatusOK {
|
||||||
log(fmt.Errorf("%s", resp.Status))
|
err = fmt.Errorf("%s", resp.Status)
|
||||||
continue
|
log(err)
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
data, err := io.ReadAll(resp.Body)
|
data, err := io.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log(err)
|
log(err)
|
||||||
continue
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
versionStr := string(data)
|
versionStr := string(data)
|
||||||
versions := strings.Fields(versionStr)
|
versions := strings.Fields(versionStr)
|
||||||
return versions, nil
|
return versions, nil
|
||||||
}
|
|
||||||
return []string{}, nil
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,19 +5,16 @@ import (
|
|||||||
"os/exec"
|
"os/exec"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/tools/goctl/util/env"
|
|
||||||
"github.com/zeromicro/go-zero/tools/goctl/vars"
|
"github.com/zeromicro/go-zero/tools/goctl/vars"
|
||||||
)
|
)
|
||||||
|
|
||||||
const goproxy = "GOPROXY=https://goproxy.cn,direct"
|
|
||||||
|
|
||||||
func goStart(dir string) {
|
func goStart(dir string) {
|
||||||
execCommand(dir, "go run .", prepareGoProxyEnv()...)
|
execCommand(dir, "go run .")
|
||||||
}
|
}
|
||||||
|
|
||||||
func goModTidy(dir string) int {
|
func goModTidy(dir string) int {
|
||||||
log.Debug(">> go mod tidy")
|
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 {
|
func execCommand(dir, arg string, envArgs ...string) int {
|
||||||
@@ -34,11 +31,3 @@ func execCommand(dir, arg string, envArgs ...string) int {
|
|||||||
_ = cmd.Run()
|
_ = cmd.Run()
|
||||||
return cmd.ProcessState.ExitCode()
|
return cmd.ProcessState.ExitCode()
|
||||||
}
|
}
|
||||||
|
|
||||||
func prepareGoProxyEnv(envArgs ...string) []string {
|
|
||||||
if env.InChina() {
|
|
||||||
return append(envArgs, goproxy)
|
|
||||||
}
|
|
||||||
|
|
||||||
return envArgs
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
FROM golang:1.22-alpine
|
FROM golang:1.22-alpine
|
||||||
|
|
||||||
ENV TZ Asia/Shanghai
|
# set timezone if you need
|
||||||
ENV GOPROXY https://goproxy.cn,direct
|
# 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
|
WORKDIR /app
|
||||||
COPY goctl /usr/bin/
|
COPY goctl /usr/bin/
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ if [ $? -ne 0 ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# go mod tidy
|
# go mod tidy
|
||||||
GOPROXY=https://goproxy.cn && go mod tidy
|
go mod tidy
|
||||||
|
|
||||||
# code inspection
|
# code inspection
|
||||||
go test -race ./...
|
go test -race ./...
|
||||||
|
|||||||
@@ -11,9 +11,9 @@ import (
|
|||||||
// upgrade gets the latest goctl by
|
// upgrade gets the latest goctl by
|
||||||
// go install github.com/zeromicro/go-zero/tools/goctl@latest
|
// go install github.com/zeromicro/go-zero/tools/goctl@latest
|
||||||
func upgrade(_ *cobra.Command, _ []string) error {
|
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" {
|
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, "")
|
info, err := execx.Run(cmd, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user