Files
versions-for-swarm/.drone.yml
2025-12-17 08:56:34 +08:00

53 lines
1.4 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:
- echo $HARBOR_PASSWORD | docker login $REGISTRY -u $HARBOR_USERNAME --password-stdin
- export VERSION=${DRONE_TAG}
- echo "[BUILD] 构建版本:" $VERSION
- |
if echo "$VERSION" | grep -q "buggy"; then
BUGGY_FLAG="--build-arg BUGGY=true"
echo "[WARNING] 检测到 buggy 版本,启用故障模式"
else
BUGGY_FLAG=""
fi
- docker build --build-arg APP_VERSION=$VERSION $BUGGY_FLAG -t $REGISTRY/$IMAGE_NAME:$VERSION .
- |
if [ "$VERSION" = "v2.1" ]; then
docker tag $REGISTRY/$IMAGE_NAME:$VERSION $REGISTRY/$IMAGE_NAME:latest
docker push $REGISTRY/$IMAGE_NAME:latest
echo "[TAG] 已标记为 latest"
fi
- docker push $REGISTRY/$IMAGE_NAME:$VERSION
- docker system prune -f
- echo "[SUCCESS] 版本 $VERSION 构建并推送成功!"
volumes:
- name: dockersock
host:
path: /var/run/docker.sock