70 lines
2.8 KiB
YAML
70 lines
2.8 KiB
YAML
# .woodpecker.yaml
|
||
steps:
|
||
- name: Java 构建
|
||
image: docker.m.daocloud.io/library/maven:3.9.6-eclipse-temurin-17
|
||
pull: true
|
||
commands:
|
||
- mvn clean package -DskipTests
|
||
# 注意:使用 volumes 必须在 Web UI 中开启 "Trusted" 权限
|
||
volumes:
|
||
- /tmp/maven-cache:/root/.m2
|
||
when:
|
||
event: [push, pull_request]
|
||
branch: master
|
||
|
||
- 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
|
||
# 👇 核心:为其指定一个绝对能稳定拉取三方大类目的镜像加速源
|
||
# 这样当它去找 moby/buildkit 时,会自动走大厂的代理通道,100% 不会超时
|
||
mirror: https://docker.m.daocloud.io
|
||
# 很多时候 plugins/docker 内部默认会处理 context,不需要你手动挂载 docker.sock
|
||
# 但需要确保服务器配置了 WOODPECKER_PLUGINS_PRIVILEGED=plugins/docker
|
||
when:
|
||
event: push
|
||
branch: master
|
||
|
||
# 第三步:抛弃所有不靠谱的 docker:cli 和 compose 插件,直接走纯 SSH 本土命令流
|
||
- name: 远程终端闭环部署 (纯命令直接冲)
|
||
image: appleboy/drone-ssh
|
||
environment:
|
||
# 👇 先把 Woodpecker 的 Secret 塞进临时环境变量里
|
||
MY_ALIYUN_USER:
|
||
from_secret: aliyun_acr_username
|
||
MY_ALIYUN_PASS:
|
||
from_secret: aliyun_acr_password
|
||
settings:
|
||
host:
|
||
from_secret: 136_ssh_host
|
||
username:
|
||
from_secret: 136_ssh_user
|
||
password:
|
||
from_secret: 136_ssh_password
|
||
port: 22
|
||
# 👇 核心安全通道:告诉插件,把上面的这两个变量强行带到远程 136 服务器的终端里去!
|
||
envs: [ MY_ALIYUN_USER, MY_ALIYUN_PASS ]
|
||
script:
|
||
# 1. 在 136 本地直接登录阿里云。因为变量被 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
|
||
|
||
|