Jenkins file edit
Some checks failed
test/timeline-frontend/pipeline/head There was a failure building this commit
Some checks failed
test/timeline-frontend/pipeline/head There was a failure building this commit
This commit is contained in:
41
Jenkinsfile
vendored
41
Jenkinsfile
vendored
@@ -228,36 +228,12 @@ pipeline {
|
|||||||
// 公共函数定义
|
// 公共函数定义
|
||||||
def deployToEnvironmentWithCompose(String env) {
|
def deployToEnvironmentWithCompose(String env) {
|
||||||
script {
|
script {
|
||||||
// 根据环境设置部署参数
|
// 根据环境设置部署参数,确保容器名称合法
|
||||||
def containerName = "${PROJECT_NAME}-${env}"
|
def cleanEnv = env.replaceAll('[^a-zA-Z0-9]', '-')
|
||||||
|
def containerName = "${PROJECT_NAME}-${cleanEnv}".replaceAll('[^a-zA-Z0-9_.-]', '')
|
||||||
def imageToDeploy = "${DOCKER_IMAGE}:latest"
|
def imageToDeploy = "${DOCKER_IMAGE}:latest"
|
||||||
|
|
||||||
// 读取原始 nginx 配置
|
// 创建 docker-compose.yml 文件,使用 host 网络模式以便访问宿主机上的后端服务
|
||||||
def nginxConfContent = readFile('nginx.conf')
|
|
||||||
|
|
||||||
// 根据部署环境替换后端服务地址
|
|
||||||
// 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:
|
|
||||||
// // 默认使用生产环境后端服务
|
|
||||||
// nginxConfContent = nginxConfContent.replaceAll('host.docker.internal:33333', 'prod-backend-service:33333')
|
|
||||||
// }
|
|
||||||
|
|
||||||
// 写入环境特定的 nginx 配置
|
|
||||||
writeFile file: "nginx-${env}.conf", text: nginxConfContent
|
|
||||||
|
|
||||||
// 创建 docker-compose.yml 文件,使用卷挂载覆盖容器内的 nginx 配置
|
|
||||||
def composeFileContent = """services:
|
def composeFileContent = """services:
|
||||||
frontend:
|
frontend:
|
||||||
image: ${imageToDeploy}
|
image: ${imageToDeploy}
|
||||||
@@ -265,14 +241,7 @@ def deployToEnvironmentWithCompose(String env) {
|
|||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
ports:
|
ports:
|
||||||
- "${getPortForEnvironment(env)}:80"
|
- "${getPortForEnvironment(env)}:80"
|
||||||
extra_hosts:
|
network_mode: "host"
|
||||||
- "host.docker.internal:host-gateway" # 允许访问宿主机
|
|
||||||
networks:
|
|
||||||
- app-network
|
|
||||||
|
|
||||||
networks:
|
|
||||||
app-network:
|
|
||||||
driver: bridge
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
// 写入 docker-compose.yml 文件
|
// 写入 docker-compose.yml 文件
|
||||||
|
|||||||
Reference in New Issue
Block a user