Files
admin-ui/.gitea/workflows/deploy.yml
张斌 5e9553d43b
Some checks failed
全局K3s部署 / deploy (push) Failing after 5s
dockerfile
2026-05-23 17:22:25 +08:00

31 lines
1.2 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.
name: 全局K3s部署
on:
push:
branches: [master]
jobs:
deploy:
runs-on: ubuntu-latest
env:
# 从组织级Secrets读取不用在仓库重复配置
K3S_HOST: ${{ secrets.K3S_HOST }}
APP_NAME: ${{ gitea.repo_name }}
steps:
- name: 拉取代码
uses: actions/checkout@v4
- name: SSH部署K3s
run: |
mkdir -p ~/.ssh
echo "${{ secrets.K3S_PEM_KEY }}" > k3s.pem
chmod 600 k3s.pem
# ========== 核心新增上传仓库里的deploy.yml到K3s临时目录 ==========
# 说明:./deploy.yml 是你Gitea仓库根目录的./gitea/workflows/deploy.yml需提前创建
scp -i k3s.pem -o StrictHostKeyChecking=no ./gitea/workflows/deploy.yml root@${K3S_HOST}:/tmp/
# ========== 核心修改kubectl指向临时目录的文件补充命名空间 ==========
ssh -i k3s.pem -o StrictHostKeyChecking=no root@${K3S_HOST} << CMD
kubectl apply -f /tmp/deploy.yml # 替换原/k8s/deploy.yml
kubectl rollout restart deployment ${APP_NAME} -n default # 加-n default避免找不到资源
rm -f /tmp/deploy.yml # 可选:部署后删除临时文件
CMD