跟新 nginx 流量切换方式
This commit is contained in:
Vendored
+4
-4
@@ -60,9 +60,7 @@ pipeline {
|
||||
echo "传输文件到目标服务器"
|
||||
sh "${SSH_CMD} 'mkdir -p ${REMOTE_DIR}'"
|
||||
sh "${SCP_CMD} ${IMAGE_NAME}.tar ${DEPLOY_USER}@${DEPLOY_HOST}:${REMOTE_DIR}/"
|
||||
// 传输 nginx.conf(用 cat 写入保持 inode,避免 bind mount 失效)
|
||||
sh "${SCP_CMD} nginx.conf ${DEPLOY_USER}@${DEPLOY_HOST}:${REMOTE_DIR}/nginx.conf.tmp"
|
||||
sh "${SSH_CMD} 'cat ${REMOTE_DIR}/nginx.conf.tmp > ${REMOTE_DIR}/nginx.conf && rm -f ${REMOTE_DIR}/nginx.conf.tmp'"
|
||||
sh "${SCP_CMD} nginx.conf ${DEPLOY_USER}@${DEPLOY_HOST}:${REMOTE_DIR}/nginx.conf"
|
||||
sh "${SCP_CMD} docker-compose.yml ${DEPLOY_USER}@${DEPLOY_HOST}:${REMOTE_DIR}/docker-compose.yml"
|
||||
}
|
||||
}
|
||||
@@ -128,6 +126,8 @@ pipeline {
|
||||
}
|
||||
echo "Nginx 容器已存在且运行中"
|
||||
}
|
||||
// docker cp nginx.conf 进容器
|
||||
sh "${SSH_CMD} 'docker cp ${REMOTE_DIR}/nginx.conf ${CONTAINER_PREFIX}-nginx:/etc/nginx/nginx.conf'"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -163,7 +163,7 @@ pipeline {
|
||||
stage('切换流量') {
|
||||
steps {
|
||||
script {
|
||||
sh "${SSH_CMD} \"sed -i 's/proxy_pass http:\\/\\/\\(blue\\|green\\):8000;/proxy_pass http:\\/\\/${env.DEPLOY_TARGET}:8000;/' ${REMOTE_DIR}/nginx.conf\""
|
||||
sh "${SSH_CMD} 'docker exec ${CONTAINER_PREFIX}-nginx sed -i \"s/proxy_pass http:\\/\\/\\(blue\\|green\\):8000;/proxy_pass http:\\/\\/${env.DEPLOY_TARGET}:8000;/\" /etc/nginx/nginx.conf'"
|
||||
sh "${SSH_CMD} 'docker exec ${CONTAINER_PREFIX}-nginx nginx -s reload'"
|
||||
echo "✅ 流量已切换到 ${env.DEPLOY_TARGET}"
|
||||
}
|
||||
|
||||
@@ -5,8 +5,6 @@ services:
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- "10502:80"
|
||||
volumes:
|
||||
- ./nginx.conf:/etc/nginx/nginx.conf:ro
|
||||
healthcheck:
|
||||
test: ["CMD", "wget", "--spider", "-q", "http://localhost/health"]
|
||||
interval: 30s
|
||||
|
||||
Reference in New Issue
Block a user