Authored by qinchao

docker 发布支持镜像

... ... @@ -419,4 +419,5 @@ public class HttpUriContants {
public static final String ADDORUPDATE_DOCKER_INFO = "/dockerProject/addOrUpdateDockerInfo";
public static final String GET_DOCERK_INFO_BY_ID = "/dockerProject/getDockerInfoById";
public static final String DEL_DOCKER_INFO_BYID = "/dockerProject/delDockerInfoById";
public static final String DOCKER_DEPLOY_ROLLBACK_BY_IMAGE="/dockerProject/deployByImageStore";
}
\ No newline at end of file
... ...
... ... @@ -27,6 +27,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
@RestController
... ... @@ -81,6 +82,8 @@ public class DockerBuildCtrl {
model.addAttribute("releaseWorkJob_projectDeployType", map.get("projectDeployType")==null?"":(String)map.get("projectDeployType"));
model.addAttribute("releaseWorkJob_branch", map.get("branch")==null?"":(String)map.get("branch"));
model.addAttribute("releaseWorkJob_imageFile", map.get("imageFile")==null?"":(String)map.get("imageFile"));
model.addAttribute("releaseWorkJob_uploadCDN", map.get("uploadCDN")==null?"":String.valueOf(map.get("uploadCDN")));
model.addAttribute("releaseWorkJob_cdnBranch", map.get("cdnBranch")==null?"":String.valueOf(map.get("cdnBranch")));
model.addAttribute("releaseWorkJob_project",releaseWorkJob_project);
model.addAttribute("releaseWorkJob_id", workJobId);
}
... ... @@ -103,7 +106,7 @@ public class DockerBuildCtrl {
BaseResponse response=httpRestClient.defaultGet("/dockerProject/getDockerProjectMapByIds", BaseResponse.class, mapIds);
Map projectMap=JSON.parseObject((String)response.getData(),Map.class);
if("deploy".equalsIgnoreCase(operate_name)){
if("deploy".equalsIgnoreCase(operate_name)&&"git".equals(project_deploy_type)){
for(String buildIdWithProjectId:buildIds.split(",")){
int index = buildIdWithProjectId.indexOf("-");
String projectId=buildIdWithProjectId.substring(0,index);
... ... @@ -116,6 +119,7 @@ public class DockerBuildCtrl {
buildInfoList.add(map);
}
}else{
//回滚 或者 镜像文件发布
String projectId=project_id;
Map map=new HashMap();
map.put("projectId",projectId);
... ... @@ -136,6 +140,7 @@ public class DockerBuildCtrl {
model.addAttribute("clusters_text", clusters_text);
model.addAttribute("operate_name", operate_name);
model.addAttribute("branch_name", branch_name);
model.addAttribute("project_deploy_type", project_deploy_type);
model.addAttribute("image_file_name", image_file_name);
model.addAttribute("workid_name", workid_name);
model.addAttribute("rollbackfile_name", rollbackImageStore);
... ... @@ -251,13 +256,13 @@ public class DockerBuildCtrl {
**/
@RequestMapping(value = "/rollback")
@ResponseBody
public BaseResponse rollback(String project_id, String environment_name, String clusters_name,String rollbackImageStore){
public BaseResponse deployByImageStore(String project_id, String environment_name, String clusters_name,String rollbackImageStore){
Map<String, String> map = new HashMap<>();
map.put("projectId", project_id);
map.put("environment", environment_name);
map.put("clusters_name", clusters_name);
map.put("rollbackImageStore", rollbackImageStore);
return httpRestClient.defaultGet("/dockerProject/rollback", BaseResponse.class, map);
return httpRestClient.defaultGet(HttpUriContants.DOCKER_DEPLOY_ROLLBACK_BY_IMAGE, BaseResponse.class, map);
}
/**
... ... @@ -268,12 +273,32 @@ public class DockerBuildCtrl {
@RequestMapping(value = "/mirrorAndDeploy")
@ResponseBody
public BaseResponse mirrorAndDeploy(String project_id, String project_name,
String environment_name,String clusters_name, String operate_name,String project_deploy_type, String branch_name,String image_file_name,
String rollbackfile_name,String workid_name, Model model, HttpSession session) {
DockerJenkinsReq dockerJenkinsReq=new DockerJenkinsReq();
String environment_name,String clusters_name, String operate_name,String project_deploy_type,
String branch_name,String image_file_name,
String rollbackfile_name,String workid_name,int uploadCDN,String cdnBranch, Model model, HttpSession session) {
User user = (User) session.getAttribute("user");
dockerJenkinsReq.setUserName(user.getName());
dockerJenkinsReq.setUserMail(user.getEmail());
String userName=user.getName();
String userEmail=user.getEmail();
if("image".equals(project_deploy_type)){
if(1==uploadCDN){
//发布异步任务
CompletableFuture.runAsync(new Runnable() {
@Override
public void run() {
Map<String,String> param=new HashMap<>();
param.put("projectId",project_id);
param.put("cdnBranch",cdnBranch);
param.put("workid_name",workid_name);
param.put("operatorEmail",userEmail);
httpRestClient.defaultGet("/dockerProject/uploadCDN",BaseResponse.class,param);
}
});
}
return deployByImageStore(project_id,environment_name,clusters_name,image_file_name);
}
DockerJenkinsReq dockerJenkinsReq=new DockerJenkinsReq();
dockerJenkinsReq.setUserName(userName);
dockerJenkinsReq.setUserMail(userEmail);
dockerJenkinsReq.setProjectIds(project_id);
dockerJenkinsReq.setNodeEnv(environment_name);
dockerJenkinsReq.setClusterId(clusters_name);
... ...
... ... @@ -179,7 +179,8 @@
var buildInfoList = '${buildInfoList}';
$(function () {
if("${operate_name}".toUpperCase()=="DEPLOY"){
console.log("project_deploy_type is "+"${project_deploy_type}");
if("${operate_name}".toUpperCase()=="DEPLOY"&&"git"=="${project_deploy_type}"){
if(buildInfoList!=null&&buildInfoList.length>0){
var buildInfoListJson=JSON.parse(buildInfoList);
//docek发布
... ... @@ -188,6 +189,7 @@
}
}
}else{
//回滚或者镜像发布
if(buildInfoList!=null&&buildInfoList.length>0){
var buildInfoListJson=JSON.parse(buildInfoList);
//docek回滚
... ...
... ... @@ -144,6 +144,20 @@
</div>
</div>
<div class="form-group" id="uploadCDN_div" class="deploy_type_div_class" style="display: none">
<label class="col-sm-1 control-label">上传CDN</label>
<div class="col-sm-1" style="width: 110px;">
<select id="uploadCDN" name="uploadCDN" class="form-control" style="width: 100px;height:40px">
<option value="0" <c:if test="${releaseWorkJob_uploadCDN == '0' }">selected</c:if> >否</option>
<option value="1" <c:if test="${releaseWorkJob_uploadCDN == '1' }">selected</c:if> >是</option>
</select>
</div>
<div class="col-sm-7" style="width: 200px;">
<input id="cdnBranch" name="cdnBranch" type="text" value="${releaseWorkJob_cdnBranch}" class="form-control" style="padding-left:10px;float:left" placeHolder="上传cdn的分支"/>
</div>
</div>
<div class="form-group" id="rollback-div" style="display: none">
<label class="col-sm-1 control-label">回滚版本选择</label>
... ... @@ -304,12 +318,15 @@
function deployTypeOnchange(val) {
$(".deploy_type_div_class").hide();
$("#"+val+"_deploy_type_div").show();
if("${releaseWorkJob_id}".length>0){
$("#projectDeployType").prop("disabled", true);
return ;
}
if(val=="image"){
$("#uploadCDN_div").show();
if("${releaseWorkJob_id}".length>0){
$("#projectDeployType").prop("disabled", true);
return ;
}
$("#imagesList").select2("val", "");
$('#imagesList').select2().empty();
//加载项目的镜像
... ... @@ -341,6 +358,10 @@
data: list
});
}
}else{
//$("#uploadCDN").val(0);
$("#uploadCDN_div").hide();//隐藏当前区域
}
}
... ... @@ -664,6 +685,8 @@
var branch = $("input[name='branch']").val();
var imageFile=$("#imagesList").val();
var uploadCDN = $("#uploadCDN").val();
var cdnBranch = $("#cdnBranch").val();
if(projectDeployType=="image"){
$("#comfirm_deploy_content_div_image").show();
branch="";
... ... @@ -671,6 +694,12 @@
alert("请填写镜像文件");
return;
}
if(uploadCDN==1){
if(!cdnBranch){
alert("请填写上传CDN分支");
return;
}
}
}else if(projectDeployType=="git"){
$("#comfirm_deploy_content_div_git").show();
if (!branch) {
... ... @@ -831,7 +860,9 @@
param.workid_name=$("input[name='workid_name']").val();
param.clusters_name=$("input[name='clusters_name']").val();
param.clusters_text=$("input[name='clusters_text']").val();
param.uploadCDN = $("#uploadCDN").val();
param.cdnBranch = $("#cdnBranch").val();
console.log(param);
//三个node项目发布灰度环境时,自动启用灰度,发布online环境时,自动关闭灰度
param.az2AutoSwitchOnlineCheck="";
if("yohoblk-wap"==param.project_name||"yohobuywap-node"==param.project_name||"yohobuy-node"==param.project_name){
... ...