From b9aa05e3973d0432ac11228a9360507daf6ae300 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=BC=A0=E7=A6=8F=E8=B4=A2?= <1471584931@qq.com>
Date: Fri, 23 Jan 2026 09:54:38 +0800
Subject: [PATCH] =?UTF-8?q?---=E4=BC=98=E5=8C=96docker=E9=95=9C=E5=83=8F?=
=?UTF-8?q?=E6=89=93=E5=8C=85?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
itc-pcitc-demo/itc-pcitc-demo-api/pom.xml | 2 +-
itc-pcitc-demo/itc-pcitc-demo-service/pom.xml | 2 +-
.../src/main/docker/Dockerfile | 8 +-
.../src/test/java/com/xjrsoft/CallTest.java | 36 ++--
.../src/test/java/com/xjrsoft/JarUtils.java | 200 ++++++++++++++++++
.../src/test/java/com/xjrsoft/TJarInfo.java | 19 ++
.../itc-pcitc-dependencies-api/pom.xml | 8 +-
.../itc-pcitc-dependencies-service/pom.xml | 8 +-
itc-pcitc-mdm/itc-pcitc-mdm-api/pom.xml | 8 +-
itc-pcitc-mdm/itc-pcitc-mdm-service/pom.xml | 8 +-
itc-pcitc-mdm/itc-pcitc-mdm-start/pom.xml | 42 +---
11 files changed, 261 insertions(+), 80 deletions(-)
create mode 100644 itc-pcitc-demo/itc-pcitc-demo-service/src/test/java/com/xjrsoft/JarUtils.java
create mode 100644 itc-pcitc-demo/itc-pcitc-demo-service/src/test/java/com/xjrsoft/TJarInfo.java
diff --git a/itc-pcitc-demo/itc-pcitc-demo-api/pom.xml b/itc-pcitc-demo/itc-pcitc-demo-api/pom.xml
index 7e7dc3c..637b795 100644
--- a/itc-pcitc-demo/itc-pcitc-demo-api/pom.xml
+++ b/itc-pcitc-demo/itc-pcitc-demo-api/pom.xml
@@ -19,7 +19,7 @@
${java.version}
http://10.10.2.102:9500
pcitc
- K9$pQ3!zX7@rT2&w
+ K9pQ3!zX7@rT2w
false
diff --git a/itc-pcitc-demo/itc-pcitc-demo-service/pom.xml b/itc-pcitc-demo/itc-pcitc-demo-service/pom.xml
index 7998853..71cd9bd 100644
--- a/itc-pcitc-demo/itc-pcitc-demo-service/pom.xml
+++ b/itc-pcitc-demo/itc-pcitc-demo-service/pom.xml
@@ -20,7 +20,7 @@
pcitc/itc-pcitc-demo
http://10.10.2.102:9509/
pcitc
- K9$pQ3!zX7@rT2&w
+ K9pQ3!zX7@rT2w
false
${project.build.finalName}-server.jar
diff --git a/itc-pcitc-demo/itc-pcitc-demo-service/src/main/docker/Dockerfile b/itc-pcitc-demo/itc-pcitc-demo-service/src/main/docker/Dockerfile
index 2976016..cff003b 100644
--- a/itc-pcitc-demo/itc-pcitc-demo-service/src/main/docker/Dockerfile
+++ b/itc-pcitc-demo/itc-pcitc-demo-service/src/main/docker/Dockerfile
@@ -5,8 +5,8 @@ FROM jdk8u112:v1
RUN mkdir -p /root/logs/java/ \
&& mkdir -p /scm/logs/ \
&& mkdir -p /opt/app/ \
+ && mkdir -p /opt/app/lib/ \
&& mkdir -p /uploadFile/ \
- && mkdir -p /opt/libs/ \
&& mkdir -p /var/log/app \
&& mkdir -p /opt/app/logs \
&& mkdir -p /opt/agent/config
@@ -29,14 +29,14 @@ ADD ./${SOURCE_NAME} /opt/app/app.jar
#RUN test -f /opt/app/app.jar || { echo "Error: JAR file not found at ${SOURCE_NAME}"; exit 1; }
#应用名称
-ENV APP_NAME=itc-pcitc-mdm
+ENV APP_NAME=demo-service
#skywalking-oap-server地址
ENV SKYWALKING_SERVER=10.10.2.102:11800
ENV ENV_APP_FILE_PATH=/opt/app/app.jar
ENV ENV_APP_PRO_FILE=local
-ENV LIB_SERVER_ADDR=http://10.10.2.102:9500/
+ENV LIB_SERVER_ADDR=http://10.10.2.102:9509/
ENV LIB_SERVER_USER=pcitc
-ENV LIB_SERVER_PWD=K9$pQ3!zX7@rT2&w
+ENV LIB_SERVER_PWD=K9pQ3!zX7@rT2w
EXPOSE 8096 5005
diff --git a/itc-pcitc-demo/itc-pcitc-demo-service/src/test/java/com/xjrsoft/CallTest.java b/itc-pcitc-demo/itc-pcitc-demo-service/src/test/java/com/xjrsoft/CallTest.java
index f545c14..ae4d187 100644
--- a/itc-pcitc-demo/itc-pcitc-demo-service/src/test/java/com/xjrsoft/CallTest.java
+++ b/itc-pcitc-demo/itc-pcitc-demo-service/src/test/java/com/xjrsoft/CallTest.java
@@ -1,6 +1,10 @@
package com.xjrsoft;
+import java.io.File;
import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.stream.Stream;
@@ -13,6 +17,9 @@ import org.springframework.test.context.junit4.SpringRunner;
import com.xjrsoft.module.common.db.service.CommonCallService;
import cn.hutool.core.io.IoUtil;
+import cn.hutool.http.HttpRequest;
+import cn.hutool.http.HttpResponse;
+import cn.hutool.http.HttpUtil;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = ITCDemoApplication.class)
@@ -29,20 +36,21 @@ public class CallTest {
System.out.println(out);
}
- public static void main(String[] args) {
- String filePath = "D:\\java\\conf\\cn-ips.txt";
- boolean first = false;
- // 2. 流式读取(适合大文件,逐行处理,不占内存)
- try (Stream lineStream = Files.lines(Paths.get(filePath))) {
- lineStream.forEach(line -> {
- // 逐行处理逻辑(如解析、过滤)
- if (!line.isEmpty()) { // 跳过空行
- System.out.print(";" + line);
- }
- });
- } catch (IOException e) {
- System.err.println("流式读取失败:" + e.getMessage());
- }
+ private static String encode(String val) throws UnsupportedEncodingException {
+ return URLEncoder.encode(val, StandardCharsets.UTF_8.name());
+ }
+
+ public static void main(String[] args) throws Exception {
+// HttpRequest post = HttpUtil.createPost("http://10.10.2.102:9500/sys/jar/download?name="+encode("netty-common-4.1.84.Final.jar")+"&env=local");
+// post.header("Content-Type", "application/json;charset=UTF-8");
+// post.header("Authorization", "Basic cGNpdGM6SzkkcFEzIXpYN0ByVDImdw==");
+// HttpResponse response = post.execute();
+// //byte[] bytes = response.bodyBytes();
+// System.out.println(response.header("Content-Type"));
+// System.out.println(response.headers());
+// System.out.println(response.header("Content-Length"));
+ //System.out.println(response.body());
+ JarUtils.download("http://10.10.2.102:9500/","Basic cGNpdGM6SzkkcFEzIXpYN0ByVDImdw==","local","netty-common-4.1.84.Final.jar",new File("D:/netty-common-4.1.84.Final.jar"));
}
}
diff --git a/itc-pcitc-demo/itc-pcitc-demo-service/src/test/java/com/xjrsoft/JarUtils.java b/itc-pcitc-demo/itc-pcitc-demo-service/src/test/java/com/xjrsoft/JarUtils.java
new file mode 100644
index 0000000..cbb70ec
--- /dev/null
+++ b/itc-pcitc-demo/itc-pcitc-demo-service/src/test/java/com/xjrsoft/JarUtils.java
@@ -0,0 +1,200 @@
+package com.xjrsoft;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.UnsupportedEncodingException;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.net.URLEncoder;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.List;
+
+public class JarUtils {
+
+ /**
+ * @Description: TODO(这里用一句话描述这个方法的作用)
+ * @param baseURI jar管理服务地址
+ * @param env 环境
+ * @param name jar名称
+ * @param outDir 保存jar包文件夹
+ * @throws Exception
+ * @return void 返回类型
+ */
+ public static void download(String baseURI,String authorization,String env,String name,File jar) throws Exception {
+ try {
+ HttpURLConnection httpConn = null;
+ // 获取输入输出流
+ InputStream is = null;
+ FileOutputStream os = null;
+ try {
+ URL url = new URL(parseDowloadUrl(baseURI,env,name));
+ httpConn = (HttpURLConnection) url.openConnection();
+ httpConn.setRequestMethod("POST");
+ httpConn.setDoOutput(true);
+ httpConn.setDoInput(true);
+ httpConn.setUseCaches(false);
+ httpConn.setConnectTimeout(30 * 1000); // 连接超时
+ httpConn.setReadTimeout(5 * 60 * 1000); // 读取超时
+ httpConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
+ httpConn.setRequestProperty("Authorization", authorization);
+ int responseCode = httpConn.getResponseCode();
+ if (responseCode < 200 || responseCode >= 300) {
+ String errorMsg = String.format("下载Jar失败:URL=%s,响应码=%d,响应信息=%s",
+ url.toString(), responseCode, httpConn.getResponseMessage());
+ System.out.println(errorMsg);
+ throw new RuntimeException(errorMsg);
+ }
+
+ is = httpConn.getInputStream();
+ os = new FileOutputStream(jar);
+ // 写入文件流,缓存为10MB
+ byte[] buf = new byte[2048];
+ int len;
+ long totalBytes = 0; // 记录下载字节数,便于日志排查
+ while((len=is.read(buf)) != -1) {
+ os.write(buf, 0, len);
+ totalBytes += len;
+ }
+ os.flush();
+ String msg =String.format("Jar下载成功!名称=%s,保存路径=%s,总大小=%d KB",name, jar.getAbsolutePath(), totalBytes / 1024);
+ System.out.println(msg);
+ } finally {
+ if(is!=null) is.close();
+ if(os!=null) os.close();
+ }
+ } catch (Exception e) {
+ throw new RuntimeException("下载jar["+name+"]失败!",e);
+ }
+ }
+
+ private static String parseDowloadUrl(String url,String env,String name) throws UnsupportedEncodingException {
+ if(url.endsWith("/")) {
+ url = url.substring(0, url.length()-1);
+ }
+ return url+"/sys/jar/download?name="+encode(name)+"&&env="+encode(env);
+ }
+
+ private static String encode(String val) throws UnsupportedEncodingException {
+ return URLEncoder.encode(val, StandardCharsets.UTF_8.name());
+ }
+
+ /**
+ * 获取Jar包信息列表
+ *
+ * @param baseURI jar管理服务基础地址
+ * @param authorization 认证令牌(如Bearer token)
+ * @param appName 应用名称
+ * @param env 环境标识(如dev/test/prod)
+ * @return Jar信息列表
+ * @throws Exception 当请求失败或处理异常时抛出
+ */
+ public static List getJarInfo(String baseURI, String authorization, String appName, String env) throws Exception {
+ // 构建表单参数(application/x-www-form-urlencoded格式需用&分隔)
+ String encodedAppName = URLEncoder.encode(appName, StandardCharsets.UTF_8.name());
+ String encodedEnv = URLEncoder.encode(env, StandardCharsets.UTF_8.name());
+ // 构建请求URL
+ URL url = new URL(parseUrl(baseURI, "/sys/jar/getAppInfo?appName=" + encodedAppName + "&env=" + encodedEnv));
+ HttpURLConnection httpConn = null;
+
+ try {
+ // 初始化HTTP连接
+ httpConn = (HttpURLConnection) url.openConnection();
+ httpConn.setRequestMethod("GET");
+ httpConn.setDoOutput(true);
+ httpConn.setDoInput(true);
+ httpConn.setUseCaches(false);
+ httpConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
+ httpConn.setRequestProperty("Authorization", authorization);
+
+ // 获取响应码
+ int responseCode = httpConn.getResponseCode();
+ // 根据响应码选择输入流(200用正常流,其他用错误流)
+ try (InputStream in = responseCode == 200 ? httpConn.getInputStream() : httpConn.getErrorStream();
+ BufferedReader br = new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8))) {
+
+ if (responseCode != 200) {
+ // 读取错误信息并抛出异常
+ String errorMsg = readAllLines(br);
+ throw new IOException("获取jar明细失败,响应码:" + responseCode + ",错误信息:" + errorMsg);
+ }
+
+ // 解析正常响应数据
+ List infos = new ArrayList<>();
+ String line = null;
+ while ((line = br.readLine()) != null){
+ String[] splits = line.split("=", 2); // 限制分割为2部分,避免值中包含=的情况
+ if (splits.length == 2) { // 校验分割结果,避免数组越界
+ infos.add(new TJarInfo(splits[0], "Y".equals(splits[1])));
+ } else {
+ // 日志记录非法格式的行(建议替换为日志框架)
+ System.err.println("无效的响应行格式:" + line);
+ }
+ }
+ return infos;
+ }
+
+ } catch (Exception e) {
+ // 包装异常,保留原始堆栈
+ throw new Exception("获取jar明细失败:" + e.getMessage(), e);
+ } finally {
+ // 确保连接关闭
+ if (httpConn != null) {
+ httpConn.disconnect();
+ }
+ }
+ }
+
+ /**
+ * 读取BufferedReader的所有行
+ */
+ private static String readAllLines(BufferedReader br) throws IOException {
+ StringBuilder sb = new StringBuilder();
+ String line;
+ while ((line = br.readLine()) != null) {
+ sb.append(line).append(System.lineSeparator());
+ }
+ return sb.toString().trim();
+ }
+
+
+ /**
+ * Returns the text read from the given reader as a String. Closes the given
+ * reader upon return.
+ */
+ public static String getText(BufferedReader reader) throws IOException {
+ try {
+ StringBuilder source = new StringBuilder();
+ String line = reader.readLine();
+
+ while (line != null) {
+ source.append(line);
+ source.append('\n');
+ line = reader.readLine();
+ }
+ return source.toString();
+ } finally {
+ try {
+ reader.close();
+ } catch (IOException ex) {
+ // Ignore
+ }
+ }
+ }
+
+ private static String parseUrl(String url,String path) {
+ if(url.endsWith("/")) {
+ url = url.substring(0, url.length()-1);
+ }
+ return url+path;
+ }
+
+ public static void main(String[] args) throws Exception {
+ URLEncoder.encode(null, StandardCharsets.UTF_8.name());
+ }
+
+}
diff --git a/itc-pcitc-demo/itc-pcitc-demo-service/src/test/java/com/xjrsoft/TJarInfo.java b/itc-pcitc-demo/itc-pcitc-demo-service/src/test/java/com/xjrsoft/TJarInfo.java
new file mode 100644
index 0000000..a59b6b5
--- /dev/null
+++ b/itc-pcitc-demo/itc-pcitc-demo-service/src/test/java/com/xjrsoft/TJarInfo.java
@@ -0,0 +1,19 @@
+package com.xjrsoft;
+
+import lombok.Data;
+
+@Data
+public class TJarInfo {
+
+ private String name; //jar名称
+
+ private boolean custom;//开发jar包,需要强制更新
+
+ public TJarInfo(String name, boolean custom) {
+ super();
+ this.name = name;
+ this.custom = custom;
+ }
+
+
+}
diff --git a/itc-pcitc-dependencies/itc-pcitc-dependencies-api/pom.xml b/itc-pcitc-dependencies/itc-pcitc-dependencies-api/pom.xml
index 314a792..2ad025a 100644
--- a/itc-pcitc-dependencies/itc-pcitc-dependencies-api/pom.xml
+++ b/itc-pcitc-dependencies/itc-pcitc-dependencies-api/pom.xml
@@ -79,12 +79,8 @@
- org.apache.maven.plugins
- maven-compiler-plugin
-
- ${java.version}
- ${java.version}
-
+ com.geg
+ tanuki-compiler-maven-plugin
diff --git a/itc-pcitc-dependencies/itc-pcitc-dependencies-service/pom.xml b/itc-pcitc-dependencies/itc-pcitc-dependencies-service/pom.xml
index 53cc0a2..f0285b8 100644
--- a/itc-pcitc-dependencies/itc-pcitc-dependencies-service/pom.xml
+++ b/itc-pcitc-dependencies/itc-pcitc-dependencies-service/pom.xml
@@ -181,12 +181,8 @@
- org.apache.maven.plugins
- maven-compiler-plugin
-
- ${java.version}
- ${java.version}
-
+ com.geg
+ tanuki-compiler-maven-plugin
diff --git a/itc-pcitc-mdm/itc-pcitc-mdm-api/pom.xml b/itc-pcitc-mdm/itc-pcitc-mdm-api/pom.xml
index fc123c0..2183062 100644
--- a/itc-pcitc-mdm/itc-pcitc-mdm-api/pom.xml
+++ b/itc-pcitc-mdm/itc-pcitc-mdm-api/pom.xml
@@ -38,12 +38,8 @@
- org.apache.maven.plugins
- maven-compiler-plugin
-
- ${java.version}
- ${java.version}
-
+ com.geg
+ tanuki-compiler-maven-plugin
diff --git a/itc-pcitc-mdm/itc-pcitc-mdm-service/pom.xml b/itc-pcitc-mdm/itc-pcitc-mdm-service/pom.xml
index 7a5761b..4a04077 100644
--- a/itc-pcitc-mdm/itc-pcitc-mdm-service/pom.xml
+++ b/itc-pcitc-mdm/itc-pcitc-mdm-service/pom.xml
@@ -74,12 +74,8 @@
- org.apache.maven.plugins
- maven-compiler-plugin
-
- ${java.version}
- ${java.version}
-
+ com.geg
+ tanuki-compiler-maven-plugin
diff --git a/itc-pcitc-mdm/itc-pcitc-mdm-start/pom.xml b/itc-pcitc-mdm/itc-pcitc-mdm-start/pom.xml
index f966173..37601d5 100644
--- a/itc-pcitc-mdm/itc-pcitc-mdm-start/pom.xml
+++ b/itc-pcitc-mdm/itc-pcitc-mdm-start/pom.xml
@@ -18,6 +18,8 @@
${java.version}
${java.version}
docker.ges.bjgastx.com/itc-pcitc-mdm
+ ${project.build.finalName}-server.jar
+ pcitc-mdm-service
@@ -31,22 +33,6 @@
app
-
- org.springframework.boot
- spring-boot-maven-plugin
- 2.7.6
-
-
-
- repackage
-
-
-
- false
-
-
-
-
org.apache.maven.plugins
maven-surefire-plugin
@@ -62,29 +48,13 @@
${java.version}
+
+ com.geg
+ tanuki-boot-maven-plugin
+
com.spotify
docker-maven-plugin
- 1.2.2
-
- ${docker-registry}
- 600000
- ${docker-image-name}:${maven.build.timestamp}
- java
- ${dockerDirectory}
- ${docker-image-name}:${maven.build.timestamp}
- false
-
- ${docker-jar-name}
-
-
-
- /
- ${project.build.directory}
- ${docker-jar-name}
-
-
-