main
黄海 9 months ago
parent 8a3c09594e
commit 5b398ace35

@ -7,13 +7,13 @@ WORKDIR /root
ENV TZ=Asia/Shanghai
# 声明变量
ARG file_name=dsBase-jar-with-dependencies.jar
ENV file_name="dsBase-jar-with-dependencies.jar"
# 让容器内部正常显示中文
ENV LANG=C.UTF-8
# 将jar包复制到容器的/root目录下
COPY ${file_name} /root/${file_name}
COPY $file_name /root/$file_name
#设置这个环境变量后您可以在Docker容器中启动Java应用程序时使用这些参数。
ENV JAVA_OPTS="-Xms1024m -Xmx2048m"
@ -21,4 +21,4 @@ ENV JAVA_OPTS="-Xms1024m -Xmx2048m"
# 标识为生产环境
ENV WORKING_ENV="dev"
ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -jar /root/${file_name}" ]
ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -jar $file_name" ]

@ -43,13 +43,14 @@ public class Publish {
//这个项目是什么类型?
String projectAttribute = PublishUtil.getProjectAttribute(choiceProject, listProject);
String workingPath = null, projectName = null, localLibPath = null;
String workingPath = null, projectName = null, localLibPath = null,devProjectName = null;
boolean isStatic = false;
for (ProjectBean projectBean : listProject) {
if (projectBean.getId() == choiceProject) {
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\\";
}
@ -60,7 +61,7 @@ public class Publish {
isStatic = true;
}
//开始打包
Kv ret = PublishUtil.publish(projectName, isStatic, workingPath, localLibPath, choiceWarehouse, choiceConfig);
Kv ret = PublishUtil.publish(projectName,devProjectName, isStatic, workingPath, localLibPath, choiceWarehouse, choiceConfig);
System.out.println("测试运行一下容器吧");
if (ret.getStr("project_port") != null) {

@ -5,6 +5,7 @@ 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.*;
@ -63,12 +64,8 @@ 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, boolean isStatic, String workingPath, String localLibPath, Kv choiceWarehouse, String choiceConfig) throws Exception {
//判断是不是有需要批处理的生成JAR的过程
String cmdPath = workingPath + "生成依赖jar.bat";
if (FileUtil.exist(cmdPath)) {
ExecBatchCmd(cmdPath);
}
public static Kv publish(String projectName, String devProjectName, boolean isStatic, String workingPath, String localLibPath, Kv choiceWarehouse, String choiceConfig) throws Exception {
System.out.println("正在生成" + projectName + "的镜像...");
//配置文件
String path = PathKit.getRootClassPath() + "\\publishImage.json";
@ -104,38 +101,24 @@ public class PublishUtil {
ssh.upload(workingPath + "Dockerfile", remotePath + "Dockerfile");
}
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());
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;
}
}
//打包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);
if (FileUtil.exist(localFile)) {
System.out.println("正在上传" + 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("]", "");
ssh.upload(localFile, remotePath + fatjarName);
}
//处理静态文件
@ -150,7 +133,7 @@ public class PublishUtil {
break;
}
}
String localFile = workingPath.substring(0, pos) + "\\static.zip";
localFile = workingPath.substring(0, pos) + "\\static.zip";
if (FileUtil.exist(localFile)) {
FileUtil.del(localFile);
}

Loading…
Cancel
Save