Merge pull request '[fix]:[20251208][构建docker,生成jar并构建镜像1]' (#28) from yinzy_dev into main
Reviewed-on: #28 Reviewed-by: 君肯管理员 <jk_admin@jk.com>
This commit is contained in:
commit
ade6a53e1d
82
.drone.yml
82
.drone.yml
@ -19,6 +19,9 @@ volumes:
|
||||
# 定义 Docker socket 卷
|
||||
- name: docker_sock
|
||||
path: /var/run/docker.sock
|
||||
# 添加共享卷用于访问JAR文件
|
||||
- name: jar-cache
|
||||
path: /localcache
|
||||
|
||||
# 触发器配置:针对 master 分支的 PR
|
||||
trigger:
|
||||
@ -34,13 +37,53 @@ clone:
|
||||
pull: false # 禁用镜像拉取
|
||||
|
||||
steps:
|
||||
# 自动检测是否存在 Java (pom.xml)
|
||||
# PR时:构建和测试
|
||||
- name: java-build-test
|
||||
image: registry.cn-beijing.aliyuncs.com/yinzy/maven:3.9-eclipse-temurin-8
|
||||
pull: false
|
||||
volumes:
|
||||
- name: maven-cache
|
||||
path: /localcache/maven/repository
|
||||
environment:
|
||||
MAVEN_OPTS: -Dmaven.repo.local=/localcache/maven/repository
|
||||
commands:
|
||||
- mkdir -p ~/.m2
|
||||
# 动态生成 settings.xml(仅用于 CI)
|
||||
- |
|
||||
cat > ~/.m2/settings.xml << 'EOF'
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
|
||||
<mirrors>
|
||||
<mirror>
|
||||
<id>aliyun</id>
|
||||
<mirrorOf>*</mirrorOf>
|
||||
<name>Aliyun Maven</name>
|
||||
<url>https://maven.aliyun.com/repository/public</url>
|
||||
</mirror>
|
||||
</mirrors>
|
||||
</settings>
|
||||
EOF
|
||||
- mvn -s ~/.m2/settings.xml clean test package
|
||||
# 验证 JAR 文件是否生成
|
||||
- ls -lah target/*.jar || (echo "JAR file not found!" && exit 1)
|
||||
when:
|
||||
path:
|
||||
include:
|
||||
- pom.xml
|
||||
event:
|
||||
- pull_request
|
||||
|
||||
# Tag时:构建(跳过测试,因为PR时已测试过)
|
||||
- name: java-build
|
||||
image: registry.cn-beijing.aliyuncs.com/yinzy/maven:3.9-eclipse-temurin-8
|
||||
pull: false
|
||||
volumes:
|
||||
- name: maven-cache
|
||||
path: /localcache/maven/repository
|
||||
- name: jar-cache
|
||||
path: /localcache
|
||||
environment:
|
||||
MAVEN_OPTS: -Dmaven.repo.local=/localcache/maven/repository
|
||||
commands:
|
||||
@ -80,8 +123,10 @@ steps:
|
||||
path:
|
||||
include:
|
||||
- pom.xml
|
||||
event: [ push, pull_request, tag ]
|
||||
event:
|
||||
- tag
|
||||
|
||||
# Tag时:构建Docker镜像
|
||||
- name: docker_build
|
||||
image: docker:latest
|
||||
pull: false
|
||||
@ -111,7 +156,38 @@ steps:
|
||||
path:
|
||||
include:
|
||||
- pom.xml
|
||||
event: [ push, pull_request, tag ]
|
||||
event:
|
||||
- tag
|
||||
|
||||
# Tag时:发布JAR文件到Gitea Release
|
||||
- name: gitea_release
|
||||
image: plugins/gitea-release:latest
|
||||
pull: false
|
||||
volumes:
|
||||
- name: jar-cache
|
||||
path: /localcache
|
||||
settings:
|
||||
api_key:
|
||||
from_secret: gitea_api_key
|
||||
base_url:
|
||||
from_secret: gitea_base_url
|
||||
files:
|
||||
- /localcache/${DRONE_REPO_NAME}/*.jar
|
||||
title: Release ${DRONE_TAG}
|
||||
note: |
|
||||
Release ${DRONE_TAG}
|
||||
|
||||
Commit: ${DRONE_COMMIT_SHA:0:8}
|
||||
Build: ${DRONE_BUILD_NUMBER}
|
||||
file_exists: overwrite
|
||||
depends_on:
|
||||
- docker_build
|
||||
when:
|
||||
path:
|
||||
include:
|
||||
- pom.xml
|
||||
event:
|
||||
- tag
|
||||
|
||||
# 自动检测是否存在 Python (requirements.txt)
|
||||
- name: python-test
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user