From 8952ee0aa88c7d8a19fd87a9494d84dbee112995 Mon Sep 17 00:00:00 2001 From: jianghao <332515344@qq.com> Date: Tue, 30 Dec 2025 13:26:46 +0800 Subject: [PATCH] Jenkins file edit --- Jenkinsfile | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 9972361..63d4a4c 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -238,15 +238,15 @@ def deployToEnvironmentWithCompose(String env) { // 根据部署环境替换后端服务地址 switch(env) { case 'dev': - // 开发环境可能使用特定的后端服务地址 + // 开发环境使用特定的后端服务地址 nginxConfContent = nginxConfContent.replaceAll('host.docker.internal:33333', 'dev-backend-service:33333') break case 'staging': - // 预发布环境可能使用特定的后端服务地址 + // 预发布环境使用特定的后端服务地址 nginxConfContent = nginxConfContent.replaceAll('host.docker.internal:33333', 'staging-backend-service:33333') break case 'prod': - // 生产环境可能使用特定的后端服务地址 + // 生产环境使用特定的后端服务地址 nginxConfContent = nginxConfContent.replaceAll('host.docker.internal:33333', 'prod-backend-service:33333') break default: @@ -257,24 +257,23 @@ def deployToEnvironmentWithCompose(String env) { // 写入环境特定的 nginx 配置 writeFile file: "nginx-${env}.conf", text: nginxConfContent - // 创建 docker-compose.yml 文件,前端服务连接到已存在的后端 - def composeFileContent = """version: '3.8' - services: - frontend: - image: ${imageToDeploy} - container_name: ${containerName} - restart: unless-stopped - ports: - - "${getPortForEnvironment(env)}:80" - extra_hosts: - - "host.docker.internal:host-gateway" # 兼容 Docker Desktop - networks: - - app-network + // 创建 docker-compose.yml 文件,使用卷挂载覆盖容器内的 nginx 配置 + def composeFileContent = """services: + frontend: + image: ${imageToDeploy} + container_name: ${containerName} + restart: unless-stopped + ports: + - "${getPortForEnvironment(env)}:80" + extra_hosts: + - "host.docker.internal:host-gateway" # 允许访问宿主机 + networks: + - app-network - networks: - app-network: - driver: bridge - """ +networks: + app-network: + driver: bridge +""" // 写入 docker-compose.yml 文件 writeFile file: 'docker-compose.yml', text: composeFileContent