This commit is contained in:
parent
2384d43136
commit
cf4555b883
|
|
@ -33,11 +33,9 @@ steps:
|
||||||
event: push
|
event: push
|
||||||
branch: master
|
branch: master
|
||||||
|
|
||||||
# 第三步:抛弃所有不靠谱的 docker:cli 和 compose 插件,直接走纯 SSH 本土命令流
|
- name: 远程终端部署
|
||||||
- name: 远程终端闭环部署 (纯命令直接冲)
|
|
||||||
image: appleboy/drone-ssh
|
image: appleboy/drone-ssh
|
||||||
environment:
|
environment:
|
||||||
# 👇 先把 Woodpecker 的 Secret 塞进临时环境变量里
|
|
||||||
MY_ALIYUN_USER:
|
MY_ALIYUN_USER:
|
||||||
from_secret: aliyun_acr_username
|
from_secret: aliyun_acr_username
|
||||||
MY_ALIYUN_PASS:
|
MY_ALIYUN_PASS:
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,29 @@
|
||||||
|
# .woodpecker/build.yaml
|
||||||
|
kind: pipeline
|
||||||
|
name: build-pipeline
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Java 构建
|
||||||
|
image: docker.m.daocloud.io/library/maven:3.9.6-eclipse-temurin-17
|
||||||
|
pull: true
|
||||||
|
commands:
|
||||||
|
- mvn clean package -DskipTests
|
||||||
|
volumes:
|
||||||
|
- /tmp/maven-cache:/root/.m2
|
||||||
|
|
||||||
|
- name: 镜像构建与推送
|
||||||
|
image: docker.m.daocloud.io/woodpeckerci/plugin-docker-buildx:latest
|
||||||
|
volumes:
|
||||||
|
- /var/run/docker.sock:/var/run/docker.sock
|
||||||
|
settings:
|
||||||
|
repo: registry.cn-zhangjiakou.aliyuncs.com/abhors/demo
|
||||||
|
tags: latest
|
||||||
|
registry: registry.cn-zhangjiakou.aliyuncs.com
|
||||||
|
username:
|
||||||
|
from_secret: aliyun_acr_username
|
||||||
|
password:
|
||||||
|
from_secret: aliyun_acr_password
|
||||||
|
mirror: https://docker.m.daocloud.io
|
||||||
|
when:
|
||||||
|
event: [push, pull_request, manual]
|
||||||
|
branch: master
|
||||||
|
|
@ -0,0 +1,68 @@
|
||||||
|
# .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
|
||||||
Loading…
Reference in New Issue