cicd-test/.drone.yml
kale 175d58c97a
All checks were successful
continuous-integration/drone/pr Build is passing
[fix]:[20251208][drone 测试本地仓库构建]
2025-12-10 09:03:03 -05:00

261 lines
7.4 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: npm-cache
path: /localcache/npm-cache
clone:
depth: 0
image: drone/git:latest
pull: false
steps:
- name: java-build-test
image: registry.cn-beijing.aliyuncs.com/yinzy/maven:jk3.9-8
pull: false
volumes:
- name: maven-cache
path: /localcache/maven/repository
environment:
MAVEN_OPTS: -Dmaven.repo.local=/localcache/maven/repository
commands:
# - touch /localcache/maven/repository/bbb.txt
# - ls -lah /localcache/maven/repository
- mkdir -p ~/.m2
- cat ~/.m2/settings.xml
- mvn -B 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: npm-cache
path: /localcache/npm-cache
commands:
- cd vue-ui
- npm config set cache /localcache/npm-cache/.npm
- npm ci -prefer-offline --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/apps
- name: npm-cache
path: /localcache/npm-cache
- name: certs
path: /localcache/registry_certs # 你提前放好 ca.crt
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: npm-cache
path: /localcache/npm-cache
- name: jar-cache # 复用已有 /localcache用于暂存 dist.zip
path: /localcache/apps
commands:
- cd vue-ui
- npm config set cache /localcache/npm-cache/.npm
- npm ci -prefer-offline --registry=https://registry.npmmirror.com
- npm run build
- cd dist && tar -czf ../dist.tgz . && cd ..
- mkdir -p /localcache/apps/${DRONE_REPO_NAME}
- cp dist.tgz /localcache/apps/${DRONE_REPO_NAME}/dist-${DRONE_TAG}.tgz -f
- ls -lah /localcache/apps/${DRONE_REPO_NAME}/dist-${DRONE_TAG}.tgz
- name: java-build
image: registry.cn-beijing.aliyuncs.com/yinzy/maven:jk3.9-8
pull: false
volumes:
- name: maven-cache
path: /localcache/maven/repository
- name: jar-cache
path: /localcache/apps
environment:
MAVEN_OPTS: -Dmaven.repo.local=/localcache/maven/repository
commands:
- mvn -B -DskipTests=true clean package
- ls -lah target/*.jar || (echo "JAR file not found!" && exit 1)
- |
mkdir -p /localcache/apps/${DRONE_REPO_NAME}
JAR_FILE=$(ls target/*.jar 2>/dev/null | head -1)
if [ -n "$JAR_FILE" ]; then
cp "$JAR_FILE" /localcache/apps/${DRONE_REPO_NAME}/ -f
echo "✅ JAR file backed up to /localcache/apps/${DRONE_REPO_NAME}/$(basename $JAR_FILE)"
ls -lh /localcache/apps/${DRONE_REPO_NAME}/
else
echo "⚠️ No JAR file found to backup"
fi
- name: frontend_docker_build
image: registry.cn-beijing.aliyuncs.com/yinzy/drone-plugins:docker-latest
pull: false
settings:
volumes:
- name: certs
path: /etc/docker/certs.d/docker-registry.local:36000/
# 1. 仓库认证信息
registry:
from_secret: local_registry_base_url
username:
from_secret: local_registry_user
password:
from_secret: local_registry_pass
# 2. 镜像名称 (不包含 Tag)
repo: /jk/apps/${DRONE_REPO_NAME}-front
# 3. 指定 Dockerfile 位置
dockerfile: docker/Dockerfile-frontend
# 4. 构建上下文 (Context),默认为 . (根目录)
context: .
# 5. 生成的 Tags
# 插件会自动生成 repo:tag
tags:
- front-${DRONE_TAG} # e.g. back-v1.0.0
- front-latest # 方便随时拉取最新版
# - front-${DRONE_COMMIT_SHA:0:8}
# 如果你需要把 dist.tgz 复制给 build
extra_files:
- dist.tgz
- 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 docker/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/apps
settings:
api_key:
from_secret: gitea_token
base_url:
from_secret: gitea_base_url
files:
- /localcache/apps/${DRONE_REPO_NAME}/*.jar
- /localcache/apps/${DRONE_REPO_NAME}/dist-${DRONE_TAG}.tgz
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: push_acr
image: docker:latest
pull: false
volumes:
- name: docker_sock
path: /var/run/docker.sock
environment:
ACR_USER:
from_secret: aliyun_acr_username # 阿里云访问凭证用户名
ACR_PASS:
from_secret: aliyun_acr_password # 阿里云访问凭证密码
ACR_REGISTRY: registry.cn-beijing.aliyuncs.com
ACR_NAMESPACE: yinzy
ACR_REPO: cicd
commands:
- echo "$ACR_PASS" | docker login $ACR_REGISTRY -u "$ACR_USER" --password-stdin
# 后端
- docker tag ${DRONE_REPO_NAME}:latest $ACR_REGISTRY/$ACR_NAMESPACE/$ACR_REPO:back-${DRONE_TAG}
- docker push $ACR_REGISTRY/$ACR_NAMESPACE/$ACR_REPO:back-${DRONE_TAG}
# 前端
- docker tag ${DRONE_REPO_NAME}-frontend:latest $ACR_REGISTRY/$ACR_NAMESPACE/$ACR_REPO:front-${DRONE_TAG}
- docker push $ACR_REGISTRY/$ACR_NAMESPACE/$ACR_REPO:front-${DRONE_TAG}
depends_on:
- docker_build
- frontend_docker_build
- name: summary
image: alpine
pull: false
commands:
- echo "✅ Tag pipeline completed at $(date)"
when:
status: [ success, failure ]
depends_on:
- gitea_release