From 532d3c5c35e92d80c26c2b8e0786595fc89cca04 Mon Sep 17 00:00:00 2001 From: yuyuanshifu <747342561@qq.com> Date: Wed, 30 Dec 2020 10:58:52 +0800 Subject: [PATCH 01/13] benchmark --- modules/cloudbrain/cloudbrain.go | 10 +++++++++- modules/setting/setting.go | 2 ++ routers/repo/cloudbrain.go | 27 +++++++++++++++++++++++++-- templates/repo/cloudbrain/new.tmpl | 4 ++++ 4 files changed, 40 insertions(+), 3 deletions(-) diff --git a/modules/cloudbrain/cloudbrain.go b/modules/cloudbrain/cloudbrain.go index 52057f0b8..394b29432 100755 --- a/modules/cloudbrain/cloudbrain.go +++ b/modules/cloudbrain/cloudbrain.go @@ -14,13 +14,14 @@ const ( CodeMountPath = "/code" DataSetMountPath = "/dataset" ModelMountPath = "/model" + BenchMarkMountPath = "/benchmark" SubTaskName = "task1" Success = "S000" ) -func GenerateTask(ctx *context.Context, jobName, image, command, uuid, codePath, modelPath string) error { +func GenerateTask(ctx *context.Context, jobName, image, command, uuid, codePath, modelPath, benchmarkPath string) error { dataActualPath := setting.Attachment.Minio.RealPath + setting.Attachment.Minio.Bucket + "/" + setting.Attachment.Minio.BasePath + @@ -69,6 +70,13 @@ func GenerateTask(ctx *context.Context, jobName, image, command, uuid, codePath, ReadOnly: false, }, }, + { + HostPath: models.StHostPath{ + Path: benchmarkPath, + MountPath: BenchMarkMountPath, + ReadOnly: true, + }, + }, }, }) if err != nil { diff --git a/modules/setting/setting.go b/modules/setting/setting.go index 3fa6403a1..cea5b2316 100755 --- a/modules/setting/setting.go +++ b/modules/setting/setting.go @@ -438,6 +438,7 @@ var ( JobPath string JobType string DebugServerHost string + BenchmarkCode string ) // DateLang transforms standard language locale name to corresponding value in datetime plugin. @@ -1113,6 +1114,7 @@ func NewContext() { JobPath = sec.Key("JOB_PATH").MustString("/datasets/minio/data/opendata/jobs/") DebugServerHost = sec.Key("DEBUG_SERVER_HOST").MustString("http://192.168.202.73") JobType = sec.Key("JOB_TYPE").MustString("debug_openi") + BenchmarkCode = sec.Key("BENCHMARKCODE").MustString("https://yangzhx:justfortest123@git.openi.org.cn/yangzhx/detection_benchmark_script.git") } func loadInternalToken(sec *ini.Section) string { diff --git a/routers/repo/cloudbrain.go b/routers/repo/cloudbrain.go index 389f86b24..d51d6d7d7 100755 --- a/routers/repo/cloudbrain.go +++ b/routers/repo/cloudbrain.go @@ -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 +} diff --git a/templates/repo/cloudbrain/new.tmpl b/templates/repo/cloudbrain/new.tmpl index 7714bae3d..a94bf1fe2 100755 --- a/templates/repo/cloudbrain/new.tmpl +++ b/templates/repo/cloudbrain/new.tmpl @@ -148,6 +148,10 @@ +
+ + +