cicd-test/.drone.yml
kale bc663d5e88
All checks were successful
continuous-integration/drone/pr Build is passing
[fix]:[20251208][drone 增加前端工程的cicd 3]
2025-12-08 03:33:31 -05:00

241 lines
6.9 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

kind: pipeline
type: docker
name: pr-ci
# PR 流水线:仅在 PR 触发
trigger:
event:
- pull_request
# 如需限制目标分支,可加 target:
# target:
# - main
workspace:
base: /drone
path: .
volumes:
- name: maven-cache
path: /localcache/maven/repository
- name: node-cache
path: /localcache/node_modules
clone:
depth: 0
image: drone/git:latest
pull: false
steps:
- 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
- |
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
- ls -lah target/*.jar || (echo "JAR file not found!" && exit 1)
- name: frontend-build
image: registry.cn-beijing.aliyuncs.com/yinzy/node:20.11-alpine3.19
pull: false
volumes:
- name: node-cache
path: /localcache/node_modules
commands:
- cd vue-ui
- npm config set cache /localcache/node_modules/.npm
- npm ci --registry=https://registry.npmmirror.com
- npm run build
- ls -lah dist
# 如需其他检查步骤,可在这里继续追加
- name: summary
image: alpine
pull: false
commands:
- echo "✅ PR pipeline completed at $(date)"
when:
status: [ success, failure ]
depends_on:
- java-build-test
- frontend-build
---
kind: pipeline
type: docker
name: release-tag
# Tag 流水线:仅在 tag 触发(不要加 branch 限制)
trigger:
event:
- tag
branch:
- "**"
workspace:
base: /drone
path: .
volumes:
- name: maven-cache
path: /localcache/maven/repository
- name: docker_sock
path: /var/run/docker.sock
- name: jar-cache
path: /localcache
- name: node-cache
path: /localcache/node_modules
clone:
depth: 0
image: drone/git:latest
pull: false
steps:
- name: frontend-build
image: registry.cn-beijing.aliyuncs.com/yinzy/node:20.11-alpine3.19
pull: false
volumes:
- name: node-cache
path: /localcache/node_modules
- name: jar-cache # 复用已有 /localcache用于暂存 dist.zip
path: /localcache
commands:
- cd vue-ui
- npm config set cache /localcache/node_modules/.npm
- npm ci --registry=https://registry.npmmirror.com
- npm run build
- cd dist && zip -r ../dist.zip . && cd ..
- mkdir -p /localcache/${DRONE_REPO_NAME}
- cp dist.zip /localcache/${DRONE_REPO_NAME}/dist-${DRONE_TAG}.zip
- 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:
- mkdir -p ~/.m2
- |
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 -DskipTests=true clean package
- ls -lah target/*.jar || (echo "JAR file not found!" && exit 1)
- |
mkdir -p /localcache/${DRONE_REPO_NAME}
JAR_FILE=$(ls target/*.jar 2>/dev/null | head -1)
if [ -n "$JAR_FILE" ]; then
cp "$JAR_FILE" /localcache/${DRONE_REPO_NAME}/ -f
echo "✅ JAR file backed up to /localcache/${DRONE_REPO_NAME}/$(basename $JAR_FILE)"
ls -lh /localcache/${DRONE_REPO_NAME}/
else
echo "⚠️ No JAR file found to backup"
fi
- name: frontend_docker_build
image: docker:latest
pull: false
volumes:
- name: docker_sock
path: /var/run/docker.sock
commands:
- docker info
- docker build -t ${DRONE_REPO_NAME}-frontend:latest -f vue-ui/Dockerfile vue-ui
- docker tag ${DRONE_REPO_NAME}-frontend:latest ${DRONE_REPO_NAME}-frontend:${DRONE_COMMIT_SHA:0:8}
- docker images ${DRONE_REPO_NAME}-frontend
depends_on:
- frontend-build
- name: docker_build
image: docker:latest
pull: false
volumes:
- name: docker_sock
path: /var/run/docker.sock
commands:
- docker info || (echo "❌ Docker daemon not available" && exit 1)
- |
if [ ! -f target/drone-test-1.0.jar ]; then
echo "❌ JAR file not found! Make sure java-build step completed successfully."
ls -la target/ || echo "target directory does not exist"
exit 1
fi
echo "📦 Building Docker image: ${DRONE_REPO_NAME}:latest"
ls -lh target/drone-test-1.0.jar
docker build -t ${DRONE_REPO_NAME}:latest -f Dockerfile .
docker tag ${DRONE_REPO_NAME}:latest ${DRONE_REPO_NAME}:${DRONE_COMMIT_SHA:0:8}
docker images ${DRONE_REPO_NAME}
depends_on:
- java-build
- name: gitea_release
image: registry.cn-beijing.aliyuncs.com/yinzy/drone-plugins:gitea-release-latest
pull: false
volumes:
- name: jar-cache
path: /localcache
settings:
api_key:
from_secret: gitea_token
base_url:
from_secret: gitea_base_url
files:
- /localcache/${DRONE_REPO_NAME}/*.jar
- /localcache/${DRONE_REPO_NAME}/dist-${DRONE_TAG}.zip
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
- frontend_docker_build
- name: summary
image: alpine
pull: false
commands:
- echo "✅ Tag pipeline completed at $(date)"
when:
status: [ success, failure ]