pipeline { agent none environment { IMAGE_NAME = 'lpt-fe: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 5 && docker exec $CONTAINER_NAME curl -f http://localhost:$CONTAINER_PORT/ || (docker logs $CONTAINER_NAME && exit 1)' } } } }