fix:加入健康检查

This commit is contained in:
2025-07-27 20:19:12 +08:00
parent 239de5fd61
commit c653d6a7ef
Vendored
+18 -15
View File
@@ -1,21 +1,21 @@
pipeline { pipeline {
agent none // 全局不指定,局部单独声明 agent none // 全局不指定,局部单独声明
environment { environment {
IMAGE_NAME = 'lpt-fe:0.0' IMAGE_NAME = 'lpt-fe:0.0'
CONTAINER_NAME = 'LPT_FE' CONTAINER_NAME = 'LPT_FE'
HOST_PORT = '5158' HOST_PORT = '5158'
CONTAINER_PORT = '80' CONTAINER_PORT = '80'
} }
stages { stages {
stage('Install Dependencies') { stage('Install Dependencies') {
agent { agent {
docker { docker {
image 'node:20-alpine' image 'node:20-alpine'
args '-v ${WORKSPACE}/.npm:/.npm -v ${WORKSPACE}/node_modules:/app/node_modules' args '-v ${WORKSPACE}/.npm:/.npm -v ${WORKSPACE}/node_modules:/app/node_modules'
} }
} }
steps { steps {
sh ''' sh '''
npm config set cache /.npm npm config set cache /.npm
npm install npm install
''' '''
@@ -23,14 +23,14 @@ pipeline {
} }
stage('Type Check & Build') { stage('Type Check & Build') {
agent { agent {
docker { docker {
image 'node:20-alpine' image 'node:20-alpine'
args '-v ${WORKSPACE}/.npm:/.npm -v ${WORKSPACE}/node_modules:/app/node_modules' args '-v ${WORKSPACE}/.npm:/.npm -v ${WORKSPACE}/node_modules:/app/node_modules'
} }
} }
steps { steps {
sh ''' sh '''
npm run type-check npm run type-check
npm run build npm run build
''' '''
@@ -38,21 +38,24 @@ pipeline {
} }
stage('Build Docker Image') { stage('Build Docker Image') {
agent any // Jenkins默认节点,有Docker命令 agent any // Jenkins默认节点,有Docker命令
steps { steps {
sh ''' sh '''
docker build -t $IMAGE_NAME . docker build -t $IMAGE_NAME .
''' '''
} }
} }
stage('Run Docker Container') { stage('Run Docker Container') {
agent any agent any
steps { steps {
sh ''' sh '''
docker rm -f $CONTAINER_NAME || true docker rm -f $CONTAINER_NAME || true
docker run -d --name $CONTAINER_NAME \\ docker run -d --name $CONTAINER_NAME \\
-p $HOST_PORT:$CONTAINER_PORT \\ -p $HOST_PORT:$CONTAINER_PORT \\
--health-cmd="curl -f http://localhost:80 || exit 1" \\
--health-interval=5s \\
--health-retries=3 \\
$IMAGE_NAME $IMAGE_NAME
''' '''
} }