|
|
@@ -1,9 +1,9 @@ |
|
|
|
package repo |
|
|
|
|
|
|
|
import ( |
|
|
|
"code.gitea.io/gitea/modules/git" |
|
|
|
"errors" |
|
|
|
"os" |
|
|
|
"os/exec" |
|
|
|
"strconv" |
|
|
|
"strings" |
|
|
|
"time" |
|
|
@@ -120,14 +120,10 @@ func CloudBrainCreate(ctx *context.Context, form auth.CreateCloudBrainForm) { |
|
|
|
uuid := form.Attachment |
|
|
|
codePath := setting.JobPath + jobName + cloudbrain.CodeMountPath |
|
|
|
repo := ctx.Repo.Repository |
|
|
|
err := downloadCode(repo, codePath) |
|
|
|
if err != nil { |
|
|
|
ctx.RenderWithErr(err.Error(), tplCloudBrainNew, &form) |
|
|
|
return |
|
|
|
} |
|
|
|
downloadCode(repo, codePath) |
|
|
|
|
|
|
|
modelPath := setting.JobPath + jobName + "/model" |
|
|
|
err = os.MkdirAll(modelPath, os.ModePerm) |
|
|
|
err := os.MkdirAll(modelPath, os.ModePerm) |
|
|
|
if err != nil { |
|
|
|
ctx.RenderWithErr(err.Error(), tplCloudBrainNew, &form) |
|
|
|
return |
|
|
@@ -243,30 +239,8 @@ func CloudBrainStop(ctx *context.Context) { |
|
|
|
} |
|
|
|
|
|
|
|
func downloadCode(repo *models.Repository, codePath string) error { |
|
|
|
/* |
|
|
|
if err := git.Clone(repo.RepoPath(), codePath, git.CloneRepoOptions{ |
|
|
|
Bare: true, |
|
|
|
Shared: true, |
|
|
|
}); err != nil { |
|
|
|
if err := git.Clone(repo.RepoPath(), codePath, git.CloneRepoOptions{}); err != nil { |
|
|
|
log.Error("Failed to clone repository: %s (%v)", repo.FullName(), err) |
|
|
|
return "", fmt.Errorf("Failed to clone repository: %s (%v)", repo.FullName(), err) |
|
|
|
} |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
err := os.MkdirAll(codePath, os.ModePerm) |
|
|
|
if err != nil { |
|
|
|
log.Error("MkdirAll failed:%v", err) |
|
|
|
return err |
|
|
|
} |
|
|
|
|
|
|
|
repoAddr := repo.CloneLink().HTTPS |
|
|
|
command := "git clone " + repoAddr[: strings.Index(repoAddr, ":") + 3] + setting.GitUser + ":" + setting.GitPassword + "@" + repoAddr[strings.Index(repoAddr, ":") + 3 :] + " " + codePath |
|
|
|
cmd := exec.Command("/bin/bash", "-c", command) |
|
|
|
output, err := cmd.Output() |
|
|
|
log.Info(string(output)) |
|
|
|
if err != nil { |
|
|
|
log.Error("exec.Command(%s) failed:%v", command, err) |
|
|
|
return err |
|
|
|
} |
|
|
|
|
|
|
|