From c2ff984c126bdb93f8085fa8667cd0ab8e9a48c9 Mon Sep 17 00:00:00 2001 From: lujianxin <2458505331@qq.com> Date: Mon, 23 Jun 2025 14:37:06 +0800 Subject: [PATCH 1/6] =?UTF-8?q?ci:=E9=87=8D=E6=9E=84=20Drone=20CI/CD=20?= =?UTF-8?q?=E6=B5=81=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 更新 .drone.yml 文件,增加多服务构建和部署步骤 - 修改 Dockerfile,简化为单层结构并直接运行 JAR 文件 - 新增 docker-compose.yml 文件,定义多服务部署配置 - 优化 CI/CD 流程,支持多服务同时构建和部署 --- .drone.yml | 66 +++++++++++++++++++++++++++------------------- Dockerfile | 14 ++-------- docker-compose.yml | 26 ++++++++++++++++++ 3 files changed, 67 insertions(+), 39 deletions(-) create mode 100644 docker-compose.yml diff --git a/.drone.yml b/.drone.yml index 3f420d2..3c1425e 100644 --- a/.drone.yml +++ b/.drone.yml @@ -3,40 +3,52 @@ type: docker name: ${serverName} # 服务名成,可与jar包名保持一致 steps: - - name: build-jar # 流水线名称 - image: maven:3.8.5-openjdk-17 # 定义创建容器的Docker镜像,基线项目使用jdk17 - volumes: # 将容器内目录挂载到宿主机,仓库需要开启Trusted设置 - - name: maven-cache - path: /root/.m2 # 将maven下载依赖的目录挂载出来,防止重复下载 - - name: maven-build - path: /home/app/build # 将应用打包好的Jar和执行脚本挂载出来 - commands: # 定义在Docker容器中执行的shell命令 - - mvn clean package -DskipTests=true # 应用打包命 - - cp ${executePath} /home/app/build/${serverName}.jar # 需要修改提取的jar包位置,默认当前在根项目的target目录下,jar包名与后续执行需保持一致 - - cp start.sh /home/app/build/ + + - name: build-jar + image: alpine + environment: + APP_VERSION: ${APP_VERSION} + volumes: + - name: build-output + path: /home/app/build + commands: + - mkdir -p /home/app/build/{gateway,system,infra} + - cp ruoyi-gateway/target/*.jar /home/app/build/gateway/app.jar + - cp ruoyi-modules-system/target/*.jar /home/app/build/system/app.jar + - cp yudao-module-infra/target/*.jar /home/app/build/file/app.jar - cp Dockerfile /home/app/build/ -# - cp .dockerignore /home/app/build/ - - cp docker.sh /home/app/build/ - name: build-docker image: docker - volumes: # 将容器内目录挂载到宿主机,仓库需要开启Trusted设置 - - name: maven-build - path: /home/app/build # 将应用打包好的Jar和执行脚本挂载出来 + environment: + APP_VERSION: ${APP_VERSION} + volumes: + - name: build-output + path: /home/app/build - name: docker - path: /var/run/docker.sock # 挂载宿主机的docker - settings: - dockerfile: /home/app/build/Dockerfile - commands: # 定义在Docker容器中执行的shell命令 + path: /var/run/docker.sock + commands: - cd /home/app/build - - chmod +x docker.sh - - sh docker.sh - - docker ps + - cd gateway && docker build -t ruoyi-gateway:${APP_VERSION} -f ../Dockerfile . + - cd ../system && docker build -t ruoyi-system:${APP_VERSION} -f ../Dockerfile . + - cd ../infra && docker build -t ruoyi-infra:${APP_VERSION} -f ../Dockerfile . -volumes: # 定义流水线挂载目录,用于共享数据 - - name: maven-build - host: - path: /home/data/maven/build # 从宿主机中挂载的目录 + - name: deploy-with-compose + image: docker/compose:1.29.2 + environment: + APP_VERSION: ${APP_VERSION} + volumes: + - name: build-output + path: /home/app/build + - name: docker + path: /var/run/docker.sock + commands: + - cd /home/app/build + - cp docker-compose.yml . + - sed -i "s/\${APP_VERSION}/${APP_VERSION}/g" docker-compose.yml + - docker-compose up -d + +volumes: - name: maven-cache host: path: /home/data/maven/cache diff --git a/Dockerfile b/Dockerfile index 3948ad8..d2a72cc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,18 +1,8 @@ # 目前制作docker镜像依赖的jdk,基线项目使用jdk17 FROM openjdk:17.0.2-oraclelinux8 -ENV SERVICE_PORTS=${innerPort} - -RUN mkdir -p /home/app/ - WORKDIR /home/app -COPY ./start.sh /home/app/ -# COPY ./.dockerignore /home/app/ -# jar包名,建议与docker.sh和drone配置文件的服务名一致 -COPY ./${serverName}.jar /home/app/ +COPY app.jar app.jar -RUN chmod 755 -R /home/app/ - - -ENTRYPOINT ["/home/app/start.sh"] +ENTRYPOINT ["java", "-jar", "app.jar", "--spring.profiles.active=prod"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..566c9f1 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,26 @@ +version: '3.8' + +services: + gateway: + image: ruoyi-gateway:${APP_VERSION} + container_name: ruoyi-gateway + ports: + - "48080:48080" + environment: + SPRING_PROFILES_ACTIVE: dev + + system: + image: ruoyi-system:${APP_VERSION} + container_name: ruoyi-system + ports: + - "48081:48081" + environment: + SPRING_PROFILES_ACTIVE: dev + + infra: + image: ruoyi-infra:${APP_VERSION} + container_name: ruoyi-infra + ports: + - "48082:48082" + environment: + SPRING_PROFILES_ACTIVE: dev \ No newline at end of file From 9389fee8bd96a5cc00380753120959d4276de2b2 Mon Sep 17 00:00:00 2001 From: lujianxin <2458505331@qq.com> Date: Mon, 23 Jun 2025 15:29:57 +0800 Subject: [PATCH 2/6] =?UTF-8?q?build:=E7=A7=BB=E9=99=A4=E7=8E=AF=E5=A2=83?= =?UTF-8?q?=E5=8F=98=E9=87=8F=E5=B9=B6=E5=85=B3=E9=97=AD=E6=BC=94=E7=A4=BA?= =?UTF-8?q?=E6=A8=A1=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 从 .drone.yml 中移除了 APP_VERSION 环境变量 -将 yudao-module-infra 的演示模式设置为 false --- .drone.yml | 4 ---- .../src/main/resources/application-dev.yaml | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/.drone.yml b/.drone.yml index 3c1425e..60ee08c 100644 --- a/.drone.yml +++ b/.drone.yml @@ -6,8 +6,6 @@ steps: - name: build-jar image: alpine - environment: - APP_VERSION: ${APP_VERSION} volumes: - name: build-output path: /home/app/build @@ -20,8 +18,6 @@ steps: - name: build-docker image: docker - environment: - APP_VERSION: ${APP_VERSION} volumes: - name: build-output path: /home/app/build diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/application-dev.yaml b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/application-dev.yaml index 15bce30..751d660 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/application-dev.yaml +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/application-dev.yaml @@ -127,4 +127,4 @@ spring: # 芋道配置项,设置当前项目所有自定义的配置 yudao: - demo: true # 开启演示模式 + demo: false # 开启演示模式 From e720e17d761d94cb0e2ef684f393ecaa49d33bf8 Mon Sep 17 00:00:00 2001 From: lujianxin <2458505331@qq.com> Date: Mon, 23 Jun 2025 18:00:12 +0800 Subject: [PATCH 3/6] =?UTF-8?q?ci(drone):=20=E6=9B=B4=E6=96=B0=E6=9E=84?= =?UTF-8?q?=E5=BB=BA=E9=85=8D=E7=BD=AE=E4=BB=A5=E6=94=AF=E6=8C=81=20Maven?= =?UTF-8?q?=20=E6=9E=84=E5=BB=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增 maven-build 步骤,使用 Maven 进行项目构建- 更新 build-jar 步骤中的 JAR 文件路径 -优化构建流程,提高构建效率 --- .drone.yml | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/.drone.yml b/.drone.yml index 60ee08c..2bd7f8c 100644 --- a/.drone.yml +++ b/.drone.yml @@ -4,6 +4,16 @@ name: ${serverName} # 服务名成,可与jar包名保持一致 steps: + - name: maven-build + image: maven:3.8.5-openjdk-17 + volumes: + - name: maven-cache + path: /root/.m2 + - name: build-output + path: /home/app/build + commands: + - mvn clean package -DskipTests=true -pl yudao-gateway,ruoyi-modules-system,yudao-module-infra -am + - name: build-jar image: alpine volumes: @@ -11,8 +21,8 @@ steps: path: /home/app/build commands: - mkdir -p /home/app/build/{gateway,system,infra} - - cp ruoyi-gateway/target/*.jar /home/app/build/gateway/app.jar - - cp ruoyi-modules-system/target/*.jar /home/app/build/system/app.jar + - cp yudao-gateway/target/*.jar /home/app/build/gateway/app.jar + - cp yudao-modules-system/target/*.jar /home/app/build/system/app.jar - cp yudao-module-infra/target/*.jar /home/app/build/file/app.jar - cp Dockerfile /home/app/build/ From a8c3996cfa83a428dfd017ccf74279e0f73168b1 Mon Sep 17 00:00:00 2001 From: lujianxin <2458505331@qq.com> Date: Tue, 24 Jun 2025 09:12:19 +0800 Subject: [PATCH 4/6] =?UTF-8?q?build(drone):=20=E6=9B=B4=E6=96=B0=20Drone?= =?UTF-8?q?=20=E6=9E=84=E5=BB=BA=E9=85=8D=E7=BD=AE=E5=92=8C=20Docker=20?= =?UTF-8?q?=E9=83=A8=E7=BD=B2=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修改 .drone.yml 中的 Maven 构建命令,使用新的模块路径 - 更新模块路径为 yudao-module-system/yudao-module-system-biz 和 yudao-module-infra/yudao-module-infra-biz - 修改 Docker 镜像名称,使用 yudao 前缀替代 ruoyi - 更新 docker-compose.yml 中的服务定义,使用新的镜像名称和容器名称 --- .drone.yml | 14 +++++++------- docker-compose.yml | 12 ++++++------ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/.drone.yml b/.drone.yml index 2bd7f8c..92c30b4 100644 --- a/.drone.yml +++ b/.drone.yml @@ -12,7 +12,7 @@ steps: - name: build-output path: /home/app/build commands: - - mvn clean package -DskipTests=true -pl yudao-gateway,ruoyi-modules-system,yudao-module-infra -am + - mvn clean package -DskipTests=true -pl yudao-gateway,yudao-module-system/yudao-module-system-biz,yudao-module-infra/yudao-module-infra-biz -am - name: build-jar image: alpine @@ -21,9 +21,9 @@ steps: path: /home/app/build commands: - mkdir -p /home/app/build/{gateway,system,infra} - - cp yudao-gateway/target/*.jar /home/app/build/gateway/app.jar - - cp yudao-modules-system/target/*.jar /home/app/build/system/app.jar - - cp yudao-module-infra/target/*.jar /home/app/build/file/app.jar + - cp yudao-gateway/target/yudao-gateway.jar /home/app/build/gateway/app.jar + - cp yudao-module-system/yudao-module-system-biz/target/yudao-module-system-biz.jar /home/app/build/system/app.jar + - cp yudao-module-infra/yudao-module-infra-biz/target//yudao-module-infra-biz.jar /home/app/build/infra/app.jar - cp Dockerfile /home/app/build/ - name: build-docker @@ -35,9 +35,9 @@ steps: path: /var/run/docker.sock commands: - cd /home/app/build - - cd gateway && docker build -t ruoyi-gateway:${APP_VERSION} -f ../Dockerfile . - - cd ../system && docker build -t ruoyi-system:${APP_VERSION} -f ../Dockerfile . - - cd ../infra && docker build -t ruoyi-infra:${APP_VERSION} -f ../Dockerfile . + - cd gateway && docker build -t yudao-gateway:${APP_VERSION} -f ../Dockerfile . + - cd ../system && docker build -t yudao-module-system:${APP_VERSION} -f ../Dockerfile . + - cd ../infra && docker build -t yudao-module-infra:${APP_VERSION} -f ../Dockerfile . - name: deploy-with-compose image: docker/compose:1.29.2 diff --git a/docker-compose.yml b/docker-compose.yml index 566c9f1..9f5b6fc 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,24 +2,24 @@ version: '3.8' services: gateway: - image: ruoyi-gateway:${APP_VERSION} - container_name: ruoyi-gateway + image: yudao-gateway:${APP_VERSION} + container_name: yudao-gatewa ports: - "48080:48080" environment: SPRING_PROFILES_ACTIVE: dev system: - image: ruoyi-system:${APP_VERSION} - container_name: ruoyi-system + image: yudao-module-system:${APP_VERSION} + container_name: yudao-module-system ports: - "48081:48081" environment: SPRING_PROFILES_ACTIVE: dev infra: - image: ruoyi-infra:${APP_VERSION} - container_name: ruoyi-infra + image: yudao-module-infra:${APP_VERSION} + container_name: yudao-module-infra ports: - "48082:48082" environment: From fb6853f57c91a00a6a14c3c50aad123be42d782a Mon Sep 17 00:00:00 2001 From: lujianxin <2458505331@qq.com> Date: Tue, 24 Jun 2025 18:10:14 +0800 Subject: [PATCH 5/6] =?UTF-8?q?ci(drone):=20=E4=BC=98=E5=8C=96=20Drone?= =?UTF-8?q?=E6=9E=84=E5=BB=BA=E6=B5=81=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 重构构建步骤,提高流程清晰度 - 添加文件存在性检查和错误处理,增强构建鲁棒性 - 优化目录结构创建方式 - 更新 Docker 镜像构建步骤 - 调整 Docker Compose 文件处理方式 - 移除未使用的触发配置 --- .drone.yml | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/.drone.yml b/.drone.yml index 92c30b4..2b9d785 100644 --- a/.drone.yml +++ b/.drone.yml @@ -12,21 +12,26 @@ steps: - name: build-output path: /home/app/build commands: + - cd /drone/src - mvn clean package -DskipTests=true -pl yudao-gateway,yudao-module-system/yudao-module-system-biz,yudao-module-infra/yudao-module-infra-biz -am - - name: build-jar + - name: copy-jars image: alpine volumes: - name: build-output path: /home/app/build commands: - - mkdir -p /home/app/build/{gateway,system,infra} - - cp yudao-gateway/target/yudao-gateway.jar /home/app/build/gateway/app.jar - - cp yudao-module-system/yudao-module-system-biz/target/yudao-module-system-biz.jar /home/app/build/system/app.jar - - cp yudao-module-infra/yudao-module-infra-biz/target//yudao-module-infra-biz.jar /home/app/build/infra/app.jar + - mkdir -p /home/app/build/gateway + - mkdir -p /home/app/build/system + - mkdir -p /home/app/build/infra + - ls -l yudao-gateway/target/ # 检查源文件是否存在 + - cp yudao-gateway/target/yudao-gateway.jar /home/app/build/gateway/app.jar || echo "Failed to copy gateway jar" + - cp yudao-module-system/yudao-module-system-biz/target/yudao-module-system-biz.jar /home/app/build/system/app.jar || echo "Failed to copy system biz jar" + - cp yudao-module-infra/yudao-module-infra-biz/target/yudao-module-infra-biz.jar /home/app/build/infra/app.jar || echo "Failed to copy infra biz jar" - cp Dockerfile /home/app/build/ + - cp docker-compose.yml /home/app/build/ - - name: build-docker + - name: build-docker-images image: docker volumes: - name: build-output @@ -50,20 +55,16 @@ steps: path: /var/run/docker.sock commands: - cd /home/app/build - - cp docker-compose.yml . - - sed -i "s/\${APP_VERSION}/${APP_VERSION}/g" docker-compose.yml - - docker-compose up -d + - sed -i "s/${APP_VERSION}/${APP_VERSION}/g" docker-compose.yml + - docker-compose -f docker-compose.yml up -d volumes: - name: maven-cache host: path: /home/data/maven/cache + - name: build-output + host: + path: /home/data/maven/build - name: docker host: - path: /var/run/docker.sock - -#trigger: -# event: -# - custom -# ref: -# - refs/tags/version1.1 + path: /var/run/docker.sock \ No newline at end of file From 9676cb02d5e9f1b7c023977b386e9ad7f564c1d6 Mon Sep 17 00:00:00 2001 From: lujianxin <2458505331@qq.com> Date: Wed, 25 Jun 2025 10:33:43 +0800 Subject: [PATCH 6/6] =?UTF-8?q?ci:=E4=BC=98=E5=8C=96=20Docker=20=E9=83=A8?= =?UTF-8?q?=E7=BD=B2=E6=B5=81=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加步骤停止和删除现有容器及镜像 - 修正 docker-compose.yml 中的容器名称 - 更改 Dockerfile 中的 Spring 配置文件 --- .drone.yml | 15 +++++++++++++++ Dockerfile | 2 +- docker-compose.yml | 2 +- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/.drone.yml b/.drone.yml index 2b9d785..b098f43 100644 --- a/.drone.yml +++ b/.drone.yml @@ -39,6 +39,21 @@ steps: - name: docker path: /var/run/docker.sock commands: + - # 停止容器(如果存在) + - docker inspect --type=container yudao-gateway >/dev/null 2>&1 && docker stop yudao-gateway || true + - docker inspect --type=container yudao-module-system >/dev/null 2>&1 && docker stop yudao-module-system || true + - docker inspect --type=container yudao-module-infra >/dev/null 2>&1 && docker stop yudao-module-infra || true + + - # 删除容器(如果存在) + - docker inspect --type=container yudao-gateway >/dev/null 2>&1 && docker rm yudao-gateway || true + - docker inspect --type=container yudao-module-system >/dev/null 2>&1 && docker rm yudao-module-system || true + - docker inspect --type=container yudao-module-infra >/dev/null 2>&1 && docker rm yudao-module-infra || true + + - # 删除镜像(如果存在) + - docker inspect --type=image yudao-gateway >/dev/null 2>&1 && docker rmi yudao-gateway || true + - docker inspect --type=image yudao-module-system >/dev/null 2>&1 && docker rmi yudao-module-system || true + - docker inspect --type=image yudao-module-infra >/dev/null 2>&1 && docker rmi yudao-module-infra || true + - cd /home/app/build - cd gateway && docker build -t yudao-gateway:${APP_VERSION} -f ../Dockerfile . - cd ../system && docker build -t yudao-module-system:${APP_VERSION} -f ../Dockerfile . diff --git a/Dockerfile b/Dockerfile index d2a72cc..3393a02 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,4 +5,4 @@ WORKDIR /home/app COPY app.jar app.jar -ENTRYPOINT ["java", "-jar", "app.jar", "--spring.profiles.active=prod"] +ENTRYPOINT ["java", "-jar", "app.jar", "--spring.profiles.active=dev"] diff --git a/docker-compose.yml b/docker-compose.yml index 9f5b6fc..245d54d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,7 +3,7 @@ version: '3.8' services: gateway: image: yudao-gateway:${APP_VERSION} - container_name: yudao-gatewa + container_name: yudao-gateway ports: - "48080:48080" environment: