Authored by qinchao

githookdocker

... ... @@ -10,6 +10,8 @@ import java.util.List;
* Created by craig.qin
*/
public interface DockerProjectMapper {
DockerProjectModel selectByProjectName(String projectName);
int selectCount();
List<DockerProjectModel> selectByPage(PageBean page);
... ...
... ... @@ -17,6 +17,15 @@
<result column="port" property="port" jdbcType="VARCHAR" />
</resultMap>
<select id="selectByProjectName" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from docker_project
where
projectname = #{projectName}
</select>
<sql id="Base_Column_List" >
id, projectname,projectgitgroup,projectjobtype,dockerprojectname,dockergrayclusterid,dockergraynamespace,
dockergrayimagestore,dockeronlineclusterid,dockeronlinenamespace,dockeronlineimagestore,port
... ...
... ... @@ -5,8 +5,11 @@ import com.model.DockerJenkinsRecord;
import com.model.DockerProjectModel;
import com.monitor.model.request.DockerJenkinsReq;
import com.monitor.model.response.BaseResponse;
import com.monitor.mysql.mapper.DockerProjectMapper;
import com.monitor.other.worksystem.dock.qq.DockerServerDeployService;
import com.monitor.other.worksystem.model.WebHooksReleaseBO;
import com.monitor.other.worksystem.service.DockerProjectService;
import com.offbytwo.jenkins.model.JobWithDetails;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
... ... @@ -28,6 +31,9 @@ public class DockerProjectCtrl {
@Autowired
private DockerServerDeployService dockerServerDeployService;
@Autowired
private DockerProjectMapper dockerProjectMapper;
/**
* 查询docker项目
*/
... ... @@ -71,6 +77,45 @@ public class DockerProjectCtrl {
}
/**
* 发布工单_jenkins:自动发布的项目
*/
@RequestMapping("/gitWebHook")
@ResponseBody
public BaseResponse gitWebHook(@RequestBody WebHooksReleaseBO webHooksReleaseBO) {
BaseResponse rtn=new BaseResponse<>();
if (!webHooksReleaseBO.getRef().contains("master")&&StringUtils.isBlank(webHooksReleaseBO.getProjectName())) {
rtn.setData("");
return rtn;
}
DockerProjectModel model=dockerProjectMapper.selectByProjectName(webHooksReleaseBO.getProjectName());
if (isRealChange(webHooksReleaseBO)&&model!=null) {
//Docker-Deploy-GitHook
DockerJenkinsReq dockerJenkinsReq=new DockerJenkinsReq();
dockerJenkinsReq.setDeployName(model.getProjectName());
dockerJenkinsReq.setProjectGitGroup(model.getProjectGitGroup());
dockerJenkinsReq.setDeployName(model.getDockerProjectName());
dockerJenkinsReq.setBranch("master");
dockerJenkinsReq.setUserMail(webHooksReleaseBO.getUser_email());
dockerJenkinsReq.setImageSource(model.getDockerOnlineImageStore());
dockerJenkinsReq.setNodeEnv("yoho-online");
String id=dockerProjectService.jenkinsBuild(dockerJenkinsReq);
rtn.setData(id);
}
return rtn;
}
public Boolean isRealChange(WebHooksReleaseBO webHooksReleaseBO) {
boolean object_kind_check = webHooksReleaseBO.getObject_kind().equals("push");
boolean ref_check = webHooksReleaseBO.getRef().equals("refs/heads/master");
boolean total_commits_count_check = webHooksReleaseBO.getTotal_commits_count() > 0;
return object_kind_check && ref_check && total_commits_count_check;
}
/**
* 发布工单_jenkins:更新镜像的状态
*/
@RequestMapping("/updateJenkinsStatus")
... ...
package com.monitor.other.worksystem.model;
import java.util.Set;
/**
* Created by jimi on 2017/9/18.
*/
public class WebHooksReleaseBO {
private String object_kind;
private String ref;
private Integer total_commits_count;
private Set<String> changFileForDockerFile;
private String projectName ;
private String projectNameSpace ;
private String gitUrl;
private String user_name;
private String user_email;
public String getUser_email() {
return user_email;
}
public void setUser_email(String user_email) {
this.user_email = user_email;
}
public String getUser_name() {
return user_name;
}
public void setUser_name(String user_name) {
this.user_name = user_name;
}
public String getGitUrl() {
return gitUrl;
}
public void setGitUrl(String gitUrl) {
this.gitUrl = gitUrl;
}
public String getProjectName() {
return projectName;
}
public void setProjectName(String projectName) {
this.projectName = projectName;
}
public String getProjectNameSpace() {
return projectNameSpace;
}
public void setProjectNameSpace(String projectNameSpace) {
this.projectNameSpace = projectNameSpace;
}
public String getObject_kind() {
return object_kind;
}
public void setObject_kind(String object_kind) {
this.object_kind = object_kind;
}
public String getRef() {
return ref;
}
public void setRef(String ref) {
this.ref = ref;
}
public Integer getTotal_commits_count() {
return total_commits_count;
}
public void setTotal_commits_count(Integer total_commits_count) {
this.total_commits_count = total_commits_count;
}
public Set<String> getChangFileForDockerFile() {
return changFileForDockerFile;
}
public void setChangFileForDockerFile(Set<String> changFileForDockerFile) {
this.changFileForDockerFile = changFileForDockerFile;
}
}
... ...
... ... @@ -56,7 +56,6 @@ public class DockerProjectServiceImpl implements DockerProjectService {
params.put("ticketID", uuid);
params.put("projectName",dockerJenkinsReq.getProjectName());
params.put("projectGitGroup",dockerJenkinsReq.getProjectGitGroup());
params.put("projectGitGroup",dockerJenkinsReq.getProjectGitGroup());
params.put("deployName",deployName);
params.put("branch",dockerJenkinsReq.getBranch());
params.put("nodeEnv",dockerJenkinsReq.getNodeEnv());
... ...