mirror of
https://gitee.com/rainbond/Rainbond.git
synced 2024-11-30 02:38:17 +08:00
[FIX] debug git clone progress log
This commit is contained in:
parent
ab31288eba
commit
989f7eb7a2
@ -164,7 +164,6 @@ func (d *DockerRunOrImageParse) dockerun(source []string) {
|
||||
name = ""
|
||||
}
|
||||
} else {
|
||||
fmt.Printf("Name %s S : %s \n", name, s)
|
||||
switch name {
|
||||
case "e", "env":
|
||||
info := strings.Split(s, "=")
|
||||
|
@ -27,7 +27,16 @@ import (
|
||||
"github.com/docker/engine-api/client"
|
||||
)
|
||||
|
||||
var dockerrun = `docker run -d -p 8080:8080 -e PWD=1qa2ws --name=tomcat_demo tomcat`
|
||||
var dockerrun = `docker run -d -v /usr/share/ca-certificates/:/etc/ssl/certs -p 4001:4001 -p 2380:2380 -p 2379:2379 \
|
||||
--name etcd quay.io/coreos/etcd:v2.3.8 \
|
||||
-name etcd0 \
|
||||
-advertise-client-urls http://0.0.0.0:2379,http://0.0.0.0:4001 \
|
||||
-listen-client-urls http://0.0.0.0:2379,http://0.0.0.0:4001 \
|
||||
-initial-advertise-peer-urls http://127.0.0.1:2380 \
|
||||
-listen-peer-urls http://0.0.0.0:2380 \
|
||||
-initial-cluster-token etcd-cluster-1 \
|
||||
-initial-cluster etcd0=http://127.0.0.1:2380 \
|
||||
-initial-cluster-state new`
|
||||
|
||||
func TestParse(t *testing.T) {
|
||||
dockerclient, err := client.NewEnvClient()
|
||||
|
@ -20,6 +20,7 @@ package sources
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"context"
|
||||
"crypto/sha1"
|
||||
"fmt"
|
||||
@ -29,8 +30,6 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/twinj/uuid"
|
||||
|
||||
"github.com/Sirupsen/logrus"
|
||||
|
||||
"gopkg.in/src-d/go-git.v4/plumbing/transport/http"
|
||||
@ -123,8 +122,7 @@ func GitClone(csi CodeSourceInfo, sourceDir string, logger event.Logger, timeout
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Minute*time.Duration(timeout))
|
||||
defer cancel()
|
||||
stop := make(chan struct{})
|
||||
progress := createProgress(ctx, logger, stop)
|
||||
progress := createProgress(ctx, logger)
|
||||
opts := &git.CloneOptions{
|
||||
URL: csi.RepositoryURL,
|
||||
Progress: progress,
|
||||
@ -250,22 +248,14 @@ func GetPublicKey() string {
|
||||
}
|
||||
|
||||
//createProgress create git log progress
|
||||
func createProgress(ctx context.Context, logger event.Logger, stop chan struct{}) sideband.Progress {
|
||||
func createProgress(ctx context.Context, logger event.Logger) sideband.Progress {
|
||||
if logger == nil {
|
||||
return os.Stdout
|
||||
}
|
||||
name := "/tmp/" + uuid.NewV4().String()
|
||||
bufferfile, err := os.OpenFile(name, os.O_RDWR|os.O_WRONLY, 755)
|
||||
if err != nil {
|
||||
return os.Stdout
|
||||
}
|
||||
bufferfile := bytes.NewBuffer([]byte{})
|
||||
fmt.Println("logger progress")
|
||||
var reader = bufio.NewReader(bufferfile)
|
||||
go func() {
|
||||
defer func() {
|
||||
bufferfile.Close()
|
||||
os.RemoveAll(name)
|
||||
}()
|
||||
defer close(stop)
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
@ -273,10 +263,13 @@ func createProgress(ctx context.Context, logger event.Logger, stop chan struct{}
|
||||
default:
|
||||
line, _, err := reader.ReadLine()
|
||||
if err != nil {
|
||||
fmt.Println("err", err.Error())
|
||||
return
|
||||
if err.Error() != "EOF" {
|
||||
fmt.Println("read git log err", err.Error())
|
||||
}
|
||||
}
|
||||
if len(line) > 0 {
|
||||
logger.Debug(string(line), map[string]string{"step": "code_progress"})
|
||||
}
|
||||
logger.Debug(string(line), map[string]string{"step": "code_progress"})
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
@ -31,11 +31,11 @@ func init() {
|
||||
}
|
||||
func TestGitClone(t *testing.T) {
|
||||
csi := CodeSourceInfo{
|
||||
RepositoryURL: "git@github.com:rilweic/2048-1.git",
|
||||
RepositoryURL: "ssh://git@gr5042d6.7804f67d.ali-sh-s1.goodrain.net:20905/root/private2018.git",
|
||||
Branch: "master",
|
||||
}
|
||||
//logger := event.GetManager().GetLogger("system")
|
||||
res, err := GitClone(csi, "/tmp/privatetest", nil, 2)
|
||||
logger := event.GetManager().GetLogger("system")
|
||||
res, err := GitClone(csi, "/tmp/privatetest", logger, 2)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user