mirror of
https://github.com/go-kratos/kratos.git
synced 2025-01-10 00:29:01 +02:00
Merge pull request #499 from bilibili/lich/support_windows
lich support windows,奥里给!
This commit is contained in:
commit
7c946dc919
@ -9,6 +9,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/bilibili/kratos/pkg/log"
|
"github.com/bilibili/kratos/pkg/log"
|
||||||
@ -24,6 +25,7 @@ var (
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
flag.StringVar(&yamlPath, "f", "docker-compose.yaml", "composer yaml path.")
|
flag.StringVar(&yamlPath, "f", "docker-compose.yaml", "composer yaml path.")
|
||||||
|
flag.IntVar(&retry, "retry", 5, "number of retries on network failure.")
|
||||||
flag.BoolVar(&noDown, "nodown", false, "containers are not recycled.")
|
flag.BoolVar(&noDown, "nodown", false, "containers are not recycled.")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -74,10 +76,13 @@ func getServices() (output []byte, err error) {
|
|||||||
if output, err = runCompose("config", "--services"); err != nil {
|
if output, err = runCompose("config", "--services"); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
var eol = []byte("\n")
|
||||||
|
if output = bytes.TrimSpace(output); runtime.GOOS == "windows" {
|
||||||
|
eol = []byte("\r\n")
|
||||||
|
}
|
||||||
services = make(map[string]*Container)
|
services = make(map[string]*Container)
|
||||||
output = bytes.TrimSpace(output)
|
for _, svr := range bytes.Split(output, eol) {
|
||||||
for _, svr := range bytes.Split(output, []byte("\n")) {
|
if output, err = runCompose("ps", "-q", string(svr)); err != nil {
|
||||||
if output, err = runCompose("ps", "-a", "-q", string(svr)); err != nil {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
var (
|
var (
|
||||||
@ -105,18 +110,17 @@ func getServices() (output []byte, err error) {
|
|||||||
|
|
||||||
func checkServices() (output []byte, err error) {
|
func checkServices() (output []byte, err error) {
|
||||||
defer func() {
|
defer func() {
|
||||||
if err != nil && retry < 4 {
|
if err != nil && retry > 0 {
|
||||||
retry++
|
retry--
|
||||||
getServices()
|
getServices()
|
||||||
time.Sleep(time.Second * 5)
|
time.Sleep(time.Second * 5)
|
||||||
output, err = checkServices()
|
output, err = checkServices()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
retry = 0
|
|
||||||
}()
|
}()
|
||||||
for svr, c := range services {
|
for svr, c := range services {
|
||||||
if err = c.Healthcheck(); err != nil {
|
if err = c.Healthcheck(); err != nil {
|
||||||
log.Error("healthcheck(%s) error(%v) retrying %d times...", svr, err, 5-retry)
|
log.Error("healthcheck(%s) error(%v) retrying %d times...", svr, err, retry)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// TODO About container check and more...
|
// TODO About container check and more...
|
||||||
|
@ -67,12 +67,21 @@ var toolIndexs = []*Tool{
|
|||||||
Requirements: []string{"wire"},
|
Requirements: []string{"wire"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "testcli",
|
Name: "testgen",
|
||||||
Alias: "testcli",
|
Alias: "testgen",
|
||||||
BuildTime: time.Date(2019, 9, 9, 0, 0, 0, 0, time.Local),
|
BuildTime: time.Date(2020, 1, 20, 22, 33, 0, 0, time.Local),
|
||||||
Install: "go get -u github.com/bilibili/kratos/tool/testcli",
|
Install: "go get -u github.com/bilibili/kratos/tool/testgen",
|
||||||
Summary: "测试代码生成",
|
Summary: "测试代码生成",
|
||||||
Platform: []string{"darwin", "linux", "windows"},
|
Platform: []string{"darwin", "linux", "windows"},
|
||||||
Author: "kratos",
|
Author: "kratos",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Name: "testcli",
|
||||||
|
Alias: "testcli",
|
||||||
|
BuildTime: time.Date(2020, 1, 20, 22, 33, 0, 0, time.Local),
|
||||||
|
Install: "go get -u github.com/bilibili/kratos/tool/testcli",
|
||||||
|
Summary: "测试代码运行",
|
||||||
|
Platform: []string{"darwin", "linux", "windows"},
|
||||||
|
Author: "kratos",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user