main
黄海 9 months ago
parent 027c12d130
commit 5982956b3e

@ -6,19 +6,17 @@ WORKDIR /root
# ENV TZ这样的用法通常是用来设置时区环境变量TZ代表Time Zone
ENV TZ=Asia/Shanghai
# 声明变量
ENV file_name="dsBase-jar-with-dependencies.jar"
# 让容器内部正常显示中文
ENV LANG=C.UTF-8
ENV LANG C.UTF-8
# 将jar包复制到容器的/root目录下
COPY $file_name /root/$file_name
# 将target文件夹下的jar包gw-charge.jar复制到容器的/root目录下
COPY ./lib /root/lib
COPY ./target /root/target
#设置这个环境变量后您可以在Docker容器中启动Java应用程序时使用这些参数。
ENV JAVA_OPTS="-Xms1024m -Xmx2048m"
ENV JAVA_OPTS="-Xms512m -Xmx1024m"
# 标识为生产环境
ENV WORKING_ENV="dev"
ENV WORKING_ENV="pro"
ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -jar $file_name" ]
ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -cp /root/target/classes:/root/lib/* com.dsideal.base.BaseApplication" ]

@ -55,6 +55,12 @@
<artifactId>minio</artifactId>
<version>${minio.version}</version>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.1</version>
</dependency>
<!--引用json库-->
<dependency>
<groupId>net.sf.json-lib</groupId>
@ -207,43 +213,13 @@
<artifactId>jjwt</artifactId>
<version>0.7.0</version>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-core</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.1.1</version>
</dependency>
</dependencies>
<build>
<!--不加此项,文件名中就会多出一个版本号-->
<finalName>dsBase</finalName>
<!--将resources做为资源目录拷贝到fatjar当中-->
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<version>3.6.1</version>
<configuration>
<source>21</source>
<target>21</target>
@ -252,43 +228,6 @@
<compilerArgument>-parameters</compilerArgument>
</configuration>
</plugin>
<!--打包fatjar的插件-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>${maven-assembly-plugin.version}</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>com.dsideal.base.BaseApplication</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- 禁用默认的 jar 打包插件,防止生成额外的 jar 文件 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>${maven-jar-plugin.version}</version>
<executions>
<execution>
<id>default-jar</id>
<phase>none</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

@ -17,10 +17,11 @@ import com.dsideal.base.StudentYd.Controller.StudentYdController;
import com.dsideal.base.Teacher.Controller.TeacherController;
import com.dsideal.base.TeacherYd.Controller.TeacherYdController;
import com.dsideal.base.Tools.Controller.excelConvertController;
import com.dsideal.base.Util.CommonUtil;
import com.dsideal.base.Util.FileUtil;
import com.dsideal.base.Util.LogBackLogFactory;
import com.dsideal.base.Util.PkUtil;
import com.jfinal.config.*;
import com.jfinal.kit.PathKit;
import com.jfinal.kit.Prop;
import com.jfinal.kit.StrKit;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
@ -29,8 +30,9 @@ import com.jfinal.plugin.hikaricp.HikariCpPlugin;
import com.jfinal.plugin.redis.RedisPlugin;
import com.jfinal.server.undertow.UndertowServer;
import com.jfinal.template.Engine;
import lombok.SneakyThrows;
import java.util.List;
import java.io.File;
public class BaseApplication extends JFinalConfig {
public static String getEnvPrefix() {
@ -104,16 +106,37 @@ public class BaseApplication extends JFinalConfig {
}
@SneakyThrows
/**
*
*/
private String connectionTestQuery = "select 1";
// 连接池中允许的最大连接数。缺省值10推荐的公式((core_count * 2) + effective_spindle_count)
private int maxPoolSize = 10;
// 一个连接 idle 状态的最大时长(毫秒),超时则被释放(retired),缺省:10分钟
private long idleTimeoutMs = 600000;
private long maxLifetimeMs = 1800000;
// 等待连接池分配连接的最大时长(毫秒),超过这个时长还没可用的连接则发生 SQLException 缺省:30秒
private long connectionTimeoutMs = 30000;
@Override
public void configPlugin(Plugins me) {
HikariCpPlugin masterPlugin = new HikariCpPlugin(PropKit.get("mysql.jdbcUrl"), PropKit.get("mysql.user"),
PropKit.get("mysql.password").trim(), PropKit.get("mysql.driverClassName"));
masterPlugin.setConnectionTestQuery(connectionTestQuery);
masterPlugin.setConnectionTimeout(connectionTimeoutMs);
masterPlugin.setIdleTimeout(idleTimeoutMs);
masterPlugin.setMaxLifetime(maxLifetimeMs);
masterPlugin.setMaximumPoolSize(maxPoolSize);
String jdbcUrlSlave = PropKit.get("mysql.jdbcUrlSlave");
if (StrKit.isBlank(jdbcUrlSlave)) jdbcUrlSlave = PropKit.get("mysql.jdbcUrl");
HikariCpPlugin slavePlugin = new HikariCpPlugin(jdbcUrlSlave, PropKit.get("mysql.user"),
PropKit.get("mysql.password").trim(), PropKit.get("mysql.driverClassName"));
slavePlugin.setConnectionTestQuery(connectionTestQuery);
slavePlugin.setConnectionTimeout(connectionTimeoutMs);
slavePlugin.setIdleTimeout(idleTimeoutMs);
slavePlugin.setMaxLifetime(maxLifetimeMs);
slavePlugin.setMaximumPoolSize(maxPoolSize);
me.add(masterPlugin);
me.add(slavePlugin);
@ -123,11 +146,17 @@ public class BaseApplication extends JFinalConfig {
ActiveRecordPlugin slaveArp = new ActiveRecordPlugin("slave", slavePlugin);
slaveArp.setDialect(new MysqlDialect());
//加载所有的sql文件
List<String> list = CommonUtil.getAllSql();
for (String sqlFile : list) {
masterArp.addSqlTemplate(sqlFile);
slaveArp.addSqlTemplate(sqlFile);
//遍历sql目录下所有的sql文件
File sqlDir;
String basePath = PathKit.getRootClassPath();
sqlDir = new File(basePath + "/Sql");
File[] sqlFiles = sqlDir.listFiles();
for (File sqlFile : sqlFiles != null ? sqlFiles : new File[0]) {
//只加载.sql文件
if (sqlFile.getName().indexOf(".sql") > 0) {
masterArp.addSqlTemplate("/Sql/" + sqlFile.getName());
slaveArp.addSqlTemplate("/Sql/" + sqlFile.getName());
}
}
//加载
me.add(masterArp);
@ -193,13 +222,16 @@ public class BaseApplication extends JFinalConfig {
/**
* jfinal
*/
@SneakyThrows
@Override
public void onStart() {
//打印 启动Logo
System.out.println(CommonUtil.txt2String("logo.txt"));
String path = BaseApplication.class.getClassLoader().getResource("logo.txt").getPath();
File file = new File(path);
System.out.println(FileUtil.txt2String(file));
//初始化人员主键序列
PkUtil.InitPersonNumPk();
//初始化组织机构主键序列
PkUtil.InitOrgNumPk();
}

@ -0,0 +1,8 @@
mkdir lib
cd lib
del *.jar /q
cd ..
mvn -f pom.xml dependency:copy-dependencies -DoutputDirectory=lib
@echo 黄海完成了!
pause

@ -6,19 +6,18 @@ WORKDIR /root
# ENV TZ这样的用法通常是用来设置时区环境变量TZ代表Time Zone
ENV TZ=Asia/Shanghai
# 声明变量
ENV file_name="dsGw-jar-with-dependencies.jar"
# 让容器内部正常显示中文
ENV LANG=C.UTF-8
ENV LANG C.UTF-8
# 将jar包复制到容器的/root目录下
COPY $file_name /root/$file_name
# 将target文件夹下的jar包gw-charge.jar复制到容器的/root目录下
COPY ./lib /root/lib
COPY ./target /root/target
#设置这个环境变量后您可以在Docker容器中启动Java应用程序时使用这些参数。
ENV JAVA_OPTS="-Xms1024m -Xmx2048m"
ENV JAVA_OPTS="-Xms512m -Xmx1024m"
# 标识为生产环境
ENV WORKING_ENV="dev"
ENV WORKING_ENV="pro"
ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -jar $file_name" ]
ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -cp /root/target/classes:/root/lib/* com.dsideal.gw.GwApplication" ]

@ -119,15 +119,6 @@
</dependency>
</dependencies>
<build>
<!--不加此项,文件名中就会多出一个版本号-->
<finalName>dsGw</finalName>
<!--将resources做为资源目录拷贝到fatjar当中-->
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
@ -141,43 +132,6 @@
<compilerArgument>-parameters</compilerArgument>
</configuration>
</plugin>
<!--打包fatjar的插件-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>${maven-assembly-plugin.version}</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>com.dsideal.gw.GwApplication</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- 禁用默认的 jar 打包插件,防止生成额外的 jar 文件 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>${maven-jar-plugin.version}</version>
<executions>
<execution>
<id>default-jar</id>
<phase>none</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

@ -1,21 +1,14 @@
package com.dsideal.gw.Util;
import cn.hutool.core.io.IoUtil;
import com.jfinal.kit.PathKit;
import org.apache.commons.codec.digest.DigestUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.JarURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
@SuppressWarnings("unchecked")
public class CommonUtil {
@ -47,42 +40,6 @@ public class CommonUtil {
return IoUtil.read(is, "UTF-8");
}
/**
* sqllist
*
* @return
*/
public static List<String> getAllSql() throws IOException {
List<String> list = new ArrayList<>();
if (isRunInJar()) {
URL url = CommonUtil.class.getClassLoader().getResource("Sql/");
String jarPath = url.toString().substring(0, url.toString().indexOf("!/") + 2);
URL jarURL = new URL(jarPath);
JarURLConnection jarCon = (JarURLConnection) jarURL.openConnection();
JarFile jarFile = jarCon.getJarFile();
Enumeration<JarEntry> jarEntrys = jarFile.entries();
while (jarEntrys.hasMoreElements()) {
JarEntry entry = jarEntrys.nextElement();
String name = entry.getName();
if (name.startsWith("Sql/") && !entry.isDirectory()) {
list.add(name);
}
}
} else {//如果运行在文件系统中直接加载sql文件
//遍历sql目录下所有的sql文件
File sqlDir;
String basePath = PathKit.getRootClassPath();
sqlDir = new File(basePath + "/Sql");
File[] sqlFiles = sqlDir.listFiles();
for (File sqlFile : sqlFiles != null ? sqlFiles : new File[0]) {
if (sqlFile.getName().indexOf(".sql") > 0) {//只加载.sql文件
list.add("Sql/"+sqlFile.getName());
}
}
}
return list;
}
/**
*
*

@ -0,0 +1,8 @@
mkdir lib
cd lib
del *.jar /q
cd ..
mvn -f pom.xml dependency:copy-dependencies -DoutputDirectory=lib
@echo 黄海完成了!
pause

@ -6,19 +6,18 @@ WORKDIR /root
# ENV TZ这样的用法通常是用来设置时区环境变量TZ代表Time Zone
ENV TZ=Asia/Shanghai
# 声明变量
ENV file_name="dsRes-jar-with-dependencies.jar"
# 让容器内部正常显示中文
ENV LANG=C.UTF-8
ENV LANG C.UTF-8
# 将jar包复制到容器的/root目录下
COPY $file_name /root/$file_name
# 将target文件夹下的jar包gw-charge.jar复制到容器的/root目录下
COPY ./lib /root/lib
COPY ./target /root/target
#设置这个环境变量后您可以在Docker容器中启动Java应用程序时使用这些参数。
ENV JAVA_OPTS="-Xms1024m -Xmx2048m"
ENV JAVA_OPTS="-Xms512m -Xmx1024m"
# 标识为生产环境
ENV WORKING_ENV="dev"
ENV WORKING_ENV="pro"
ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -jar $file_name" ]
ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -cp /root/target/classes:/root/lib/* com.dsideal.resource.ResApplication" ]

@ -261,43 +261,6 @@
<compilerArgument>-parameters</compilerArgument>
</configuration>
</plugin>
<!--打包fatjar的插件-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>${maven-assembly-plugin.version}</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>com.dsideal.base.BaseApplication</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- 禁用默认的 jar 打包插件,防止生成额外的 jar 文件 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>${maven-jar-plugin.version}</version>
<executions>
<execution>
<id>default-jar</id>
<phase>none</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

@ -4,7 +4,6 @@ import com.dsideal.resource.Base.Controller.BaseController;
import com.dsideal.resource.Index.IndexController;
import com.dsideal.resource.Interceptor.*;
import com.dsideal.resource.Plugin.YamlProp;
import com.dsideal.resource.Util.CommonUtil;
import com.dsideal.resource.Util.FileUtil;
import com.dsideal.resource.Util.LogBackLogFactory;
import com.jfinal.config.*;
@ -16,10 +15,8 @@ import com.jfinal.plugin.hikaricp.HikariCpPlugin;
import com.jfinal.plugin.redis.RedisPlugin;
import com.jfinal.server.undertow.UndertowServer;
import com.jfinal.template.Engine;
import lombok.SneakyThrows;
import java.io.File;
import java.util.List;
public class ResApplication extends JFinalConfig {
@ -82,7 +79,6 @@ public class ResApplication extends JFinalConfig {
// 等待连接池分配连接的最大时长(毫秒),超过这个时长还没可用的连接则发生 SQLException 缺省:30秒
private long connectionTimeoutMs = 30000;
@SneakyThrows
@Override
public void configPlugin(Plugins me) {
HikariCpPlugin masterPlugin = new HikariCpPlugin(PropKit.get("mysql.jdbcUrl"), PropKit.get("mysql.user"),
@ -111,13 +107,18 @@ public class ResApplication extends JFinalConfig {
ActiveRecordPlugin slaveArp = new ActiveRecordPlugin("slave", slavePlugin);
slaveArp.setDialect(new MysqlDialect());
//加载所有的sql文件
List<String> list = CommonUtil.getAllSql();
for (String sqlFile : list) {
masterArp.addSqlTemplate(sqlFile);
slaveArp.addSqlTemplate(sqlFile);
//遍历sql目录下所有的sql文件
File sqlDir;
String basePath = ResApplication.class.getResource("/").getPath();
sqlDir = new File(basePath + "/Sql");
File[] sqlFiles = sqlDir.listFiles();
for (File sqlFile : sqlFiles != null ? sqlFiles : new File[0]) {
//只加载.sql文件
if (sqlFile.getName().indexOf(".sql") > 0) {
masterArp.addSqlTemplate("/Sql/" + sqlFile.getName());
slaveArp.addSqlTemplate("/Sql/" + sqlFile.getName());
}
}
//加载
me.add(masterArp);
me.add(slaveArp);
@ -138,6 +139,7 @@ public class ResApplication extends JFinalConfig {
//注册非空拦截器
me.add(new EmptyInterceptor());
//注册Ids检查是不是数字的检查器
me.add(new CheckIdsInterceptor());
@ -149,9 +151,6 @@ public class ResApplication extends JFinalConfig {
//注册一个检查输入文本长度的拦截器
me.add(new LengthInterceptor());
//注册JWT
me.add(new JwtCheckInterceptor());
}
/**
@ -164,10 +163,11 @@ public class ResApplication extends JFinalConfig {
/**
* jfinal
*/
@SneakyThrows
@Override
public void onStart() {
//打印 启动Logo
System.out.println(CommonUtil.txt2String("logo.txt"));
String path = ResApplication.class.getClassLoader().getResource("logo.txt").getPath();
File file = new File(path);
System.out.println(FileUtil.txt2String(file));
}
}

@ -50,7 +50,6 @@ public class Publish {
String basedir = new File(System.getProperty("user.dir")).getCanonicalPath();
workingPath = basedir + "\\" + projectBean.getDevProjectName() + "\\";
projectName = projectBean.getPublishProjectName();
devProjectName= projectBean.getDevProjectName();
if (FileUtil.exist(workingPath + "lib")) {
localLibPath = workingPath + "lib\\";
}
@ -61,7 +60,7 @@ public class Publish {
isStatic = true;
}
//开始打包
Kv ret = PublishUtil.publish(projectName,devProjectName, isStatic, workingPath, localLibPath, choiceWarehouse, choiceConfig);
Kv ret = PublishUtil.publish(projectName,isStatic, workingPath, localLibPath, choiceWarehouse, choiceConfig);
System.out.println("测试运行一下容器吧");
if (ret.getStr("project_port") != null) {

@ -5,7 +5,6 @@ import cn.hutool.core.util.ZipUtil;
import com.alibaba.fastjson2.JSONObject;
import com.jfinal.kit.Kv;
import com.jfinal.kit.PathKit;
import com.jfinal.kit.PropKit;
import com.jfinal.kit.StrKit;
import java.io.*;
@ -64,8 +63,12 @@ public class PublishUtil {
* docker tag 19a54d2204aa registry.cn-hangzhou.aliyuncs.com/yltcharge/jdk:21
* docker push registry.cn-hangzhou.aliyuncs.com/yltcharge/jdk:21
*/
public static Kv publish(String projectName, String devProjectName, boolean isStatic, String workingPath, String localLibPath, Kv choiceWarehouse, String choiceConfig) throws Exception {
public static Kv publish(String projectName, boolean isStatic, String workingPath, String localLibPath, Kv choiceWarehouse, String choiceConfig) throws Exception {
//判断是不是有需要批处理的生成JAR的过程
String cmdPath = workingPath + "生成依赖jar.bat";
if (FileUtil.exist(cmdPath)) {
ExecBatchCmd(cmdPath);
}
System.out.println("正在生成" + projectName + "的镜像...");
//配置文件
String path = PathKit.getRootClassPath() + "\\publishImage.json";
@ -101,24 +104,38 @@ public class PublishUtil {
ssh.upload(workingPath + "Dockerfile", remotePath + "Dockerfile");
}
System.out.println("正在上传" + projectName + "的jar包...");
//上传jar包
String fatjarName = devProjectName + "-jar-with-dependencies.jar";
String localFile = workingPath + "target/" + fatjarName;
//获取项目端口
String undertow_dev = workingPath.replace("\\","/") + "target/classes/undertow_dev.properties";
List<String> list=FileUtil.readLines(undertow_dev, "UTF-8");
for (String line : list) {
if (line.contains("undertow.port")) {
String[] split = line.split("=");
project_port = split[1];
break;
if (!StrKit.isBlank(localLibPath)) {
System.out.println("正在创建lib目录...");
ssh.mkdir(remotePath + "lib");
//遍历lib目录下的文件
for (File file : FileUtil.loopFiles(localLibPath)) {
System.out.println("正在上传jar包" + file.getName());
ssh.upload(file.getAbsolutePath(), remotePath + "lib/" + file.getName());
}
}
if (FileUtil.exist(localFile)) {
System.out.println("正在上传" + fatjarName + "...");
//打包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);
//上传
ssh.upload(localFile, remotePath + fatjarName);
ssh.upload(localFile, remotePath + "target.zip");
//删除target.zip
FileUtil.del(localFile);
//解压缩
System.out.println("正在解压缩target.zip...");
ssh.exec("cd " + remotePath + " && unzip target.zip");
ssh.exec("cd " + remotePath + " && rm -rf target.zip");
//获取项目端口
String undertow_dev = remotePath + "target/classes/undertow_dev.properties";
String cmd = "grep '^undertow\\.port=' " + undertow_dev + " | awk -F'=' '{print $2}'";
project_port = ssh.exec(cmd).getStr("message").replace("[", "").replace("]", "");
}
//处理静态文件
@ -133,7 +150,7 @@ public class PublishUtil {
break;
}
}
localFile = workingPath.substring(0, pos) + "\\static.zip";
String localFile = workingPath.substring(0, pos) + "\\static.zip";
if (FileUtil.exist(localFile)) {
FileUtil.del(localFile);
}

Loading…
Cancel
Save