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