Compare commits

..

No commits in common. "fd71cc85c43640f576da019e92cc5fabc7ee8932" and "69a25507e805c6664865e49b182608733e22533b" have entirely different histories.

3 changed files with 12 additions and 32 deletions

View File

@ -1,7 +0,0 @@
#!/bin/bash
echo "Building the project"
cd /home/videoplayer
git pull
pwd
/home/lijun/go/bin/go build
echo "Build complete"

View File

@ -18,7 +18,6 @@ type CIDRunLog struct {
gorm.Model
CID_id int `gorm:"column:cid_id"`
Auth_id int `form:"column:auth_id"`
Script string `gorm:"column:script"`
Log string `gorm:"column:log"`
Error string `gorm:"column:error"`
}
@ -74,8 +73,8 @@ func UpdateCIDByID(id, auth_id int, name, url, script, token string) bool {
}
// CreateRunLog,添加执行日志
func CreateRunLog(cid_id, auth_id int, script, log, err string) uint {
cidRunLog := CIDRunLog{CID_id: cid_id, Auth_id: auth_id, Log: log, Error: err, Script: script}
func CreateRunLog(cid_id, auth_id int, log, err string) uint {
cidRunLog := CIDRunLog{CID_id: cid_id, Auth_id: auth_id, Log: log, Error: err}
result := DB.Debug().Create(&cidRunLog)
if result != nil {
fmt.Println(err)
@ -86,7 +85,7 @@ func CreateRunLog(cid_id, auth_id int, script, log, err string) uint {
func FindRunLogByAuthID(auth_id int) []CIDRunLog {
var cidRunLogs []CIDRunLog
DB.Debug().Where(" auth_id = ?", auth_id).Order("created_at desc").Find(&cidRunLogs)
DB.Debug().Where(" auth_id = ?", auth_id).Find(&cidRunLogs).Order("created_at desc")
return cidRunLogs
}

View File

@ -5,8 +5,8 @@ import (
"fmt"
"github.com/gin-gonic/gin"
"os/exec"
"regexp"
"strconv"
"strings"
"videoplayer/dao"
"videoplayer/proto"
)
@ -55,12 +55,9 @@ func RunCID(c *gin.Context) {
c.JSON(200, gin.H{"error": "CID not found", "code": proto.OperationFailed, "message": "failed"})
return
} else {
strs := strings.Split(cid.Url, "/")
name := strs[len(strs)-1]
names := strings.Split(name, ".")
name = names[0]
//脚本内容
re := regexp.MustCompile(`(?i)(?:https?://|git@)[^/]+/([^/]+)/([^/]+)(?:\.git)?$`)
matches := re.FindStringSubmatch(cid.Url)
name := matches[2]
scriptContent := `#!/bin/bash
TARGET_DIR = ` + proto.CID_BASE_DIR + `/workspace` + name + `
if [ ! -d $TARGET_DIR ]; then
@ -74,15 +71,11 @@ func RunCID(c *gin.Context) {
//执行脚本
cmd := exec.Command("/bin/bash", "-c", scriptContent)
err3 := cmd.Run()
err3_info := ""
if err3 != nil {
err3_info = err3.Error()
}
fmt.Println("bash content:", scriptContent)
// 使用bytes.Buffer捕获输出
var out bytes.Buffer
cmd.Stdout = &out
dao.CreateRunLog(req.ID, authID, scriptContent, out.String(), err3_info) //添加执行日志
dao.CreateRunLog(req.ID, authID, out.String(), err3.Error()) //添加执行日志
c.JSON(200, gin.H{"code": proto.SuccessCode, "message": "success", "data": "success"})
}
@ -189,10 +182,9 @@ func CIDCallback(c *gin.Context) {
res := dao.FindCIDByIDAndToken(cid, token)
if res.ID != 0 {
//从url获取仓库名称
strs := strings.Split(res.Url, "/")
name := strs[len(strs)-1]
names := strings.Split(name, ".")
name = names[0]
re := regexp.MustCompile(`(?i)(?:https?://|git@)[^/]+/([^/]+)/([^/]+)(?:\.git)?$`)
matches := re.FindStringSubmatch(res.Url)
name := matches[2]
scriptContent := `#!/bin/bash
TARGET_DIR = ` + proto.CID_BASE_DIR + `/workspace` + name + `
if [ ! -d $TARGET_DIR ]; then
@ -206,14 +198,10 @@ func CIDCallback(c *gin.Context) {
//执行脚本
cmd := exec.Command("/bin/bash", "-c", scriptContent)
err3 := cmd.Run()
err3_info := ""
if err3 != nil {
err3_info = err3.Error()
}
// 使用bytes.Buffer捕获输出
var out bytes.Buffer
cmd.Stdout = &out
dao.CreateRunLog(cid, res.Auth_id, scriptContent, out.String(), err3_info) //添加执行日志
dao.CreateRunLog(cid, res.Auth_id, out.String(), err3.Error()) //添加执行日志
c.JSON(200, gin.H{"code": proto.SuccessCode, "message": "success", "data": "success"})
} else {
c.JSON(200, gin.H{"error": "CID not found by id and token", "code": proto.OperationFailed, "message": "failed"})