Compare commits

...

3 Commits

Author SHA1 Message Date
kale
a5c24fc31a [fix]:[20251208][构建docker,生成jar并构建镜像]
Some checks failed
continuous-integration/drone/pr Build is failing
2025-12-07 22:23:03 -05:00
kale
99bf38c9ff [fix]:[20251208][构建docker1] 2025-12-07 22:18:55 -05:00
kale
067aad30df [fix]:[20251208][构建docker1] 2025-12-07 22:18:43 -05:00

View File

@ -62,48 +62,51 @@ steps:
- mvn -s ~/.m2/settings.xml -DskipTests=true clean package
# 验证 JAR 文件是否生成
- ls -lah target/*.jar || (echo "JAR file not found!" && exit 1)
# 备份 JAR 文件到 /localcache/${DRONE_REPO_NAME}
- |
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}/
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
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 ]
- name: docker_build
image: docker
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: ${DRONE_REPO_NAME}:latest"
echo "📁 JAR file info:"
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}
echo "✅ Built Docker image: ${DRONE_REPO_NAME}:latest"
docker images ${DRONE_REPO_NAME}
depends_on:
- java-build
when:
path:
include:
- pom.xml
event: [ push, pull_request, tag ]
# 自动检测是否存在 Python (requirements.txt)
- name: python-test