Compare commits

..

No commits in common. "90155a696aac96a2b8b90beccb66d9a7ba4d0bb9" and "194442170e5330067fe6a8006948abb1d39738c9" have entirely different histories.

3 changed files with 16 additions and 88 deletions

View File

@ -1,49 +0,0 @@
# Jenkins相关文件
Jenkinsfile*
jenkins-docker/
*.md
# Git相关
.git/
.gitignore
# IDE相关
.idea/
.vscode/
*.iml
*.ipr
*.iws
# 构建产物除了需要的jar文件
target/classes/
target/test-classes/
target/surefire-reports/
target/site/
target/maven-archiver/
target/maven-status/
# 日志文件
*.log
# 临时文件
*.tmp
*.swp
*~
# 系统文件
.DS_Store
Thumbs.db
# Docker相关
*.tar
docker-compose.yml
# 部署脚本
deploy.sh
server-setup*.sh
# 文档
JENKINS_*.md
SSH_CONFIG_GUIDE.md
ENTERPRISE_JENKINS_GUIDE.md
QUICK_START.md

View File

@ -1,5 +1,5 @@
# 使用多阶段构建优化镜像大小 # 使用多阶段构建优化镜像大小
FROM amazoncorretto:17-alpine-jdk as builder FROM openjdk:17-jdk-slim as builder
# 设置工作目录 # 设置工作目录
WORKDIR /app WORKDIR /app
@ -18,19 +18,15 @@ COPY src ./src
# 构建应用 # 构建应用
RUN ./mvnw clean package -DskipTests RUN ./mvnw clean package -DskipTests
# 运行时镜像 - 使用更小的Alpine镜像 # 运行时镜像
FROM amazoncorretto:17-alpine FROM openjdk:17-jre-slim
# 安装curl用于健康检查
RUN apk add --no-cache curl
# 设置时区 # 设置时区
ENV TZ=Asia/Shanghai ENV TZ=Asia/Shanghai
RUN apk add --no-cache tzdata && \ RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
# 创建非root用户 # 创建非root用户
RUN addgroup -g 1000 spring && adduser -u 1000 -G spring -s /bin/sh -D spring RUN groupadd -r spring && useradd -r -g spring spring
# 创建应用目录 # 创建应用目录
WORKDIR /app WORKDIR /app

41
Jenkinsfile vendored
View File

@ -1,8 +1,9 @@
pipeline { pipeline {
agent any agent any
options {
options {
buildDiscarder(logRotator(numToKeepStr: '10')) buildDiscarder(logRotator(numToKeepStr: '10'))
timeout(time: 60, unit: 'MINUTES') // 增加到60分钟 timeout(time: 30, unit: 'MINUTES')
timestamps() timestamps()
} }
@ -144,37 +145,17 @@ pipeline {
} }
} }
} }
stage('构建Docker镜像') {
stage('构建Docker镜像') {
steps { steps {
echo '🐳 构建Docker镜像...' echo '🐳 构建Docker镜像...'
script { script {
retry(2) { def image = docker.build("${IMAGE_NAME}:${IMAGE_TAG}")
try {
// 清理旧镜像以节省空间 // 也创建latest标签
sh 'docker image prune -f || true' sh "docker tag ${IMAGE_NAME}:${IMAGE_TAG} ${IMAGE_NAME}:latest"
echo "开始构建Docker镜像: ${IMAGE_NAME}:${IMAGE_TAG}" echo "✅ Docker镜像构建完成: ${IMAGE_NAME}:${IMAGE_TAG}"
// 使用timeout包装Docker构建
timeout(time: 15, unit: 'MINUTES') {
def image = docker.build("${IMAGE_NAME}:${IMAGE_TAG}")
// 也创建latest标签
sh "docker tag ${IMAGE_NAME}:${IMAGE_TAG} ${IMAGE_NAME}:latest"
}
echo "✅ Docker镜像构建完成: ${IMAGE_NAME}:${IMAGE_TAG}"
// 验证镜像是否创建成功
sh "docker images ${IMAGE_NAME}:${IMAGE_TAG}"
} catch (Exception e) {
echo "⚠️ Docker构建失败: ${e.getMessage()}"
// 清理可能的中间状态
sh 'docker system prune -f || true'
throw e
}
}
} }
} }
} }