后端新增 GET /api/docker/stats,走 Docker Engine API(unix socket)读取容器状态、CPU/内存/网络/磁盘与端口;前端 /dashboard 概览页展示汇总与容器列表,5 秒自动刷新;compose 只读挂载 docker.sock 并通过 group_add 注入宿主机 docker 组 GID。
67 lines
1.5 KiB
Groovy
67 lines
1.5 KiB
Groovy
pipeline {
|
|
agent any
|
|
|
|
options {
|
|
timestamps()
|
|
disableConcurrentBuilds()
|
|
|
|
buildDiscarder(
|
|
logRotator(
|
|
numToKeepStr: '10',
|
|
artifactNumToKeepStr: '5'
|
|
)
|
|
)
|
|
}
|
|
|
|
stages {
|
|
|
|
stage('Checkout') {
|
|
steps {
|
|
cleanWs()
|
|
checkout scm
|
|
}
|
|
}
|
|
|
|
stage('Build Images') {
|
|
steps {
|
|
script {
|
|
env.BUILD_TIME = sh(script: "date '+%Y-%m-%d %H:%M:%S'", returnStdout: true).trim()
|
|
env.COMMIT_SHORT = sh(script: 'git rev-parse --short HEAD', returnStdout: true).trim()
|
|
}
|
|
sh 'docker compose build backend frontend'
|
|
}
|
|
}
|
|
|
|
stage('Deploy') {
|
|
steps {
|
|
script {
|
|
// 读取宿主机 docker.sock 的组 GID,供后端容器以附加组方式访问 socket。
|
|
env.DOCKER_GID = sh(
|
|
script: "stat -c '%g' /var/run/docker.sock 2>/dev/null || echo 999",
|
|
returnStdout: true
|
|
).trim()
|
|
}
|
|
sh '''
|
|
docker compose up -d
|
|
docker compose ps
|
|
'''
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
post {
|
|
success {
|
|
echo 'Build and deploy succeeded'
|
|
}
|
|
|
|
failure {
|
|
echo 'Build or deploy failed'
|
|
}
|
|
|
|
always {
|
|
echo 'Pipeline finished'
|
|
}
|
|
}
|
|
}
|