添加FangJiaScript
This commit is contained in:
Vendored
+96
-64
@@ -1,18 +1,86 @@
|
||||
#!/usr/bin/env groovy
|
||||
|
||||
// 每个项目的完整部署配置字典,新增项目只需在此添加一条记录
|
||||
// buildDir: Maven 构建目录名(deliverables/<buildDir>),默认与 key 同名,不同时显式指定
|
||||
def PROJECT_CONFIG = [
|
||||
'fangjiabkoff' : [
|
||||
imageName : 'fangjia-bkoff',
|
||||
composeDir : 'fangjia-bkoff',
|
||||
serviceName : 'fangjia-bkoff',
|
||||
deployHost : '192.168.0.80',
|
||||
deployBase : '/home/docker',
|
||||
sshCredId : 'goojia-ssh',
|
||||
],
|
||||
'chafangtong' : [
|
||||
imageName : 'chafangtong',
|
||||
composeDir : 'chafangtong',
|
||||
serviceName : 'chafangtong',
|
||||
deployHost : '192.168.0.80',
|
||||
deployBase : '/home/docker',
|
||||
sshCredId : 'goojia-ssh',
|
||||
],
|
||||
'fangjia' : [
|
||||
imageName : 'fangjia-coresite',
|
||||
composeDir : 'fangjia-coresite',
|
||||
serviceName : 'fangjia-coresite',
|
||||
deployHost : '192.168.0.80',
|
||||
deployBase : '/home/docker',
|
||||
sshCredId : 'goojia-ssh',
|
||||
],
|
||||
'fangjiapds' : [
|
||||
imageName : 'fangjia-pds',
|
||||
composeDir : 'fangjia-pds',
|
||||
serviceName : 'fangjia-pds',
|
||||
deployHost : '192.168.0.80',
|
||||
deployBase : '/home/docker',
|
||||
sshCredId : 'goojia-ssh',
|
||||
],
|
||||
'fangjiastatic' : [
|
||||
imageName : 'fangjia-static',
|
||||
composeDir : 'fangjia-coresite',
|
||||
serviceName : 'fangjia-static',
|
||||
deployHost : '192.168.0.80',
|
||||
deployBase : '/home/docker',
|
||||
sshCredId : 'goojia-ssh',
|
||||
],
|
||||
'geluke' : [
|
||||
imageName : 'geluke',
|
||||
composeDir : 'geluke',
|
||||
serviceName : 'geluke',
|
||||
deployHost : '192.168.0.80',
|
||||
deployBase : '/home/docker',
|
||||
sshCredId : 'goojia-ssh',
|
||||
],
|
||||
'fangjiaopen' : [
|
||||
imageName : 'fangjia-open',
|
||||
composeDir : 'fangjia-open',
|
||||
serviceName : 'fangjia-open',
|
||||
deployHost : '192.168.0.36',
|
||||
deployBase : '/home/docker',
|
||||
sshCredId : 'goojia-ssh',
|
||||
],
|
||||
'fangjia-script' : [
|
||||
buildDir : 'script', // deliverables/script
|
||||
imageName : 'fangjia-script',
|
||||
composeDir : 'fangjia-script',
|
||||
serviceName : 'fangjia-script',
|
||||
deployHost : '192.168.0.80',
|
||||
deployBase : '/home/docker',
|
||||
sshCredId : 'goojia-ssh',
|
||||
],
|
||||
]
|
||||
|
||||
pipeline {
|
||||
agent { label 'linux' }
|
||||
parameters {
|
||||
choice(name: 'PROJECT_NAME', choices: ['chafangtong', 'fangjia', 'fangjiapds', 'fangjiastatic', 'geluke', 'fangjiaopen'], description: '请选择发布的项目')
|
||||
choice(name: 'PROJECT_NAME', choices: ['chafangtong', 'fangjia', 'fangjiapds', 'fangjiastatic', 'geluke', 'fangjiaopen', 'fangjia-script'], description: '请选择发布的项目')
|
||||
}
|
||||
tools {
|
||||
jdk 'JDK8'
|
||||
}
|
||||
|
||||
environment {
|
||||
REGISTRY = "192.168.0.19:9011"
|
||||
DEPLOY_USER = "goojia"
|
||||
DEPLOY_HOST = "192.168.0.80" // 目标部署服务器 IP,按实际修改
|
||||
DEPLOY_BASE = "/home/docker" // docker
|
||||
REGISTRY = "192.168.0.19:9011"
|
||||
}
|
||||
|
||||
stages {
|
||||
@@ -25,14 +93,11 @@ pipeline {
|
||||
stage('Maven Build') {
|
||||
steps {
|
||||
script {
|
||||
def projects = ['fangjiabkoff', 'chafangtong', 'fangjia', 'fangjiapds', 'fangjiastatic', 'geluke', 'fangjiaopen']
|
||||
for (def project : projects) {
|
||||
if (params.PROJECT_NAME == project) {
|
||||
dir("deliverables/${project}") {
|
||||
withMaven(globalMavenSettingsConfig: '426b9a25-aa0d-47d3-a24c-8abdfc4421ff', jdk: "JDK8") {
|
||||
sh 'mvn clean package -Dmaven.test.skip=true'
|
||||
}
|
||||
}
|
||||
def cfg = PROJECT_CONFIG[params.PROJECT_NAME]
|
||||
def buildDir = cfg.buildDir ?: params.PROJECT_NAME
|
||||
dir("deliverables/${buildDir}") {
|
||||
withMaven(globalMavenSettingsConfig: '426b9a25-aa0d-47d3-a24c-8abdfc4421ff', jdk: "JDK8") {
|
||||
sh 'mvn clean package -Dmaven.test.skip=true'
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -42,28 +107,18 @@ pipeline {
|
||||
stage('Docker Build & Push') {
|
||||
steps {
|
||||
script {
|
||||
def projects = ['fangjiabkoff', 'chafangtong', 'fangjia', 'fangjiapds', 'fangjiastatic', 'geluke', 'fangjiaopen']
|
||||
def imagesName = [
|
||||
'fangjiabkoff' : 'fangjia-bkoff',
|
||||
'chafangtong' : 'chafangtong',
|
||||
'fangjia' : 'fangjia-coresite',
|
||||
'fangjiapds' : 'fangjia-pds',
|
||||
'fangjiastatic' : 'fangjia-static',
|
||||
'geluke' : 'geluke',
|
||||
'fangjiaopen' : 'fangjia-open'
|
||||
]
|
||||
for (def project : projects) {
|
||||
if (params.PROJECT_NAME == project) {
|
||||
def imageName = imagesName[project]
|
||||
def imageTag = env.BUILD_TAG.toLowerCase()
|
||||
dir("projects/${imageName}") {
|
||||
withDockerRegistry(credentialsId: 'DockerNexus', url: "http://${REGISTRY}") {
|
||||
sh "docker build -t ${REGISTRY}/${imageName}:${imageTag} ."
|
||||
// 同时打 latest 方便 docker compose pull
|
||||
sh "docker tag ${REGISTRY}/${imageName}:${imageTag} ${REGISTRY}/${imageName}:latest"
|
||||
sh "docker push ${REGISTRY}/${imageName}:latest"
|
||||
}
|
||||
}
|
||||
def cfg = PROJECT_CONFIG[params.PROJECT_NAME]
|
||||
def buildDir = cfg.buildDir ?: params.PROJECT_NAME
|
||||
def imageTag = env.BUILD_TAG.toLowerCase()
|
||||
dir("projects/${cfg.imageName}") {
|
||||
// fangjia-script 构建产物在 deliverables/script/target/classes,需同步过来
|
||||
if (cfg.buildDir) {
|
||||
sh "rsync -a --delete ../../deliverables/${buildDir}/target/classes/ target/classes/"
|
||||
}
|
||||
withDockerRegistry(credentialsId: 'DockerNexus', url: "http://${REGISTRY}") {
|
||||
sh "docker build -t ${REGISTRY}/${cfg.imageName}:${imageTag} ."
|
||||
sh "docker tag ${REGISTRY}/${cfg.imageName}:${imageTag} ${REGISTRY}/${cfg.imageName}:latest"
|
||||
sh "docker push ${REGISTRY}/${cfg.imageName}:latest"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -73,36 +128,13 @@ pipeline {
|
||||
stage('Docker Compose Deploy') {
|
||||
steps {
|
||||
script {
|
||||
def composeDir = [
|
||||
'fangjiabkoff' : 'fangjia-bkoff',
|
||||
'chafangtong' : 'chafangtong',
|
||||
'fangjia' : 'fangjia-coresite',
|
||||
'fangjiapds' : 'fangjia-pds',
|
||||
'fangjiastatic' : 'fangjia-coresite',
|
||||
'geluke' : 'geluke',
|
||||
'fangjiaopen' : 'fangjia-open'
|
||||
]
|
||||
def serviceNames = [
|
||||
'fangjiabkoff' : 'fangjia-bkoff',
|
||||
'chafangtong' : 'chafangtong',
|
||||
'fangjia' : 'fangjia-coresite',
|
||||
'fangjiapds' : 'fangjia-pds',
|
||||
'fangjiastatic' : 'fangjia-coresite',
|
||||
'geluke' : 'geluke',
|
||||
'fangjiaopen' : 'fangjia-open'
|
||||
]
|
||||
def project = params.PROJECT_NAME
|
||||
def dir = composeDir[project]
|
||||
def serviceName =serviceNames[project]
|
||||
withCredentials([usernamePassword(credentialsId: 'goojia-ssh', usernameVariable: 'SSH_USER', passwordVariable: 'SSH_PASS')]) {
|
||||
def cfg = PROJECT_CONFIG[params.PROJECT_NAME]
|
||||
withCredentials([usernamePassword(credentialsId: cfg.sshCredId, usernameVariable: 'SSH_USER', passwordVariable: 'SSH_PASS')]) {
|
||||
sh """
|
||||
sshpass -p "\$SSH_PASS" ssh -o StrictHostKeyChecking=no \$SSH_USER@${DEPLOY_HOST} '
|
||||
cd ${DEPLOY_BASE}/${dir}
|
||||
# 拉取最新镜像
|
||||
sshpass -p "\$SSH_PASS" ssh -o StrictHostKeyChecking=no \$SSH_USER@${cfg.deployHost} '
|
||||
cd ${cfg.deployBase}/${cfg.composeDir}
|
||||
docker compose pull
|
||||
# 重启对应服务(不影响其他服务)
|
||||
docker compose up -d --no-deps --force-recreate ${serviceName}
|
||||
# 清理旧镜像
|
||||
docker compose up -d --no-deps --force-recreate ${cfg.serviceName}
|
||||
docker image prune -f
|
||||
'
|
||||
"""
|
||||
@@ -120,4 +152,4 @@ pipeline {
|
||||
echo "❌ ${params.PROJECT_NAME} 部署失败,请检查日志"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user