From c924ee7bb7a615a5ea39a0b466854f138594bacb Mon Sep 17 00:00:00 2001 From: XinWei <2718030729@qq.com> Date: Fri, 30 Aug 2024 11:23:38 +0800 Subject: [PATCH] =?UTF-8?q?datacenter=E6=9E=84=E5=BB=BA=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .drone-datacenter.yml | 94 +------------------ .../ludu-module-datacenter-biz/Dockerfile | 2 +- .../ludu-module-datacenter-biz/run.sh | 6 +- .../framework/nacos/config/BeanInit.java | 33 +++---- 4 files changed, 26 insertions(+), 109 deletions(-) diff --git a/.drone-datacenter.yml b/.drone-datacenter.yml index 611e5c90a..13c84ba48 100644 --- a/.drone-datacenter.yml +++ b/.drone-datacenter.yml @@ -2,80 +2,11 @@ kind: pipeline # 定义对象类型,还有secret和signature两种类型 type: docker # 定义流水线类型,还有kubernetes、exec、ssh等类型 -name: ludu-system-drone # 定义流水线名称 +name: ludu-datacenter-drone # 定义流水线名称 steps: # 定义流水线执行步骤,这些步骤将顺序执行 -# - name: package # 流水线名称 -# -# image: maven:3-jdk-8 # 定义创建容器的Docker镜像 -# -# volumes: # 将容器内目录挂载到宿主机,仓库需要开启Trusted设置 -# -# - name: maven-cache -# -# path: /root/.m2 # 将maven下载依赖的目录挂载出来,防止重复下载 -# -# - name: maven-build -# -# path: /app/build # 将应用打包好的Jar和执行脚本挂载出来 -# -# commands: # 定义在Docker容器中执行的shell命令 -# -# - mvn package -Dmaven.test.skip=true # 应用打包命令 -# - mkdir -p /app/build/ludu-module-datacenter/target -# - cp ./ludu-module-datacenter/ludu-module-datacenter-biz/target/ludu-module-datacenter-biz.jar /app/build/ludu-module-datacenter/target -# - cp ./ludu-module-datacenter/ludu-module-datacenter-biz/Dockerfile /app/build/ludu-module-datacenter -# - cp ./ludu-module-datacenter/ludu-module-datacenter-biz/run.sh /app/build/ludu-module-datacenter -# -# - name: copy-to-object # 构建基础模块和复制票务停车场到轮渡服务器 -# -# image: appleboy/drone-ssh # SSH工具镜像 -# -# settings: -# -# host: 101.43.112.107 # 远程连接地址 -# -# username: root # 远程连接账号 -# -# password: -# -# from_secret: ssh_password # 从Secret中读取SSH密码 -# -# port: 22 # 远程连接端口 -# -# command_timeout: 15m # 远程执行命令超时时间 -# -# script: -# -# - scp -r /ludu/maven/build/ludu-module-datacenter root@120.46.37.243:/ludu/maven/build -# - echo "datacenter done" -# -# - name: build-old-service -# -# image: appleboy/drone-ssh # SSH工具镜像 -# -# settings: -# -# host: 120.46.37.243 # 远程连接地址 -# -# username: root # 远程连接账号 -# -# password: -# -# from_secret: ssh_password2 # 从Secret中读取SSH密码 -# -# port: 22 # 远程连接端口 -# -# command_timeout: 5m # 远程执行命令超时时间 -# -# script: -# -# - cd /ludu/maven/build/ludu-module-datacenter/ -# - chmod +x ./run.sh # 更改为可执行脚本 -# - ./run.sh || echo "ludu-module-datacenter build failed" # 运行脚本打包应用镜像并运行 - - name: build-new-service image: appleboy/drone-ssh # SSH工具镜像 @@ -97,22 +28,7 @@ steps: # 定义流水线执行步骤,这些步骤将顺序执行 script: | cd /root/ludu-cloud git pull origin master - rm -f ludu-module-datacenter/ludu-module-datacenter-biz/src/main/java/cn/iocoder/yudao/module/datacenter/framework/nacos/config/BeanInit.java - /root/apache-maven-3.9.4/bin/mvn clean package -Dmaven.test.skip=true - port=48092 # 指定端口号 - pid=$(lsof -t -i:$port) # 获取占用指定端口的进程号 - if [ -n "$pid" ]; then - echo "Killing process $pid" - kill -9 $pid - fi - nohup java -jar ludu-module-datacenter/ludu-module-datacenter-biz/target/ludu-module-datacenter-biz.jar --spring.profiles.active=dev > api.log & - -volumes: # 定义流水线挂载目录,用于共享数据 - - - name: maven-build - host: - path: /ludu/maven/build # 从宿主机中挂载的目录 - - - name: maven-cache - host: - path: /ludu/maven/cache # 从宿主机中挂载的目录 \ No newline at end of file + /root/apache-maven-3.9.4/bin/mvn package -Dmaven.test.skip=true + cd ludu-module-datacenter/ludu-module-datacenter-biz/ + chmod +x run.sh + ./run.sh || echo "ludu-module-datacenter build failed" \ No newline at end of file diff --git a/ludu-module-datacenter/ludu-module-datacenter-biz/Dockerfile b/ludu-module-datacenter/ludu-module-datacenter-biz/Dockerfile index aa87bcfe0..031bd5e4a 100644 --- a/ludu-module-datacenter/ludu-module-datacenter-biz/Dockerfile +++ b/ludu-module-datacenter/ludu-module-datacenter-biz/Dockerfile @@ -1,6 +1,6 @@ ## AdoptOpenJDK 停止发布 OpenJDK 二进制,而 Eclipse Temurin 是它的延伸,提供更好的稳定性 ## 感谢复旦核博士的建议!灰子哥,牛皮! -FROM eclipse-temurin:8-jre +FROM openjdk:8-jre ## 创建目录,并使用它作为工作目录 RUN mkdir -p /ludu-module-datacenter-biz diff --git a/ludu-module-datacenter/ludu-module-datacenter-biz/run.sh b/ludu-module-datacenter/ludu-module-datacenter-biz/run.sh index b29dd32c6..fa2f00df5 100644 --- a/ludu-module-datacenter/ludu-module-datacenter-biz/run.sh +++ b/ludu-module-datacenter/ludu-module-datacenter-biz/run.sh @@ -1,6 +1,6 @@ -app_name='ludu-module-datacenter2' +app_name='ludu-module-datacenter1' # 定义应用版本 -app_version='2.0.0' +app_version='1.0.0' # 定义应用环境 #profile_active='prod' echo '----stop container----' @@ -13,4 +13,4 @@ docker rmi ${app_name}:${app_version} echo '----build image----' docker buildx build -f Dockerfile -t ${app_name}:${app_version} . echo '----start container----' -docker run -d -p 9091:48092 --name ${app_name} ${app_name}:${app_version} \ No newline at end of file +docker run -d -p 48092:48092 --name ${app_name} ${app_name}:${app_version} \ No newline at end of file diff --git a/ludu-module-datacenter/ludu-module-datacenter-biz/src/main/java/cn/iocoder/yudao/module/datacenter/framework/nacos/config/BeanInit.java b/ludu-module-datacenter/ludu-module-datacenter-biz/src/main/java/cn/iocoder/yudao/module/datacenter/framework/nacos/config/BeanInit.java index 5b4c0fae6..6a434e252 100644 --- a/ludu-module-datacenter/ludu-module-datacenter-biz/src/main/java/cn/iocoder/yudao/module/datacenter/framework/nacos/config/BeanInit.java +++ b/ludu-module-datacenter/ludu-module-datacenter-biz/src/main/java/cn/iocoder/yudao/module/datacenter/framework/nacos/config/BeanInit.java @@ -9,24 +9,25 @@ import org.springframework.context.annotation.Primary; import java.net.InetAddress; import java.net.UnknownHostException; -@Configuration +// TODO 由于datacenter走网关内网,不指定外网IP和端口,自动获取本地 +//@Configuration public class BeanInit { /** * 用于改变程序自动获取的本机ip */ - @Value("${spring.profiles.active}") - private String activeEnv; - @Bean - @Primary - public NacosDiscoveryProperties nacosProperties() throws UnknownHostException { - NacosDiscoveryProperties nacosDiscoveryProperties = new NacosDiscoveryProperties(); - if ("dev".equals(activeEnv)){ - // 直接指定域名 - String customIp = "120.46.37.243"; // 替换为你的域名 - int customPort = 9091; // 替换为你的端口 - nacosDiscoveryProperties.setIp(customIp); - nacosDiscoveryProperties.setPort(customPort); - } - return nacosDiscoveryProperties; - } +// @Value("${spring.profiles.active}") +// private String activeEnv; +// @Bean +// @Primary +// public NacosDiscoveryProperties nacosProperties() throws UnknownHostException { +// NacosDiscoveryProperties nacosDiscoveryProperties = new NacosDiscoveryProperties(); +// if ("dev".equals(activeEnv)){ +// // 直接指定域名 +// String customIp = "120.46.37.243"; // 替换为你的域名 +// int customPort = 9091; // 替换为你的端口 +// nacosDiscoveryProperties.setIp(customIp); +// nacosDiscoveryProperties.setPort(customPort); +// } +// return nacosDiscoveryProperties; +// } }