mirror of
https://gitee.com/rainbond/Rainbond.git
synced 2024-12-02 11:47:36 +08:00
[REV] optimize code check update method
This commit is contained in:
parent
ec4e7fb6cf
commit
ef0487a832
@ -19,6 +19,7 @@ import fileinput
|
||||
from utils.shell import Executer as shell
|
||||
from utils.docker import DockerfileItem
|
||||
from clients.region import RegionAPI
|
||||
from clients.region_api import RegionBackAPI
|
||||
from clients.acp_api import ACPAPI
|
||||
from clients.userconsole import UserConsoleAPI
|
||||
|
||||
@ -56,6 +57,7 @@ class RepoBuilder():
|
||||
self.api = ACPAPI(conf=self.configs['region'])
|
||||
self.user_cs_client = UserConsoleAPI(conf=self.configs['userconsole'])
|
||||
self.repo_url = task['repo_url']
|
||||
self.region_client = RegionBackAPI()
|
||||
self.tenant_id = task['tenant_id']
|
||||
self.service_id = task['service_id']
|
||||
self.tenant_name = task['tenant_name']
|
||||
@ -186,17 +188,17 @@ class RepoBuilder():
|
||||
entrypoint_cmd = ' '.join(entrypoint)
|
||||
shell.call(
|
||||
'''sed -i -e 's#_type_#ENTRYPOINT#' -e 's#^_entrypoint_#'{0}'#' .goodrain/init'''.
|
||||
format(pipes.quote(entrypoint_cmd)),
|
||||
format(pipes.quote(entrypoint_cmd)),
|
||||
cwd=self.source_dir)
|
||||
if cmd is not None:
|
||||
shell.call(
|
||||
'''sed -i -e 's#^_cmd_#'{0}'#' .goodrain/init'''.
|
||||
format(pipes.quote(cmd)),
|
||||
format(pipes.quote(cmd)),
|
||||
cwd=self.source_dir)
|
||||
else:
|
||||
shell.call(
|
||||
'''sed -i -e 's#_type_#CMD#' -e 's#^_cmd_#'{0}'#' .goodrain/init'''.
|
||||
format(pipes.quote(cmd)),
|
||||
format(pipes.quote(cmd)),
|
||||
cwd=self.source_dir)
|
||||
return True
|
||||
except (shell.ExecException, OSError), e:
|
||||
@ -231,9 +233,9 @@ class RepoBuilder():
|
||||
inner_port = inner_port.replace('"', '')
|
||||
|
||||
return {
|
||||
"inner_port": inner_port,
|
||||
"volume_mount_path": volume_mount_path
|
||||
}, entrypoint, cmd
|
||||
"inner_port": inner_port,
|
||||
"volume_mount_path": volume_mount_path
|
||||
}, entrypoint, cmd
|
||||
|
||||
def build_image(self):
|
||||
# self.write_build_log(u"开始编译Dockerfile")
|
||||
@ -322,7 +324,7 @@ class RepoBuilder():
|
||||
h = self.user_cs_client
|
||||
try:
|
||||
h.update_service(self.service_id, json.dumps(update_items))
|
||||
update_service_region(self,self.service_id,json.dumps(update_items))
|
||||
self.region_client.update_service_region(self.service_id,json.dumps(update_items))
|
||||
except h.CallApiError, e:
|
||||
self.log.error(
|
||||
"网络异常,更新应用镜像名称失败. {}".format(e.message),
|
||||
|
@ -28,3 +28,8 @@ class RegionBackAPI(BaseHttpClient):
|
||||
print body
|
||||
res, body = self._post(url, self.default_headers, body)
|
||||
return res, body
|
||||
|
||||
|
||||
def update_service_region(self, service_id, body):
|
||||
url = self.base_url+'/codecheck/{0}'.format(service_id)
|
||||
res, body = self._put(url, self.default_headers, body)
|
@ -40,6 +40,11 @@ func AddCodeCheck(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
b,_:=ioutil.ReadAll(r.Body)
|
||||
j,err:=simplejson.NewJson(b)
|
||||
if err != nil {
|
||||
logrus.Errorf("error decode json,details %s",err.Error())
|
||||
httputil.ReturnError(r,w,400,"bad request")
|
||||
return
|
||||
}
|
||||
result.URLRepos,_=j.Get("url_repos").String()
|
||||
result.CheckType,_=j.Get("check_type").String()
|
||||
result.CodeFrom,_=j.Get("code_from").String()
|
||||
@ -51,11 +56,7 @@ func AddCodeCheck(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
defer r.Body.Close()
|
||||
|
||||
if err != nil {
|
||||
logrus.Errorf("error decode json,details %s",err.Error())
|
||||
httputil.ReturnError(r,w,400,"bad request")
|
||||
return
|
||||
}
|
||||
|
||||
dbmodel:=convertModelToDB(result)
|
||||
//checkAndGet
|
||||
db.GetManager().CodeCheckResultDao().AddModel(dbmodel)
|
||||
@ -64,14 +65,31 @@ func AddCodeCheck(w http.ResponseWriter, r *http.Request) {
|
||||
func Update(w http.ResponseWriter, r *http.Request) {
|
||||
serviceID := strings.TrimSpace(chi.URLParam(r, "serviceID"))
|
||||
result := new(model.CodeCheckResult)
|
||||
decoder := json.NewDecoder(r.Body)
|
||||
|
||||
b,_:=ioutil.ReadAll(r.Body)
|
||||
defer r.Body.Close()
|
||||
err := decoder.Decode(result)
|
||||
logrus.Infof("update receive %s",string(b))
|
||||
j,err:=simplejson.NewJson(b)
|
||||
if err != nil {
|
||||
logrus.Errorf("error decode json,details %s",err.Error())
|
||||
httputil.ReturnError(r,w,400,"bad request")
|
||||
return
|
||||
}
|
||||
result.BuildImageName,_=j.Get("image").String()
|
||||
portList,err:=j.Get("port_list").Map()
|
||||
if err != nil {
|
||||
portList=make(map[string]interface{})
|
||||
}
|
||||
volumeList,err:=j.Get("volume_list").StringArray()
|
||||
if err != nil {
|
||||
volumeList=nil
|
||||
}
|
||||
strMap:=make(map[string]string)
|
||||
for k,v:=range portList {
|
||||
strMap[k]=v.(string)
|
||||
}
|
||||
result.VolumeList=volumeList
|
||||
result.PortList=strMap
|
||||
result.ServiceID=serviceID
|
||||
dbmodel:=convertModelToDB(result)
|
||||
dbmodel.DockerFileReady=true
|
||||
|
Loading…
Reference in New Issue
Block a user