mirror of
https://gitee.com/rainbond/Rainbond.git
synced 2024-11-30 02:38:17 +08:00
[FIX] fix pull code bug
This commit is contained in:
parent
bab133f263
commit
257c98e782
@ -85,6 +85,7 @@ func NewSouceCodeBuildItem(in []byte) *SourceCodeBuildItem {
|
||||
User: gjson.GetBytes(in, "user").String(),
|
||||
Password: gjson.GetBytes(in, "password").String(),
|
||||
TenantID: gjson.GetBytes(in, "tenant_id").String(),
|
||||
ServiceID: gjson.GetBytes(in, "service_id").String(),
|
||||
}
|
||||
envs := gjson.GetBytes(in, "envs").String()
|
||||
be := make(map[string]string)
|
||||
@ -119,7 +120,7 @@ func (i *SourceCodeBuildItem) Run(timeout time.Duration) error {
|
||||
// 2.check dockerfile/ source_code
|
||||
// 3.build
|
||||
// 4.upload image /upload slug
|
||||
rbi, err := sources.CreateRepostoryBuildInfo(i.CodeSouceInfo.RepositoryURL, i.CodeSouceInfo.Branch, i.TenantID)
|
||||
rbi, err := sources.CreateRepostoryBuildInfo(i.CodeSouceInfo.RepositoryURL, i.CodeSouceInfo.Branch, i.TenantID, i.ServiceID)
|
||||
if err != nil {
|
||||
i.Logger.Error("Git项目仓库地址格式错误", map[string]string{"step": "parse"})
|
||||
return err
|
||||
|
@ -97,7 +97,7 @@ func (d *SourceCodeParse) Parse() ParseErrorList {
|
||||
return d.errors
|
||||
}
|
||||
//验证仓库地址
|
||||
buildInfo, err := sources.CreateRepostoryBuildInfo(csi.RepositoryURL, csi.Branch, csi.TenantID)
|
||||
buildInfo, err := sources.CreateRepostoryBuildInfo(csi.RepositoryURL, csi.Branch, csi.TenantID, csi.ServiceID)
|
||||
if err != nil {
|
||||
d.logger.Error("Git项目仓库地址格式错误", map[string]string{"step": "parse"})
|
||||
d.errappend(ErrorAndSolve(FatalError, "Git项目仓库地址格式错误", SolveAdvice("modify_url", "请确认并修改仓库地址")))
|
||||
|
@ -22,7 +22,6 @@ import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"context"
|
||||
"crypto/sha1"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
@ -62,6 +61,7 @@ type CodeSourceInfo struct {
|
||||
Password string `json:"password"`
|
||||
//避免项目之间冲突,代码缓存目录提高到租户
|
||||
TenantID string `json:"tenant_id"`
|
||||
ServiceID string `json:"service_id"`
|
||||
}
|
||||
|
||||
//GetCodeCacheDir 获取代码缓存目录
|
||||
@ -70,30 +70,30 @@ func (c CodeSourceInfo) GetCodeCacheDir() string {
|
||||
if cacheDir == "" {
|
||||
cacheDir = "/cache"
|
||||
}
|
||||
h := sha1.New()
|
||||
h.Write([]byte(c.RepositoryURL))
|
||||
bs := h.Sum(nil)
|
||||
bsStr := fmt.Sprintf("%x", bs)
|
||||
logrus.Debugf("git path is %s", path.Join(cacheDir, "build", c.TenantID, bsStr))
|
||||
return path.Join(cacheDir, "build", c.TenantID, bsStr)
|
||||
//h := sha1.New()
|
||||
//h.Write([]byte(c.RepositoryURL))
|
||||
//bs := h.Sum(nil)
|
||||
//bsStr := fmt.Sprintf("%x", bs)
|
||||
logrus.Debugf("git path is %s", path.Join(cacheDir, "build", c.TenantID, c.ServiceID))
|
||||
return path.Join(cacheDir, "build", c.TenantID, c.ServiceID)
|
||||
}
|
||||
|
||||
//GetCodeSourceDir 获取代码下载目录
|
||||
func (c CodeSourceInfo) GetCodeSourceDir() string {
|
||||
return GetCodeSourceDir(c.RepositoryURL, c.Branch, c.TenantID)
|
||||
return GetCodeSourceDir(c.RepositoryURL, c.Branch, c.TenantID, c.ServiceID)
|
||||
}
|
||||
|
||||
//GetCodeSourceDir 获取源码下载目录
|
||||
func GetCodeSourceDir(RepositoryURL, branch, tenantID string) string {
|
||||
func GetCodeSourceDir(RepositoryURL, branch, tenantID string, ServiceID string) string {
|
||||
sourceDir := os.Getenv("SOURCE_DIR")
|
||||
if sourceDir == "" {
|
||||
sourceDir = "/grdata/source"
|
||||
}
|
||||
h := sha1.New()
|
||||
h.Write([]byte(RepositoryURL + branch))
|
||||
bs := h.Sum(nil)
|
||||
bsStr := fmt.Sprintf("%x", bs)
|
||||
return path.Join(sourceDir, "build", tenantID, bsStr)
|
||||
//h := sha1.New()
|
||||
//h.Write([]byte(RepositoryURL + branch))
|
||||
//bs := h.Sum(nil)
|
||||
//bsStr := fmt.Sprintf("%x", bs)
|
||||
return path.Join(sourceDir, "build", tenantID, ServiceID)
|
||||
}
|
||||
|
||||
//CheckFileExist CheckFileExist
|
||||
@ -121,7 +121,6 @@ func GitClone(csi CodeSourceInfo, sourceDir string, logger event.Logger, timeout
|
||||
GetPrivateFileParam := csi.TenantID
|
||||
flag := true
|
||||
Loop:
|
||||
fmt.Println(GetPrivateFileParam, flag)
|
||||
if logger != nil {
|
||||
//进度信息
|
||||
logger.Info(fmt.Sprintf("开始从Git源(%s)获取代码", csi.RepositoryURL), map[string]string{"step": "clone_code"})
|
||||
@ -263,7 +262,6 @@ func GitPull(csi CodeSourceInfo, sourceDir string, logger event.Logger, timeout
|
||||
GetPrivateFileParam := csi.TenantID
|
||||
flag := true
|
||||
Loop:
|
||||
fmt.Println(GetPrivateFileParam, flag)
|
||||
if logger != nil {
|
||||
//进度信息
|
||||
logger.Info(fmt.Sprintf("开始从Git源(%s)更新代码", csi.RepositoryURL), map[string]string{"step": "clone_code"})
|
||||
|
@ -61,7 +61,7 @@ func (r *RepostoryBuildInfo) GetProtocol() string {
|
||||
}
|
||||
|
||||
//CreateRepostoryBuildInfo 创建源码编译信息
|
||||
func CreateRepostoryBuildInfo(repoURL, branch, tenantID string) (*RepostoryBuildInfo, error) {
|
||||
func CreateRepostoryBuildInfo(repoURL, branch, tenantID string, ServiceID string) (*RepostoryBuildInfo, error) {
|
||||
// repoURL= github.com/goodrain/xxx.git?dir=home
|
||||
ep, err := transport.NewEndpoint(repoURL)
|
||||
if err != nil {
|
||||
@ -75,9 +75,9 @@ func CreateRepostoryBuildInfo(repoURL, branch, tenantID string) (*RepostoryBuild
|
||||
if index > -1 && len(repoURL) > index+5 {
|
||||
fmt.Println(repoURL[index+5:], repoURL[:index])
|
||||
rbi.BuildPath = repoURL[index+5:]
|
||||
rbi.CodeHome = GetCodeSourceDir(repoURL[:index], branch, tenantID)
|
||||
rbi.CodeHome = GetCodeSourceDir(repoURL[:index], branch, tenantID, ServiceID)
|
||||
rbi.RepostoryURL = repoURL[:index]
|
||||
}
|
||||
rbi.CodeHome = GetCodeSourceDir(repoURL, branch, tenantID)
|
||||
rbi.CodeHome = GetCodeSourceDir(repoURL, branch, tenantID, ServiceID)
|
||||
return rbi, nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user