demo/.woodpecker/deploy.yaml

68 lines
2.8 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.

# .woodpecker/deploy.yaml
kind: pipeline
name: deploy-pipeline
# 🛑 依赖铁律:必须等上游的 build-pipeline 构建推送成功,这里才开始轰鸣
depends_on:
- build-pipeline
# 🛠️ 核心策略:集群矩阵定义
# 在这里配置你所有不同的服务器 IP以及它们在 Woodpecker Web UI 后台对应的专属 Secret 名字
matrix:
include:
- NODE_NAME: "集群节点A (136服务器)"
SECRET_NODE_IP: "136_ssh_host"
# 👇 告诉插件:此节点去读名为 node_a_user 和 node_a_pass 的 Secret
SECRET_USER_NAME: "136_ssh_user"
SECRET_PASS_NAME: "136_ssh_password"
- NODE_NAME: "集群节点B (114服务器)"
SECRET_NODE_IP: "114_ssh_host"
# 👇 告诉插件:此节点去读名为 node_b_user 和 node_b_pass 的 Secret
SECRET_USER_NAME: "114_ssh_user"
SECRET_PASS_NAME: "114_ssh_password"
steps:
- name: 远程终端集群部署
image: docker.m.daocloud.io/appleboy/drone-ssh:latest
environment:
# 将公共的阿里云密文注入到临时环境变量中
MY_ALIYUN_USER:
from_secret: aliyun_acr_username
MY_ALIYUN_PASS:
from_secret: aliyun_acr_password
settings:
# 👇 动态读取矩阵中当前节点的真实 IP
host:
from_secret: ${SECRET_NODE_IP}
# 👇 动态读取矩阵中指定的、各不相同的 SSH 账号密码 Secret 名字
username:
from_secret: ${SECRET_USER_NAME}
password:
from_secret: ${SECRET_PASS_NAME}
port: 22
# 告诉插件,把上面的这两个公共变量强行带到远程各服务器的终端里去
envs: [ MY_ALIYUN_USER, MY_ALIYUN_PASS ]
script:
- echo "========================================="
- echo "🚀 开始部署节点:${NODE_NAME} (${SECRET_NODE_IP})"
- echo "========================================="
# 1. 在各自的远程服务器本土直接登录阿里云,由于变量被 envs 带过去了,值绝对真实有效!
- docker login --username "$MY_ALIYUN_USER" --password "$MY_ALIYUN_PASS" registry.cn-zhangjiakou.aliyuncs.com
# 2. 清理远程旧容器(防止重名冲突,加 || true 防止第一次找不到报错)
- docker stop demo-container || true
- docker rm demo-container || true
# 3. 远程各服务器本土拉取最新镜像,走各自服务器的网络,绝对不会超时
- docker pull registry.cn-zhangjiakou.aliyuncs.com/abhors/demo:latest
# 4. 直接原生 docker run 轰起来!不需要任何额外文件,不需要 compose
- docker run -d --name demo-container -p 8080:8080 --restart always registry.cn-zhangjiakou.aliyuncs.com/abhors/demo:latest
- echo "🎉 ${NODE_NAME} 部署成功!"
when:
event: [push, pull_request, manual]
branch: master