提交 377a4bcd authored 作者: chenshiying's avatar chenshiying

[新增] 部署脚本更新

上级 1050f2b9
......@@ -37,3 +37,4 @@ build/
**/src/main/resources/bin/server/**
**/src/main/resources/bin/jenkins/**
**/src/main/resources/bin/jenkinsGit/**
package com.loit.common.script;
import com.loit.common.script.dto.BackendFrontEnum;
import com.loit.common.script.dto.DeployInfoDataDTO;
import com.loit.common.script.dto.FrontGroupEnum;
import com.loit.common.script.dto.FrontInstanceDto;
import com.loit.common.utils.ListUtil;
import com.loit.common.utils.StringUtils;
import com.loit.common.utils.excel.ImportExcel;
import com.loit.common.utils.file.FileUtils;
import com.loit.common.utils.freemarker.FreeMarkerUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.entity.ContentType;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@Slf4j
public class GeneratorGitJobScript {
protected static String root_path = "F:\\9Git140\\loit-build-common\\loit-build-component\\loit-build-deploy-env\\src\\main\\resources\\bin";
protected static String root_path_jenkins_full = root_path + "\\jenkinsGit";
private static Map<String, FrontInstanceDto> frontInstanceDtoMap = new LinkedHashMap<>();
public static void main(String[] args) {
try {
String filePathStr = "F:\\9Git140\\loit-build-common\\loit-build-component\\loit-build-deploy-env\\src\\main\\resources\\deployInfo.xlsx";
File pdfFile = new File(filePathStr);
FileInputStream fileInputStream = new FileInputStream(pdfFile);
MultipartFile multipartFile = new MockMultipartFile(pdfFile.getName(), pdfFile.getName(),
ContentType.APPLICATION_OCTET_STREAM.toString(), fileInputStream);
ImportExcel ei = new ImportExcel(multipartFile, 1, 0);
List<DeployInfoDataDTO> grayVersionDataDTOList = ei.getDataList(DeployInfoDataDTO.class);
if (ListUtil.isEmpty(grayVersionDataDTOList)) {
return;
}
//对前端实例进行分组
for (DeployInfoDataDTO deployDataDTO : grayVersionDataDTOList) {
BackendFrontEnum backendFrontType = BackendFrontEnum.getEnumByCode(deployDataDTO.getBackendFrontType());
if (BackendFrontEnum.BACKEND.equals(backendFrontType)) {
continue;
}
String serviceName = deployDataDTO.getServiceName();
FrontInstanceDto frontInstanceDto = frontInstanceDtoMap.get(serviceName);
if (frontInstanceDto == null) {
frontInstanceDto = new FrontInstanceDto();
String serviceNameSub = "loit-" + serviceName.replace("-web", "").replace("-h5", "");
String serviceNameCookie = "loit" + serviceName.replaceAll("-", "");
frontInstanceDto.setServiceName(serviceName);
frontInstanceDto.setServiceNameSub(serviceNameSub);
frontInstanceDto.setServiceNameCookie(serviceNameCookie);
frontInstanceDto.setServiceNameAbb(deployDataDTO.getServiceNameAbb());
frontInstanceDtoMap.put(serviceName, frontInstanceDto);
}
FrontGroupEnum frontGroup = FrontGroupEnum.getEnumByCode(deployDataDTO.getFrontGroup());
String ipAndPort = deployDataDTO.getFixedIp() + ":" + deployDataDTO.getPort();
if (FrontGroupEnum.gray.equals(frontGroup)) {
frontInstanceDto.getGrayList().add(ipAndPort);
}
if (FrontGroupEnum.normal.equals(frontGroup)) {
frontInstanceDto.getNormalList().add(ipAndPort);
}
}
//生成前端nginx 配置文件
frontInstanceDtoMap.forEach((key, frontInstanceDto) -> {
if (StringUtils.isBlank(key)) {
return;
}
// Map model = new HashMap();
// model.put("serviceNameSub", frontInstanceDto.getServiceNameSub());
// model.put("serviceNameCookie", frontInstanceDto.getServiceNameCookie());
// model.put("serviceName", frontInstanceDto.getServiceName());
// model.put("serviceNameAbb", frontInstanceDto.getServiceNameAbb());
// model.put("grayList", frontInstanceDto.getGrayList());
// model.put("normalList", frontInstanceDto.getNormalList());
buildInitEnv(frontInstanceDto);
});
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}
/**
* 生成InitEnv
*
* @throws IOException
*/
private static void buildInitEnv(FrontInstanceDto frontInstanceDto) {
String fileDir = root_path_jenkins_full;
File folder = new File(fileDir);
if (!folder.exists()) {
folder.mkdirs();
}
String serviceName = frontInstanceDto.getServiceName();
if (StringUtils.isBlank(serviceName)) {
return;
}
String createJobFile = root_path_jenkins_full + "\\createJob.txt";
String jenkinsJobName = createJenkinsJobName(serviceName);
Map model = new HashMap();
model.put("deployJobName", jenkinsJobName);
model.put("serviceName", serviceName);
String result = FreeMarkerUtils.process("jenkinsJobCreate.ftl", model);
FileUtils.appendNewLine(createJobFile, result);
String jobsDir = root_path_jenkins_full + "\\" + jenkinsJobName;
File jobsFolder = new File(jobsDir);
if (!jobsFolder.exists()) {
jobsFolder.mkdirs();
}
String configFilePath = jobsDir + "\\config.xml";
String jobConfig = FreeMarkerUtils.process("jenkinsJobGit.ftl", model);
FileUtils.appendNewLine(configFilePath, jobConfig);
}
private static String createJenkinsJobName(String serviceName) {
if ("getway".equals(serviceName)) {
serviceName = "gateway";
}
String jenkinsJobName = "loit-git-branch-" + serviceName + "-module-build";
return jenkinsJobName;
}
}
......@@ -73,13 +73,14 @@ public class DeployInfoDataDTO implements Serializable {
@ExcelField(title = "模块ID", sort = 14)
private String modelId;
public String getModelId() {
return modelId;
}
@ApiModelProperty(value = "git地址")
@ExcelField(title = "git地址", sort = 15)
private String gitPath;
public void setModelId(String modelId) {
this.modelId = modelId;
}
@ApiModelProperty(value = "git构建jar路径")
@ExcelField(title = "git构建jar路径", sort = 16)
private String gitBuildSub;
public String getFixedIp() {
return fixedIp;
......@@ -177,8 +178,6 @@ public class DeployInfoDataDTO implements Serializable {
this.needCreateInstanceSql = needCreateInstanceSql;
}
public String getNacosServiceName() {
return nacosServiceName;
}
......@@ -187,4 +186,28 @@ public class DeployInfoDataDTO implements Serializable {
this.nacosServiceName = nacosServiceName;
}
public String getModelId() {
return modelId;
}
public void setModelId(String modelId) {
this.modelId = modelId;
}
public String getGitPath() {
return gitPath;
}
public void setGitPath(String gitPath) {
this.gitPath = gitPath;
}
public String getGitBuildSub() {
return gitBuildSub;
}
public void setGitBuildSub(String gitBuildSub) {
this.gitBuildSub = gitBuildSub;
}
}
......@@ -54,7 +54,7 @@
</userRemoteConfigs>
<branches>
<hudson.plugins.git.BranchSpec>
<name>${branch}</name>
<name>${r"${"}branch}</name>
</hudson.plugins.git.BranchSpec>
</branches>
<doGenerateSubmoduleConfigurations>false</doGenerateSubmoduleConfigurations>
......@@ -93,7 +93,7 @@
echo &quot;##################create remore dist begin#############&quot;
destDir=&quot;/home/version/push-jar/${projectCode}/${modelServiceName}/${modelVersion}&quot;
destDir=&quot;/home/version/push-jar/${r"${"}projectCode}/${r"${"}modelServiceName}/${r"${"}modelVersion}&quot;
echo &apos;please check destDir is include projectCode、modelServiceName、modelVersion:&apos; + $destDir
if [ -z &quot;$projectCode&quot; ]; then
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论