main
黄海 10 months ago
parent a95060e603
commit acdea13f7c

@ -35,8 +35,15 @@ import java.io.File;
public class BaseApplication extends JFinalConfig {
public static String getEnvPrefix() {
String myEnvVar = System.getenv("WORKING_ENV");
return myEnvVar == null ? "dev" : "pro";
}
public static void main(String[] args) {
UndertowServer.create(BaseApplication.class, "undertow.properties").start();
String configFile = "undertow_{?}.properties".replace("{?}", getEnvPrefix());
System.out.println("加载容器配置文件: " + configFile);
UndertowServer.create(BaseApplication.class, configFile).start();
}
/**
@ -47,16 +54,9 @@ public class BaseApplication extends JFinalConfig {
//使用LogBack
me.setLogFactory(new LogBackLogFactory());
//加载配置文件
//配置文件
String configFile = "application_dev.properties";
String myEnvVar = System.getenv("WORKING_ENV");
if (myEnvVar != null) {
configFile = configFile.replace("_dev", "_pro");
System.out.println("环境变量 WORKING_ENV 的值是: " + myEnvVar);
} else {
System.out.println("环境变量 WORKING_ENV 未设置。");
}
String configFile = "application_{?}.properties".replace("{?}", getEnvPrefix());
PropKit.use(configFile);
System.out.println("加载主配置文件: " + configFile);
}
/**

@ -2,7 +2,7 @@
undertow.devMode=true
undertow.port=9000
undertow.host=0.0.0.0
#undertow.resourcePath =/usr/local/tomcat8/webapps/dsBase,classpath:static
#undertow.resourcePath =/root/dsBase/WebRoot,classpath:static
undertow.resourcePath =D:/dsWork/dsExam/ds-base/WebRoot,classpath:static
# 目录名称

@ -0,0 +1,35 @@
# true 值支持热加载
undertow.devMode=true
undertow.port=9000
undertow.host=0.0.0.0
undertow.resourcePath =/root/dsBase/WebRoot,classpath:static
# 目录名称
undertow.contextPath=/dsBase
# 设定I/O线程数.
server.undertow.io-threads=8
# 设定工作线程数
server.undertow.worker-threads=60
# 查询当前某程序的线程或进程数
# yum install psmisc -y
# ps -e | grep java | awk '{print $1}
# pstree -p 15453 | wc -l
# gzip 压缩开关
undertow.gzip.enable=true
# 配置压缩级别,默认值 -1。 可配置 1 到 9。 1 拥有最快压缩速度9 拥有最高压缩率
undertow.gzip.level=-1
# 触发压缩的最小内容长度
undertow.gzip.minLength=1024
# 开启access日志
server.undertow.accesslog.enabled=true
server.undertow.accesslog.pattern=%t %a "%r" %s (%D ms)
# ssl 开启时,是否开启 http2。检测该配置是否生效在 chrome 地址栏中输入: chrome://net-internals/#http2
#undertow.http2.enable=true
#http://www.jfinal.com/doc/1-4

@ -51,10 +51,10 @@ public class PublishUtil {
workingPath = project.getString("workingPath");
localLibPath = project.getString("localLibPath");
if (project.getString("localStatic") != null) {
localStatic = workingPath + project.getString("localStatic");
localStatic = project.getString("localStatic");
}
if (project.getString("localNginxConf") != null) {
localNginxConf = workingPath + project.getString("localNginxConf");
localNginxConf = project.getString("localNginxConf");
}
break;
}
@ -71,7 +71,7 @@ public class PublishUtil {
newVersion = newVersion.replace(" ", "").replace("-", "").replace(":", "");
//准备工作
remotePath = "/usr/local/" + projectName;
remotePath = "/usr/local/" + projectName+"/";
ssh.exec("rm -rf " + remotePath);
ssh.mkdir(remotePath);
@ -89,13 +89,21 @@ public class PublishUtil {
}
}
if (!StrKit.isBlank(localStatic)) {
System.out.println("正在创建static目录...");
ssh.mkdir(remotePath + "/static");
//遍历static目录下的文件
for (File file : FileUtil.loopFiles(localStatic)) {
System.out.println("正在上传文件:" + file.getName());
ssh.upload(file.getAbsolutePath(), remotePath + "/static/" + file.getName());
}
System.out.println("正在创建" + localStatic + "目录...");
ssh.mkdir(remotePath + "/" + localStatic);
//1、需要把目录压缩成ZIP文件
// 将目录打包成ZIP文件不包含目录本身只包含目录下的文件和子目录
String localFile = workingPath + localStatic + ".zip";
System.out.println("正在进行静态文件的打包ZIP操作请稍等...");
ZipUtil.zip(workingPath + localStatic, localFile, true);
System.out.println("静态文件打包ZIP已完成正在上传...");
//2、需要把ZIP文件上传
ssh.upload(localFile, remotePath + "/" + localStatic + ".zip");
//3、把ZIP文件在远端解压缩
ssh.exec("cd " + remotePath + " && unzip " + localStatic + ".zip");
ssh.exec("cd " + remotePath + " && rm -rf " + localStatic + ".zip");
//4、删除target.zip
FileUtil.del(localFile);
}
if (!StrKit.isBlank(localNginxConf)) {
System.out.println("正在上传nginx.conf...");
@ -104,16 +112,16 @@ public class PublishUtil {
System.out.println("成功完成上传文件nginx.conf");
}
//打包target为zip
if (FileUtil.isDirectory(workingPath + "/target")) {
String localFile = workingPath + "/target.zip";
if (FileUtil.isDirectory(workingPath + "target")) {
String localFile = workingPath + "target.zip";
if (FileUtil.exist(localFile)) {
FileUtil.del(localFile);
}
System.out.println("正在上传target.zip...");
// 将目录打包成ZIP文件不包含目录本身只包含目录下的文件和子目录
ZipUtil.zip(workingPath + "/target", localFile, true);
ZipUtil.zip(workingPath + "target", localFile, true);
//上传
ssh.upload(localFile, remotePath + "/target.zip");
ssh.upload(localFile, remotePath + "target.zip");
//删除target.zip
FileUtil.del(localFile);
//解压缩
@ -127,6 +135,7 @@ public class PublishUtil {
String cmd = "cd /usr/local/" + projectName + " && docker build -t " + projectName + ":" + newVersion + " .";
System.out.println(cmd);
ssh.exec(cmd);
//获取最新打包后的镜像ID
cmd = "docker images --format \"{{.Repository}} {{.Tag}} {{.ID}} {{.CreatedAt}}\" | grep " + projectName + " | sort -k4,5 -r | head -n1 | awk '{print $3}'";
Kv kv = ssh.exec(cmd);

@ -15,7 +15,7 @@
"projectName": "ds-base",
"workingPath": "D:/dsWork/dsExam/ds-base/",
"localLibPath": "D:/dsWork/dsExam/ds-base/lib/",
"localStatic": "D:/dsWork/dsExam/ds-base/WebRoot/",
"localStatic": "WebRoot",
"localNginxConf": ""
}
]

@ -15,7 +15,7 @@
"projectName": "ds-base",
"workingPath": "D:/dsWork/dsExam/ds-base/",
"localLibPath": "D:/dsWork/dsExam/ds-base/lib/",
"localStatic": "D:/dsWork/dsExam/ds-base/WebRoot/",
"localStatic": "WebRoot",
"localNginxConf": ""
}
]

Loading…
Cancel
Save