Files
versions-for-swarm/.drone.yml
seahi 2bf72e1feb
Some checks failed
continuous-integration/drone/push Build encountered an error
Update app.py
2025-12-17 08:51:11 +08:00

71 lines
1.6 KiB
YAML

kind: pipeline
type: docker
name: build-by-tag
node:
name: pve
trigger:
event:
- tag
ref:
- refs/tags/v*
steps:
- name: build-and-push
image: docker:dind
volumes:
- name: dockersock
path: /var/run/docker.sock
environment:
REGISTRY: harbor.seahi.me
IMAGE_NAME: stu/versions-for-swarm
HARBOR_USERNAME:
from_secret: harbor_username
HARBOR_PASSWORD:
from_secret: harbor_password
commands:
# 登录 Harbor
- echo $HARBOR_PASSWORD | docker login $REGISTRY -u $HARBOR_USERNAME --password-stdin
# 从 Git Tag 获取版本号
- export VERSION=${DRONE_TAG}
- echo "📦 构建版本: $VERSION"
# 判断是否为 buggy 版本
- |
if echo "$VERSION" | grep -q "buggy"; then
BUGGY_FLAG="--build-arg BUGGY=true"
echo "⚠️ 检测到 buggy 版本,启用故障模式"
else
BUGGY_FLAG=""
fi
# 构建镜像
- docker build
--build-arg APP_VERSION=$VERSION
$BUGGY_FLAG
-t $REGISTRY/$IMAGE_NAME:$VERSION
.
# 如果是 v2.1,同时标记为 latest
- |
if [ "$VERSION" = "v2.1" ]; then
docker tag $REGISTRY/$IMAGE_NAME:$VERSION $REGISTRY/$IMAGE_NAME:latest
docker push $REGISTRY/$IMAGE_NAME:latest
echo "🏷️ 已标记为 latest"
fi
# 推送镜像
- docker push $REGISTRY/$IMAGE_NAME:$VERSION
# 清理
- docker system prune -f
- echo "✅ 版本 $VERSION 构建并推送成功!"
volumes:
- name: dockersock
host:
path: /var/run/docker.sock