Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
L
loit-build-common
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
loit-Infrastructure
loit-build-common
Commits
377a4bcd
提交
377a4bcd
authored
5月 28, 2021
作者:
chenshiying
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[新增] 部署脚本更新
上级
1050f2b9
隐藏空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
198 行增加
和
10 行删除
+198
-10
.gitignore
.gitignore
+1
-0
GeneratorGitJobScript.java
...in/java/com/loit/common/script/GeneratorGitJobScript.java
+164
-0
DeployInfoDataDTO.java
...in/java/com/loit/common/script/dto/DeployInfoDataDTO.java
+31
-8
deployInfo.xlsx
.../loit-build-deploy-env/src/main/resources/deployInfo.xlsx
+0
-0
deployInfo1.xlsx
...loit-build-deploy-env/src/main/resources/deployInfo1.xlsx
+0
-0
jenkinsJobGit.ftl
...-deploy-env/src/main/resources/template/jenkinsJobGit.ftl
+2
-2
没有找到文件。
.gitignore
浏览文件 @
377a4bcd
...
...
@@ -37,3 +37,4 @@ build/
**/src/main/resources/bin/server/**
**/src/main/resources/bin/jenkins/**
**/src/main/resources/bin/jenkinsGit/**
loit-build-component/loit-build-deploy-env/src/main/java/com/loit/common/script/GeneratorGitJobScript.java
0 → 100644
浏览文件 @
377a4bcd
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
;
}
}
loit-build-component/loit-build-deploy-env/src/main/java/com/loit/common/script/dto/DeployInfoDataDTO.java
浏览文件 @
377a4bcd
...
...
@@ -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
;
}
}
loit-build-component/loit-build-deploy-env/src/main/resources/deployInfo.xlsx
浏览文件 @
377a4bcd
No preview for this file type
loit-build-component/loit-build-deploy-env/src/main/resources/deployInfo1.xlsx
0 → 100644
浏览文件 @
377a4bcd
File added
loit-build-component/loit-build-deploy-env/src/main/resources/template/jenkinsJobGit.ftl
浏览文件 @
377a4bcd
...
...
@@ -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
"
##################create remore dist begin#############
"
destDir=
"
/home/version/push-jar/${
projectCode}/${modelServiceName}/${
modelVersion}
"
destDir=
"
/home/version/push-jar/${
r"${"}projectCode}/${r"${"}modelServiceName}/${r"${"}
modelVersion}
"
echo
'
please check destDir is include projectCode、modelServiceName、modelVersion:
'
+ $destDir
if [ -z
"
$projectCode
"
]; then
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论