From 28b3da70053672e09490c8725bf795d1d49526bd Mon Sep 17 00:00:00 2001 From: Doubleyin <953994191@qq.com> Date: Mon, 29 Sep 2025 00:10:22 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=9E=84=E5=BB=BA=E6=B5=81?= =?UTF-8?q?=E7=A8=8B=EF=BC=8C=E9=87=87=E7=94=A8=E7=BB=9F=E4=B8=80=E6=A0=87?= =?UTF-8?q?=E5=87=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitea/workflows/deploy.yml | 19 ++------- Dockerfile | 3 -- Dockerfile.ci | 4 -- ci-cd-deploy.yml | 49 ----------------------- deploy.yml | 19 ++++----- docker-compose-dev.yml | 19 --------- docker-compose.yml | 23 ----------- src/main/resources/application-dev.yml | 16 -------- src/main/resources/application-prod.yml | 20 --------- src/main/resources/application.properties | 11 ++++- src/main/resources/application.yml | 16 -------- 11 files changed, 22 insertions(+), 177 deletions(-) delete mode 100644 ci-cd-deploy.yml delete mode 100644 docker-compose-dev.yml delete mode 100644 docker-compose.yml delete mode 100644 src/main/resources/application-dev.yml delete mode 100644 src/main/resources/application-prod.yml delete mode 100644 src/main/resources/application.yml diff --git a/.gitea/workflows/deploy.yml b/.gitea/workflows/deploy.yml index 58f8f46..64ff35e 100644 --- a/.gitea/workflows/deploy.yml +++ b/.gitea/workflows/deploy.yml @@ -53,6 +53,7 @@ jobs: - name: 运行测试 run: mvn test + - name: 构建 Docker 镜像 run: | # 使用 Dockerfile 构建镜像 @@ -87,22 +88,8 @@ jobs: sudo mkdir -p /etc/ssl/certs sudo chown $USER:$USER /app/logs 2>/dev/null || true - echo "启动新容器..." - docker run -d \ - --name light-delivery-container \ - --restart=unless-stopped \ - --log-opt max-size=10m \ - --log-opt max-file=3 \ - -p 8080:8080 \ - -p 8443:8443 \ - -e SPRING_PROFILES_ACTIVE=prod \ - -e SPRING_DATASOURCE_URL=jdbc:mysql://115.190.121.151:3306/light_delivery?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true \ - -e SPRING_DATASOURCE_USERNAME=double \ - -e SPRING_DATASOURCE_PASSWORD="${{ secrets.DB_PASSWORD }}" \ - -e JAVA_OPTS="-Xmx512m -Xms256m -Djava.security.egd=file:/dev/./urandom" \ - -v /app/logs:/app/logs \ - -v /etc/ssl/certs:/etc/ssl/certs:ro \ - light-delivery-app:latest + echo "使用统一的部署配置启动新容器..." + docker-compose -f deploy.yml up -d - name: 等待应用启动并健康检查 run: | diff --git a/Dockerfile b/Dockerfile index 5986ab8..e67e500 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,8 +11,5 @@ COPY target/light-delivery-1.0.0.jar app.jar EXPOSE 8080 EXPOSE 8443 -# 设置环境变量 -ENV SPRING_PROFILES_ACTIVE=prod - # 启动应用 ENTRYPOINT ["java", "-jar", "app.jar"] \ No newline at end of file diff --git a/Dockerfile.ci b/Dockerfile.ci index cff3a8d..90ffc89 100644 --- a/Dockerfile.ci +++ b/Dockerfile.ci @@ -15,9 +15,5 @@ USER spring:spring EXPOSE 8080 EXPOSE 8443 -# 设置环境变量 -ENV SPRING_PROFILES_ACTIVE=prod -ENV JAVA_OPTS="-Xmx512m" - # 启动应用 ENTRYPOINT ["sh", "-c", "java $JAVA_OPTS -jar app.jar"] \ No newline at end of file diff --git a/ci-cd-deploy.yml b/ci-cd-deploy.yml deleted file mode 100644 index 554bb0f..0000000 --- a/ci-cd-deploy.yml +++ /dev/null @@ -1,49 +0,0 @@ -# CI/CD Pipeline Deployment Configuration -version: '3.8' - -# 构建阶段配置 -services: - # 构建服务 - 用于在 CI/CD 环境中构建镜像 - builder: - image: maven:3.8-openjdk-17 - working_dir: /app - volumes: - - .:/app - - ~/.m2:/root/.m2 # Maven 缓存 - environment: - - MAVEN_OPTS=-Xmx1024m - command: > - bash -c " - mvn clean package -DskipTests && - mvn jib:build -Djib.to.image=light-delivery-app:$${BUILD_NUMBER:-latest} -Djib.allowInsecureRegistries=true - " - - # 应用服务 - 实际部署的服务 - light-delivery-app: - image: light-delivery-app:${IMAGE_TAG:-latest} - container_name: light-delivery-app - ports: - - "8080:8080" - - "8443:8443" - environment: - - SPRING_PROFILES_ACTIVE=prod - - SPRING_DATASOURCE_URL=jdbc:mysql://115.190.121.151:3306/light_delivery?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true - - SPRING_DATASOURCE_USERNAME=double - - SPRING_DATASOURCE_PASSWORD=Hu@ng1998! - - JAVA_OPTS=-Xmx512m - - SERVER_PORT=8080 - volumes: - - /etc/ssl/certs:/etc/ssl/certs - restart: unless-stopped - networks: - - light-network - healthcheck: - test: ["CMD", "curl", "-f", "http://localhost:8080/actuator/health"] - interval: 30s - timeout: 10s - retries: 3 - start_period: 60s - -networks: - light-network: - driver: bridge \ No newline at end of file diff --git a/deploy.yml b/deploy.yml index 78cade1..1b5f206 100644 --- a/deploy.yml +++ b/deploy.yml @@ -3,22 +3,23 @@ version: '3.8' services: light-delivery-app: - # 使用云端 CI/CD 构建的镜像 - image: light-delivery-app:${IMAGE_TAG:-latest} - container_name: light-delivery-app + image: light-delivery-app:latest + container_name: light-delivery-container ports: - "8080:8080" - "8443:8443" environment: - - SPRING_PROFILES_ACTIVE=prod - - SPRING_DATASOURCE_URL=jdbc:mysql://115.190.121.151:3306/light_delivery?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true - - SPRING_DATASOURCE_USERNAME=double - SPRING_DATASOURCE_PASSWORD=Hu@ng1998! - - JAVA_OPTS=-Xmx512m - - SERVER_PORT=8080 + - KEY_STORE_PASSWORD=BIKEWZzBVN2J volumes: - - /etc/ssl/certs:/etc/ssl/certs + - /app/logs:/app/logs + - /etc/ssl/certs:/etc/ssl/certs:ro restart: unless-stopped + logging: + driver: "json-file" + options: + max-size: "10m" + max-file: "3" networks: - light-network healthcheck: diff --git a/docker-compose-dev.yml b/docker-compose-dev.yml deleted file mode 100644 index 8f0e975..0000000 --- a/docker-compose-dev.yml +++ /dev/null @@ -1,19 +0,0 @@ -services: - app: - build: . - container_name: light-delivery-app-dev - ports: - - "8080:8080" - environment: - - SPRING_PROFILES_ACTIVE=dev - - SPRING_DATASOURCE_URL=jdbc:mysql://115.190.121.151:3306/light_delivery?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true - - SPRING_DATASOURCE_USERNAME=double - - SPRING_DATASOURCE_PASSWORD=Hu@ng1998! - - JAVA_OPTS=-Xmx512m - restart: unless-stopped - networks: - - light-network - -networks: - light-network: - driver: bridge \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml deleted file mode 100644 index ce17e39..0000000 --- a/docker-compose.yml +++ /dev/null @@ -1,23 +0,0 @@ -services: - app: - build: . - container_name: light-delivery-app - ports: - - "443:443" - - "80:80" - environment: - - SPRING_PROFILES_ACTIVE=prod - - SPRING_DATASOURCE_URL=jdbc:mysql://115.190.121.151:3306/light_delivery?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true - - SPRING_DATASOURCE_USERNAME=double - - SPRING_DATASOURCE_PASSWORD=Hu@ng1998! - - JAVA_OPTS=-Xmx512m - - KEY_STORE_PASSWORD=changeit - volumes: - - /etc/ssl/certs:/etc/ssl/certs - restart: unless-stopped - networks: - - light-network - -networks: - light-network: - driver: bridge \ No newline at end of file diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml deleted file mode 100644 index 0e05357..0000000 --- a/src/main/resources/application-dev.yml +++ /dev/null @@ -1,16 +0,0 @@ -# 开发环境配置 -server: - port: 8080 - -spring: - application: - name: light-delivery-backend-dev - -logging: - level: - com.light.delivery: DEBUG - -# JWT配置 -jwt: - secret: lightDeliveryDevSecretKey - expiration: 86400 \ No newline at end of file diff --git a/src/main/resources/application-prod.yml b/src/main/resources/application-prod.yml deleted file mode 100644 index b3307a1..0000000 --- a/src/main/resources/application-prod.yml +++ /dev/null @@ -1,20 +0,0 @@ -# 生产环境配置 -server: - port: 443 - ssl: - key-store-type: PKCS12 - key-store: /etc/ssl/certs/www.doubleyin.cn.pfx - key-store-password: ${KEY_STORE_PASSWORD} - -spring: - application: - name: light-delivery-backend-prod - -logging: - level: - com.light.delivery: INFO - -# JWT配置 -jwt: - secret: lightDeliveryProdSecretKey - expiration: 86400 \ No newline at end of file diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index e9439bf..3fd59f7 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,4 +1,11 @@ spring.application.name=Light +# 服务器端口配置 +server.port=443 + +# SSL配置 +server.ssl.key-store-type=PKCS12 +server.ssl.key-store=/etc/ssl/certs/www.doubleyin.cn.pfx +server.ssl.key-store-password=${KEY_STORE_PASSWORD} # --- MySQL Database Configuration (Remote Server) --- spring.datasource.url=jdbc:mysql://115.190.121.151:3306/light_delivery?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true @@ -31,8 +38,8 @@ wx.api.access-token-url=https://api.weixin.qq.com/cgi-bin/token?grant_type=clien wx.api.code2session-url=https://api.weixin.qq.com/sns/jscode2session # Logging Configuration -logging.level.com.light.delivery.config=DEBUG +logging.level.com.light.delivery=INFO # JWT Configuration -jwt.secret=R/GuND+mK487AS+bUW5uqGmt5dyCkPf3g+uRdxHBY1eYEhxxG1cNgnfrk0l+vv+Xi8werl4P2lDAs0gaiqAqRA== +jwt.secret=lightDeliveryProdSecretKey jwt.expiration=86400 \ No newline at end of file diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml deleted file mode 100644 index 714dbf3..0000000 --- a/src/main/resources/application.yml +++ /dev/null @@ -1,16 +0,0 @@ -# 默认配置 -spring: - profiles: - active: dev - -server: - port: 8080 - -logging: - level: - com.light.delivery: DEBUG - -# JWT配置 -jwt: - secret: lightDeliverySecretKey - expiration: 86400 \ No newline at end of file