|
|
@@ -87,7 +87,8 @@ pipeline {
|
|
|
//服务配置
|
|
|
API_PORT = 9200
|
|
|
API_REMOTE_DEBUG_PORT = 9201
|
|
|
- API_NAMESPACE_RESTFUL = "${params.module}"
|
|
|
+ // 与 application-*.yml 的 server.servlet.context-path 保持一致,不能用 module 名
|
|
|
+ API_NAMESPACE_RESTFUL = "router/rest"
|
|
|
|
|
|
//DOCKER配置
|
|
|
DOCKER_REGISTRY = "reg-aliyun"
|
|
|
@@ -96,10 +97,17 @@ pipeline {
|
|
|
DOCKER_LOGIN_REGISTRY = "https://${DOCKER_HOST}"
|
|
|
|
|
|
BUILD_PREFIX = "storlead-huawei"
|
|
|
- //镜像完整名称 registry-vpc.cn-shenzhen.aliyuncs.com/storlead/sp-project-management-prod:1.0
|
|
|
- DOCKER_IMG_NAME = "${DOCKER_HOST}/${BUILD_PREFIX}/${params.module}-${params.profile}:${VERSION}"
|
|
|
- //镜像名 storlead/sp-project-management-prod:1.0
|
|
|
- IMG_NAME = "${BUILD_PREFIX}/${params.module}-${params.profile}:${VERSION}"
|
|
|
+ // 部署服务名:java 用根工程 artifactId(storlead-saas-platform),再拼环境后缀 -test/-prod/-uat
|
|
|
+ // Maven 模块名 params.module(storlead-api)只用于编译和 jar 路径,不作为运行时服务名
|
|
|
+ DEPLOY_APP = "${params.module}"
|
|
|
+ if (params.modulePrefix == "java") {
|
|
|
+ DEPLOY_APP = "${ARTIFACTID}"
|
|
|
+ }
|
|
|
+ DEPLOY_NAME = "${DEPLOY_APP}-${params.profile}"
|
|
|
+ //镜像完整名称 registry.cn-shenzhen.aliyuncs.com/storlead-huawei/storlead-saas-platform-test:1.0
|
|
|
+ DOCKER_IMG_NAME = "${DOCKER_HOST}/${BUILD_PREFIX}/${DEPLOY_NAME}:${VERSION}"
|
|
|
+ IMG_NAME = "${BUILD_PREFIX}/${DEPLOY_NAME}:${VERSION}"
|
|
|
+ echo "部署服务名 DEPLOY_NAME=${DEPLOY_NAME}"
|
|
|
|
|
|
PUSH_DOCK_IMG = true
|
|
|
SERVER_HOST_NAME = "test1"
|
|
|
@@ -131,11 +139,7 @@ pipeline {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- echo "处理MODULE_NAMESPACE_RESTFUL"
|
|
|
- //把 module 名 从 sp-xxx 变成 xxx 也就是 项目 的 namespace
|
|
|
-// if (API_NAMESPACE_RESTFUL == "storlead-centre-api") {
|
|
|
-// API_NAMESPACE_RESTFUL = "api"
|
|
|
-// }
|
|
|
+ echo "处理MODULE_NAMESPACE_RESTFUL=${API_NAMESPACE_RESTFUL}"
|
|
|
echo "处理镜像推送"
|
|
|
}
|
|
|
}
|
|
|
@@ -239,12 +243,13 @@ pipeline {
|
|
|
sh """
|
|
|
echo '
|
|
|
FROM ${BASE_IMAGE}
|
|
|
+ RUN apt-get update && apt-get install -y --no-install-recommends curl && rm -rf /var/lib/apt/lists/*
|
|
|
|
|
|
COPY java/${params.module}/target/${params.module}-${VERSION}.jar app.jar
|
|
|
EXPOSE ${API_PORT}
|
|
|
EXPOSE ${API_REMOTE_DEBUG_PORT}
|
|
|
- HEALTHCHECK --interval=1m --timeout=10s CMD curl -f http://localhost:${API_PORT}/${API_NAMESPACE_RESTFUL}/actuator
|
|
|
- ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom", "-Djava.awt.headless=true","-Dspring.profiles.active=${params.profile}", "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:${API_REMOTE_DEBUG_PORT}","-jar","/app.jar"]' > Dockerfile
|
|
|
+ HEALTHCHECK --interval=1m --timeout=10s CMD curl -f http://localhost:${API_PORT}/${API_NAMESPACE_RESTFUL}/actuator/health
|
|
|
+ ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom", "-Djava.awt.headless=true","-Dspring.profiles.active=${params.profile}", "-Dserver.port=${API_PORT}", "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:${API_REMOTE_DEBUG_PORT}","-jar","/app.jar"]' > Dockerfile
|
|
|
docker build -t ${DOCKER_IMG_NAME} .
|
|
|
"""
|
|
|
sh "docker push ${DOCKER_IMG_NAME}"
|
|
|
@@ -294,7 +299,7 @@ pipeline {
|
|
|
echo '
|
|
|
version: "3.7"
|
|
|
services:
|
|
|
- ${params.module}-${params.profile}:
|
|
|
+ ${DEPLOY_NAME}:
|
|
|
image: ${DOCKER_IMG_NAME}
|
|
|
deploy:
|
|
|
replicas: ${SWARM_INIT_REPLICAS_NUM}
|
|
|
@@ -317,7 +322,7 @@ pipeline {
|
|
|
# 最多连续重试3次如果仍然失败则放弃重试
|
|
|
max_attempts: 3
|
|
|
healthcheck:
|
|
|
- test: ["CMD", "curl", "-f", "http://localhost:${API_PORT}/${API_NAMESPACE_RESTFUL}/actuator"]
|
|
|
+ test: ["CMD", "curl", "-f", "http://localhost:${API_PORT}/${API_NAMESPACE_RESTFUL}/actuator/health"]
|
|
|
interval: 1m
|
|
|
timeout: 5s
|
|
|
retries: 3
|
|
|
@@ -345,19 +350,13 @@ pipeline {
|
|
|
${ARTIFACTID}:
|
|
|
driver: overlay
|
|
|
external: true
|
|
|
- ' > ${params.module}-${params.profile}-stack.yml
|
|
|
+ ' > ${DEPLOY_NAME}-stack.yml
|
|
|
"""
|
|
|
- // if (params.profile =="dev") {
|
|
|
- // sh "docker stack deploy -c ${ARTIFACTID}-${params.profile}-stack.yml ${ARTIFACTID}-${params.profile}"
|
|
|
-
|
|
|
- // sh "docker ps -f name=${ARTIFACTID} -q | xargs --no-run-if-empty docker container stop"
|
|
|
- // sh "docker container ls -a -fname=${ARTIFACTID} -q | xargs -r docker container rm"
|
|
|
- // sh "docker run -d --restart=always -p ${API_PORT}:${API_PORT} -p ${API_REMOTE_DEBUG_PORT}:${API_REMOTE_DEBUG_PORT} -v /app:/app --name ${ARTIFACTID} ${DOCKER_IMG_NAME}"
|
|
|
- // } else {
|
|
|
// 全部都以swarm 模式启动
|
|
|
- sshPut remote: remote, from: "${params.module}-${params.profile}-stack.yml", into: "/docker/sp/${params.module}-${params.profile}-stack.yml"
|
|
|
- sshCommand remote: remote, command: "docker stack deploy --resolve-image=always --with-registry-auth -c /docker/sp/${params.module}-${params.profile}-stack.yml ${params.module}-${params.profile}"
|
|
|
- // }
|
|
|
+ // 旧栈名为 storlead-api-{profile},改名后需先删掉,否则 10070 端口冲突
|
|
|
+ sshCommand remote: remote, command: "docker stack ls --format '{{.Name}}' | grep -qx 'storlead-api-${params.profile}' && docker stack rm storlead-api-${params.profile} && sleep 20 || true"
|
|
|
+ sshPut remote: remote, from: "${DEPLOY_NAME}-stack.yml", into: "/docker/sp/${DEPLOY_NAME}-stack.yml"
|
|
|
+ sshCommand remote: remote, command: "docker stack deploy --resolve-image=always --with-registry-auth -c /docker/sp/${DEPLOY_NAME}-stack.yml ${DEPLOY_NAME}"
|
|
|
}
|
|
|
}
|
|
|
}
|