feat:更新

This commit is contained in:
linzhongyan 2025-10-28 19:03:49 +08:00
parent 5f2ab42c37
commit 99532b883d

42
Jenkinsfile vendored
View File

@ -1,58 +1,28 @@
pipeline {
agent any
environment {
APP_NAME = "go-dy"
IMAGE_NAME = "go-dy:latest"
WORKDIR = "/opt/go-dy"
DOCKER_REGISTRY = "" // 如果你需要推送到镜像仓库可以填
APP_HOME = "/opt/go-dy"
}
stages {
stage('Checkout Code') {
stage('Checkout') {
steps {
git branch: 'main',
url: 'http://47.95.203.241:3000/ReeseLin/golang-dy-back.git',
credentialsId: '932fcb89-1c39-4005-b664-15e862f09e20'
git url: 'http://47.95.203.241:3000/ReeseLin/golang-dy-back', branch: 'main', credentialsId: 'GITEA_CREDENTIAL_ID'
}
}
stage('Build Binary') {
steps {
// 使用 golang 官方镜像构建
sh """
docker run --rm -v ${WORKDIR}:/app -w /app golang:1.22-alpine \
sh -c "go mod tidy && go build -o ${APP_NAME} ."
"""
sh 'docker run --rm -v $APP_HOME:/app -w /app golang:1.22-alpine sh -c "go mod tidy && go build -o go-dy ."'
}
}
stage('Build Docker Image') {
steps {
sh """
docker build -t ${IMAGE_NAME} ${WORKDIR}
"""
sh 'docker build -t go-dy:latest $APP_HOME'
}
}
stage('Deploy') {
steps {
// 停掉旧容器,启动新容器
sh """
docker stop ${APP_NAME} || true
docker rm ${APP_NAME} || true
docker run -d --name ${APP_NAME} -p 8090:8090 ${IMAGE_NAME}
"""
sh 'docker stop go-dy || true && docker rm go-dy || true && docker run -d --name go-dy -p 8090:18080 go-dy:latest'
}
}
}
post {
success {
echo "流水线执行成功,服务已更新!"
}
failure {
echo "流水线失败,请检查日志"
}
}
}