|
|
@@ -2,6 +2,7 @@ package repo |
|
|
|
|
|
|
|
import ( |
|
|
|
"code.gitea.io/gitea/modules/git" |
|
|
|
"encoding/json" |
|
|
|
"errors" |
|
|
|
"os" |
|
|
|
"os/exec" |
|
|
@@ -132,7 +133,7 @@ func CloudBrainCreate(ctx *context.Context, form auth.CreateCloudBrainForm) { |
|
|
|
} |
|
|
|
|
|
|
|
benchmarkPath := setting.JobPath + jobName + cloudbrain.BenchMarkMountPath |
|
|
|
downloadBenchmarkCode(benchmarkPath) |
|
|
|
downloadBenchmarkCode(repo, jobName, benchmarkPath) |
|
|
|
|
|
|
|
err = cloudbrain.GenerateTask(ctx, jobName, image, command, uuid, codePath, modelPath, benchmarkPath) |
|
|
|
if err != nil { |
|
|
@@ -261,7 +262,7 @@ func downloadCode(repo *models.Repository, codePath string) error { |
|
|
|
return nil |
|
|
|
} |
|
|
|
|
|
|
|
func downloadBenchmarkCode(benchmarkPath string) error { |
|
|
|
func downloadBenchmarkCode(repo *models.Repository, taskName string, benchmarkPath string) error { |
|
|
|
err := os.MkdirAll(benchmarkPath, os.ModePerm) |
|
|
|
if err != nil { |
|
|
|
log.Error("mkdir benchmarkPath failed", err.Error()) |
|
|
@@ -277,6 +278,30 @@ func downloadBenchmarkCode(benchmarkPath string) error { |
|
|
|
return err |
|
|
|
} |
|
|
|
|
|
|
|
//todo: write sth into a config file |
|
|
|
fileName := benchmarkPath + cloudbrain.TaskInfoName |
|
|
|
f, err := os.OpenFile(fileName, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, os.ModePerm) |
|
|
|
if err != nil { |
|
|
|
log.Error("OpenFile failed", err.Error()) |
|
|
|
return err |
|
|
|
} |
|
|
|
|
|
|
|
defer f.Close() |
|
|
|
|
|
|
|
data, err := json.Marshal(models.TaskInfo{ |
|
|
|
Username: repo.Owner.Name, |
|
|
|
TaskName: taskName, |
|
|
|
CodeName: repo.Name, |
|
|
|
}) |
|
|
|
if err != nil { |
|
|
|
log.Error("json.Marshal failed", err.Error()) |
|
|
|
return err |
|
|
|
} |
|
|
|
|
|
|
|
_, err = f.Write(data) |
|
|
|
if err != nil { |
|
|
|
log.Error("WriteString failed", err.Error()) |
|
|
|
return err |
|
|
|
} |
|
|
|
|
|
|
|
return nil |
|
|
|
} |