Files
lpt-fe/Jenkinsfile
cat-shark ec157b06dc fix(ci): 修复部署流水线配置
- 使用 Git commit hash 作为镜像标签
- 增加健康检查超时到 15 秒
- 添加镜像清理阶段(保留 7 天)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-19 19:11:10 +08:00

48 lines
1.7 KiB
Groovy

pipeline {
agent none
environment {
IMAGE_NAME = "lpt-fe:${env.GIT_COMMIT?.take(8) ?: '0.0'}"
CONTAINER_NAME = 'LPT_FE'
CONTAINER_PORT = '80'
}
stages {
stage('构建 Docker 镜像') {
agent any
steps {
sh 'docker build --build-arg BUILD_MODE=production -t $IMAGE_NAME .'
}
}
stage('部署容器') {
agent any
steps {
sh '''
docker network create traefik-public || true
docker rm -f $CONTAINER_NAME || true
docker run -d --name $CONTAINER_NAME \\
--network traefik-public \\
--label "traefik.enable=true" \\
--label "traefik.docker.network=traefik-public" \\
--label 'traefik.http.routers.lpt-fe.rule=Host(`lpt.cat-shark.xyz`)' \\
--label "traefik.http.routers.lpt-fe.entrypoints=websecure" \\
--label "traefik.http.routers.lpt-fe.tls.certresolver=le" \\
--label "traefik.http.routers.lpt-fe.service=lpt-fe" \\
--label "traefik.http.services.lpt-fe.loadbalancer.server.port=$CONTAINER_PORT" \\
$IMAGE_NAME
'''
}
}
stage('健康检查') {
agent any
steps {
sh 'sleep 15 && docker exec $CONTAINER_NAME curl -f http://localhost:$CONTAINER_PORT/ || (docker logs $CONTAINER_NAME && exit 1)'
}
}
stage('清理旧镜像') {
agent any
steps {
sh 'docker image prune -af --filter "until=168h" || true'
}
}
}
}