Files
scratch/.drone.yml
T
endial 02c5fd39be
continuous-integration/drone/push Build is failing
fix: 更新默认ci/cd 中 git 拉取配置文件
2025-12-26 15:29:18 +08:00

99 lines
2.6 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: build-multiarch-podman
# 匹配 Runner 标签
node:
runtime: podman
arch: amd64
multiarch: true
# 触发条件
trigger:
include:
- event: push
branch: [main, release/*]
- event: tag
# 核心:启用 Drone 内置 Git 克隆配置
clone:
disable: false # 启用内置克隆(默认就是 false,显式声明更稳妥)
depth: 1 # 浅克隆,加快速度
tags: true # 拉取标签(适配 Tag 触发)
steps:
# 登录容器仓库(如 Harbor、Docker Hub、阿里云 ACR
- name: registry login
image: quay.io/containers/podman:v4.9
privileged: true
volumes:
- name: podman-sock
path: /run/podman/podman.sock
- name: containers-config
path: /etc/containers
environment:
REGISTRY_USER:
from_secret: swr_username
REGISTRY_PASSWORD:
from_secret: swr_password
REGISTRY_SERVER: swr.cn-north-4.myhuaweicloud.com
commands:
- |
echo "Logging into registry..."
podman login "$REGISTRY_SERVER" -u "$REGISTRY_USER" -p "$REGISTRY_PASSWORD" || {
echo "Registry login failed!"
exit 1
}
# 构建并推送镜像
- name: build and push
image: quay.io/containers/podman:v4.9
privileged: true
volumes:
- name: podman-sock
path: /run/podman/podman.sock
- name: containers-config
path: /etc/containers
environment:
IMAGE_NAME: swr.cn-north-4.myhuaweicloud.com/colovu/scratch
commands:
- |
if [ -n "$DRONE_TAG" ]; then
IMAGE_TAG="$DRONE_TAG"
else
IMAGE_TAG="$DRONE_COMMIT_SHA"
fi
echo "Building image..."
podman build \
--tag "${IMAGE_NAME}:${IMAGE_TAG}" \
.
echo "Pushing image..."
podman push "${IMAGE_NAME}:${IMAGE_TAG}"
# 可选:打 latest 标签
if [ "${DRONE_BRANCH}" = "main" ]; then
podman push \
"${IMAGE_NAME}:${IMAGE_TAG}" \
"docker://${IMAGE_NAME}:latest"
fi
echo "Image pushed: ${IMAGE_NAME}:${IMAGE_TAG}"
# 清理步骤(无论成功/失败都执行)
- name: cleanup
image: quay.io/containers/podman:v4.9
privileged: true
volumes:
- name: podman-sock
path: /run/podman/podman.sock
commands:
- |
echo "Logging out of registry..."
podman logout swr.cn-north-4.myhuaweicloud.com || true
echo "Cleaning up unused images..."
podman system prune -af || true
when:
status: [success, failure] # 成功/失败都执行清理