cicd-test/.drone.yml
kale 63c98c5eb1
Some checks failed
continuous-integration/drone/pr Build is failing
[fix]:[20251208][构建docker1]
2025-12-07 22:13:17 -05:00

128 lines
4.0 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: multi-lang-ci
# 推荐工作区配置 - 修改为当前项目的正确路径
workspace:
base: /drone
path: .
# 定义缓存卷,用于存储 Maven 依赖
volumes:
- name: cache
temp: {}
- name: npm-cache
path: /localcache/npmcache
# 添加 Maven 缓存卷(虽然通过 runner 挂载,但显式声明更清晰)
- name: maven-cache
path: /localcache/maven/repository
# 触发器配置:针对 master 分支的 PR
trigger:
event:
- pull_request
branch:
- main
# 默认克隆步骤 (使用您本地已有的 drone/git:latest)
clone:
depth: 0
image: drone/git:latest
pull: false # 禁用镜像拉取
steps:
# 自动检测是否存在 Java (pom.xml)
- 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
environment:
MAVEN_OPTS: -Dmaven.repo.local=/localcache/maven/repository
commands:
# 动态生成 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 -DskipTests=true clean package
# 验证 JAR 文件是否生成
- ls -lah target/*.jar || (echo "JAR file not found!" && exit 1)
when:
path:
include:
- pom.xml
event: [ push, pull_request, tag ]
# - name: docker_build
# image: docker:latest
# pull: false
# volumes:
# - name: docker_sock
# path: /var/run/docker.sock
# commands:
# # 验证 JAR 文件存在
# - |
# 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 with tag: drone-test:${DRONE_REPO_NAME}"
# - echo "📁 JAR file info:"
# - ls -lh target/drone-test-1.0.jar
# # 构建 Docker 镜像
# - docker build -t drone-test:${DRONE_REPO_NAME} -f Dockerfile .
# # 如果存在 DRONE_TAG同时打 latest 标签
# - |
# if [ -n "${DRONE_TAG}" ]; then
# docker tag drone-test:${DRONE_REPO_NAME} drone-test:latest
# echo "✅ Tagged as drone-test:latest"
# fi
# - echo "✅ Built Docker image: drone-test:${DRONE_REPO_NAME}"
# # 显示镜像信息
# - docker images drone-test
# depends_on:
# - java-build
# when:
# path:
# include:
# - pom.xml
# event: [ push, pull_request, tag ]
# 自动检测是否存在 Python (requirements.txt)
- name: python-test
image: python:3.12.0-slim
pull: false
commands:
# 临时设置 pip 源(仅本次会话)
- pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple/
- pip config set install.trusted-host pypi.tuna.tsinghua.edu.cn
- if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- if [ -f test_example.py ]; then python -m pytest test_example.py -v; fi
when:
branch:
exclude: [ "*" ]
# 最终报告(无论成功失败都运行)
- name: summary
image: alpine
pull: false
commands:
- echo "✅ CI completed at $(date)"
when:
status: [ success, failure ]