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

67 lines
2.6 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:
K3S_HOST: 121.37.117.181
APP_NAME: ${{ gitea.repo_name }}
# 替换为你的Gitea内置镜像仓库地址必填
REGISTRY: 116.204.74.41:3000/red-future
steps:
# 核心修改1改用Gitea官方的checkout避开GitHub
- name: 拉取代码
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为Docker动作增加网络重试
env:
ACTIONS_RUNNER_DEBUG: true
with:
driver-opts: network=host
# 2. 登录镜像仓库适配Gitea内置仓库若用DockerHub则保留原配置
- name: Login to Gitea Registry
uses: docker/login-action@v3
with:
registry: 116.204.74.41:3000
username: ${{ secrets.GITEA_USER }} # 需在Gitea配置该密钥用户名
password: ${{ secrets.GITEA_PWD }} # 需在Gitea配置该密钥密码/令牌)
# 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
# 增加构建超时和重试
timeout: 300s
# 4. 修改后的SSH部署步骤核心上传仓库内deploy.yaml到K3s临时目录解决路径不存在
- name: SSH部署K3s
run: |
mkdir -p ~/.ssh
echo "${{ secrets.K3S_PEM_KEY }}" > k3s.pem
chmod 600 k3s.pem
# 关键上传仓库根目录的deploy.yaml到K3s服务器/tmp目录
scp -i k3s.pem -o StrictHostKeyChecking=no -o ConnectTimeout=10 ./deploy.yaml root@${K3S_HOST}:/tmp/
# 执行kubectl命令指向临时文件+补充命名空间
ssh -i k3s.pem -o StrictHostKeyChecking=no -o ConnectTimeout=10 root@${K3S_HOST} << CMD
kubectl apply -f /tmp/deploy.yaml
kubectl rollout restart deployment ${APP_NAME} -n default
# 可选:清理临时文件
rm -f /tmp/deploy.yaml
CMD