fix:加入健康检查
This commit is contained in:
Vendored
+14
-10
@@ -52,6 +52,7 @@ pipeline {
|
|||||||
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 \\
|
||||||
|
--network mysql_default \\
|
||||||
-p $HOST_PORT:$CONTAINER_PORT \\
|
-p $HOST_PORT:$CONTAINER_PORT \\
|
||||||
--health-cmd="curl -f http://localhost:80 || exit 1" \\
|
--health-cmd="curl -f http://localhost:80 || exit 1" \\
|
||||||
--health-interval=5s \\
|
--health-interval=5s \\
|
||||||
@@ -65,21 +66,24 @@ pipeline {
|
|||||||
agent any
|
agent any
|
||||||
steps {
|
steps {
|
||||||
script {
|
script {
|
||||||
|
def lastStatus = ''
|
||||||
timeout(time: 60, unit: 'SECONDS') {
|
timeout(time: 60, unit: 'SECONDS') {
|
||||||
waitUntil {
|
waitUntil {
|
||||||
def status = sh(
|
def status = sh(
|
||||||
script: "docker inspect -f '{{.State.Health.Status}}' $CONTAINER_NAME || echo 'no-healthcheck'",
|
script: "docker inspect -f '{{.State.Health.Status}}' $CONTAINER_NAME || echo 'no-healthcheck'",
|
||||||
returnStdout: true
|
returnStdout: true
|
||||||
).trim()
|
).trim()
|
||||||
echo "Current container status: ${status}"
|
|
||||||
return (status == 'healthy')
|
if (status != lastStatus) {
|
||||||
|
echo "Container health: ${status}"
|
||||||
|
lastStatus = status
|
||||||
|
}
|
||||||
|
|
||||||
|
return (status == 'healthy')
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user