Files
admin-ui/.gitea/workflows/deploy.yml
张斌 6db7f5ed8c
Some checks failed
全局K3s部署 / deploy (push) Failing after 31s
dockerfile
2026-05-23 18:01:03 +08:00

68 lines
3.0 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:
# ========== 核心修复替换为具体Ubuntu版本解决运行期匹配问题 ==========
runs-on: ubuntu-24.04
env:
# 从组织级Secrets读取不用在仓库重复配置
K3S_HOST: ${{ secrets.K3S_HOST }}
APP_NAME: ${{ gitea.repo_name }}
# 补充若后续要推送镜像需替换为实际镜像仓库地址比如你的Gitea镜像仓库
REGISTRY: 116.204.74.41:3000/red-future
steps:
# ========== 核心新增国内Git代理彻底解决GitHub拉取慢 ==========
- name: 配置国内GitHub代理加速
run: |
# 全局Git代理所有GitHub请求走国内镜像站
git config --global url."https://ghproxy.com/https://github.com/".insteadOf "https://github.com/"
# 可选替换Ubuntu源为清华源加速依赖安装
sed -i 's/archive.ubuntu.com/mirrors.tuna.tsinghua.edu.cn/g' /etc/apt/sources.list
apt update -y
# ========== 核心修改替换checkout源避开GitHub ==========
- name: 拉取代码Gitea官方源
uses: gitea/actions/checkout@v4
with:
fetch-depth: 0 # 可选:拉取完整历史,加速后续操作
timeout-minutes: 10 # 增加超时,避免拉取中断
# 1. 初始化 Docker Buildx原内容不变
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
# 2. 可选:登录镜像仓库(若需推送镜像,取消注释并配置密钥)
# - name: Login to Gitea Registry
# uses: docker/login-action@v3
# with:
# registry: 116.204.74.41:3000
# username: ${{ secrets.GITEA_USER }}
# password: ${{ secrets.GITEA_PWD }}
# 3. 构建+推送(原内容不变)
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ env.REGISTRY }}/${{ env.APP_NAME }}:${{ gitea.sha }}
cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ env.APP_NAME }}:buildcache
cache-to: type=registry,ref=${{ env.REGISTRY }}/${{ env.APP_NAME }}:buildcache,mode=max
# 4. 修复后的SSH部署步骤解决路径+命名空间问题)
- name: SSH部署K3s
run: |
mkdir -p ~/.ssh
echo "${{ secrets.K3S_PEM_KEY }}" > k3s.pem
chmod 600 k3s.pem
# ========== 修正1上传仓库根目录的deploy.yaml到K3s临时目录 ==========
scp -i k3s.pem -o StrictHostKeyChecking=no ./deploy.yaml root@${K3S_HOST}:/tmp/
# ========== 修正2kubectl指向临时文件+补充命名空间 ==========
ssh -i k3s.pem -o StrictHostKeyChecking=no root@${K3S_HOST} << CMD
kubectl apply -f /tmp/deploy.yaml
kubectl rollout restart deployment ${APP_NAME} -n default
rm -f /tmp/deploy.yaml # 可选:清理临时文件
CMD