|
|
|
@@ -4,6 +4,7 @@ import ( |
|
|
|
"code.gitea.io/gitea/modules/git" |
|
|
|
"errors" |
|
|
|
"os" |
|
|
|
"os/exec" |
|
|
|
"strconv" |
|
|
|
"strings" |
|
|
|
"time" |
|
|
|
@@ -109,6 +110,7 @@ func CloudBrainNew(ctx *context.Context) { |
|
|
|
ctx.Data["code_path"] = cloudbrain.CodeMountPath |
|
|
|
ctx.Data["dataset_path"] = cloudbrain.DataSetMountPath |
|
|
|
ctx.Data["model_path"] = cloudbrain.ModelMountPath |
|
|
|
ctx.Data["benchmark_path"] = cloudbrain.BenchMarkMountPath |
|
|
|
ctx.HTML(200, tplCloudBrainNew) |
|
|
|
} |
|
|
|
|
|
|
|
@@ -122,14 +124,17 @@ func CloudBrainCreate(ctx *context.Context, form auth.CreateCloudBrainForm) { |
|
|
|
repo := ctx.Repo.Repository |
|
|
|
downloadCode(repo, codePath) |
|
|
|
|
|
|
|
modelPath := setting.JobPath + jobName + "/model" |
|
|
|
modelPath := setting.JobPath + jobName + cloudbrain.ModelMountPath |
|
|
|
err := os.MkdirAll(modelPath, os.ModePerm) |
|
|
|
if err != nil { |
|
|
|
ctx.RenderWithErr(err.Error(), tplCloudBrainNew, &form) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
err = cloudbrain.GenerateTask(ctx, jobName, image, command, uuid, codePath, modelPath) |
|
|
|
benchmarkPath := setting.JobPath + jobName + cloudbrain.BenchMarkMountPath |
|
|
|
downloadBenchmarkCode(benchmarkPath) |
|
|
|
|
|
|
|
err = cloudbrain.GenerateTask(ctx, jobName, image, command, uuid, codePath, modelPath, benchmarkPath) |
|
|
|
if err != nil { |
|
|
|
ctx.RenderWithErr(err.Error(), tplCloudBrainNew, &form) |
|
|
|
return |
|
|
|
@@ -255,3 +260,21 @@ func downloadCode(repo *models.Repository, codePath string) error { |
|
|
|
|
|
|
|
return nil |
|
|
|
} |
|
|
|
|
|
|
|
func downloadBenchmarkCode(benchmarkPath string) error { |
|
|
|
err := os.MkdirAll(benchmarkPath, os.ModePerm) |
|
|
|
if err != nil { |
|
|
|
log.Error("mkdir benchmarkPath failed", err.Error()) |
|
|
|
return err |
|
|
|
} |
|
|
|
|
|
|
|
command := "git clone " + setting.BenchmarkCode + " " + benchmarkPath |
|
|
|
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 |
|
|
|
} |
|
|
|
return nil |
|
|
|
} |