From 8b82b1f15182c8890da277a67c5ec364e7f32fc8 Mon Sep 17 00:00:00 2001 From: yuyuanshifu <747342561@qq.com> Date: Thu, 17 Dec 2020 11:15:58 +0800 Subject: [PATCH] optimization --- custom/conf/app.ini.sample | 2 -- modules/setting/setting.go | 4 ---- routers/repo/cloudbrain.go | 34 ++++------------------------------ 3 files changed, 4 insertions(+), 36 deletions(-) diff --git a/custom/conf/app.ini.sample b/custom/conf/app.ini.sample index 1a7ada50d..c469fee7b 100755 --- a/custom/conf/app.ini.sample +++ b/custom/conf/app.ini.sample @@ -1055,8 +1055,6 @@ DEBUG_SERVER_HOST = http://192.168.202.73/ USER = cW4cMtH24eoWPE7X PWD = 4BPmgvK2hb2Eywwyp4YZRY4B7yQf4DA.C JOB_TYPE = debug_openi -GIT_USER = opendata -GIT_PASSWORD = pa%40123456 [decompress] HOST = http://192.168.207.34:39987 diff --git a/modules/setting/setting.go b/modules/setting/setting.go index cbeeeaf5f..3fa6403a1 100755 --- a/modules/setting/setting.go +++ b/modules/setting/setting.go @@ -438,8 +438,6 @@ var ( JobPath string JobType string DebugServerHost string - GitUser string - GitPassword string ) // DateLang transforms standard language locale name to corresponding value in datetime plugin. @@ -1115,8 +1113,6 @@ 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") - GitUser = sec.Key("GIT_USER").MustString("opendata") - GitPassword = sec.Key("GIT_PASSWORD").MustString("pa%40123456") } func loadInternalToken(sec *ini.Section) string { diff --git a/routers/repo/cloudbrain.go b/routers/repo/cloudbrain.go index 881202197..29ef3fe6c 100755 --- a/routers/repo/cloudbrain.go +++ b/routers/repo/cloudbrain.go @@ -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 }