Files
api-client/.drone.yml
zzc 4cfde00218
Some checks failed
continuous-integration/drone/tag Build is failing
build: drone
2026-01-05 09:20:26 +08:00

136 lines
4.7 KiB
YAML
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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: frontend-deploy
steps:
# =============================
# 1. 构建并推送前端镜像
# =============================
# 1⃣ 构建并推送 Docker 镜像
- name: build & push image
image: plugins/docker
settings:
registry: images.lihailezzc.com
repo: images.lihailezzc.com/ai-meng/api-client
tags:
- latest
- ${DRONE_TAG}
username: robot$build-robot
password: FbVZ7xv0wCA4es40sclV9kywOryz4l02
dockerfile: Dockerfile
# =============================
# 2. SSH 服务器部署
# =============================
# - name: deploy to server
# image: appleboy/drone-ssh # 专门用于 SSH 执行命令
# settings:
# host: 123.57.105.123 # 服务器 IP
# username: aimeng # 登录用户
# ssh_key: |
# -----BEGIN OPENSSH PRIVATE KEY-----
# b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW
# QyNTUxOQAAACA83omyFMBLSjFBZpG84twncgU7JIw9j9rVj2iIZwLvjAAAAJg6n1PsOp9T
# 7AAAAAtzc2gtZWQyNTUxOQAAACA83omyFMBLSjFBZpG84twncgU7JIw9j9rVj2iIZwLvjA
# AAAEBRiuNI+OWKCQCHKn6FMFzGIx3sFW1XE5fqLrf48Qh0nTzeibIUwEtKMUFmkbzi3Cdy
# BTskjD2P2tWPaIhnAu+MAAAAEGRyb25lIGRlcGxveSBrZXkBAgMEBQ==
# -----END OPENSSH PRIVATE KEY-----
# port: 12580
# script:
# - echo "🚀 登录服务器,拉取最新镜像并部署"
# - cd /home/aimeng/workspace/docker-compose/admin
# - export NEW_WEB_SUFFIX=$(date +%s)
# - export WEB_NEW="cms_${NEW_SUFFIX}"
# - docker compose run -d --name $WEB_NEW api_server
# - docker stop api_server || true
# - docker rm api_server || true
# - docker rename $API_NEW api_server
# - docker image prune -f
# - docker compose pull cms
# - docker compose up -d frontend
# 3⃣ 飞书通知
- name: notify feishu
image: curlimages/curl
environment:
FEISHU_WEBHOOK_URL: https://open.feishu.cn/open-apis/bot/v2/hook/be0b7f21-894e-4280-9469-69005fa5be9c
commands:
- |
set -x
# 构建状态
COLOR=$( [ "$DRONE_BUILD_STATUS" = "success" ] && echo "green" || echo "red" )
# 基础信息
COMMIT_MSG=$(echo "$DRONE_COMMIT_MESSAGE" | sed 's/"/\\"/g')
AUTHOR=${DRONE_COMMIT_AUTHOR_NAME}
PROJECT=${DRONE_REPO_NAME}
BRANCH=${DRONE_BRANCH}
PROJECT_VERSION=${DRONE_TAG}
URL=${DRONE_BUILD_LINK}
# 耗时计算
DURATION=$((DRONE_BUILD_FINISHED - DRONE_BUILD_CREATED))
MIN=$((DURATION / 60))
SEC=$((DURATION % 60))
FINISH="$MIN分$SEC秒"
# 调试输出
echo "DEBUG: DURATIONA=$DURATIONA"
echo "DEBUG: DURATIONB=$DURATIONB"
echo "DEBUG: DURATION=$DURATION"
echo "DEBUG: MIN=$MIN"
echo "DEBUG: SEC=$SEC"
echo "DEBUG: FINISH=$FINISH"
curl --request POST \
--url "$FEISHU_WEBHOOK_URL" \
--header 'content-type: application/json' \
--data "{
\"msg_type\": \"interactive\",
\"card\": {
\"config\": { \"wide_screen_mode\": true },
\"header\": {
\"title\": { \"tag\": \"plain_text\", \"content\": \"🚀 CI/CD 构建通知\" },
\"template\": \"$COLOR\"
},
\"elements\": [
{
\"tag\": \"div\",
\"text\": {
\"tag\": \"lark_md\",
\"content\": \"**项目**$PROJECT\\n**分支**$BRANCH\\n**版本 **$PROJECT_VERSION \\n**提交人**$AUTHOR\\n**提交说明**$COMMIT_MSG\"
}
},
{ \"tag\": \"hr\" },
{
\"tag\": \"div\",
\"fields\": [
{ \"is_short\": true, \"text\": { \"tag\": \"lark_md\", \"content\": \"**状态**\\n$DRONE_BUILD_STATUS\" } },
{ \"is_short\": true, \"text\": { \"tag\": \"lark_md\", \"content\": \"**耗时**\\n$FINISH\" } }
]
},
{
\"tag\": \"action\",
\"actions\": [
{
\"tag\": \"button\",
\"text\": { \"tag\": \"plain_text\", \"content\": \"查看详情\" },
\"url\": \"$URL\",
\"type\": \"primary\"
}
]
}
]
}
}"
when:
status:
- success
- failure
trigger:
event:
- tag