main
黄海 10 months ago
parent f5a1716b5a
commit 83fb7ca09b

@ -1,4 +1,4 @@
FROM registry.cn-hangzhou.aliyuncs.com/yltcharge/jdk:21
FROM dragonwell-registry.cn-hangzhou.cr.aliyuncs.com/dragonwell/dragonwell:21
# WORKDIR指令用于设置容器内部的工作目录即后续指令执行时的当前目录。当Docker容器启动并执行命令时这些命令将在WORKDIR指定的目录中执行。
WORKDIR /root
@ -6,6 +6,9 @@ WORKDIR /root
# ENV TZ这样的用法通常是用来设置时区环境变量TZ代表Time Zone
ENV TZ=Asia/Shanghai
# 让容器内部正常显示中文
ENV LANG C.UTF-8
# 将target文件夹下的jar包gw-charge.jar复制到容器的/root目录下
COPY ./lib /root/lib
COPY ./target /root/target

@ -57,8 +57,13 @@ public class Publish {
isStatic = true;
}
//开始打包
String result = PublishUtil.publish(projectName, isStatic, workingPath, localLibPath, choiceWarehouse, choiceConfig);
Kv ret = PublishUtil.publish(projectName, isStatic, workingPath, localLibPath, choiceWarehouse, choiceConfig);
System.out.println("测试运行一个容器吧,比如docker run --name " + result.split(":")[0] + " -p 8001:8001 -d " + result);
System.out.println("测试运行一下容器吧");
if (ret.getStr("project_port") != null) {
String port = ret.getStr("project_port");
System.out.println("docker run --name " + ret.getStr("projectName").split(":")[0] + " -p " + port + ":" + port + " -d " + ret.getStr("projectName"));
System.out.println("docker exec -it 替换我为容器ID /bin/bash");
}
}
}

@ -47,7 +47,7 @@ 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 String publish(String projectName, 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 {
System.out.println("正在生成" + projectName + "的镜像...");
//配置文件
String path = PathKit.getRootClassPath() + "\\publishImage.json";
@ -58,6 +58,8 @@ public class PublishUtil {
String pwd = jo.getString("pwd");
int port = jo.getIntValue("port");
String project_port=null;
//声明SSH对象
SSHUtil ssh = new SSHUtil(user, pwd, host, port);
ssh.connect();
@ -108,6 +110,11 @@ public class PublishUtil {
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("]","");
}
//处理静态文件
@ -152,7 +159,7 @@ public class PublishUtil {
System.out.println("环境变量修改成功!");
//如果容器正在运行中,那么容器对应的镜像删除失败
cmd="docker rm -f $(docker ps -aq)";
cmd = "docker rm -f $(docker ps -aq)";
ssh.exec(cmd);
//删除所有镜像
@ -189,7 +196,9 @@ public class PublishUtil {
ssh.disconnect();
System.out.println("恭喜,镜像打包成功!");
return projectName + ":" + newVersion;
Kv ret = Kv.by("projectName", projectName+":"+newVersion);
ret.set("project_port",project_port);
return ret;
}
/**

Loading…
Cancel
Save