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

57 lines
2.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:
K3S_HOST: 121.37.117.181
APP_NAME: ${{ gitea.repo_name }}
# 替换为你的Gitea内置镜像仓库地址从你的Gitea地址推导
REGISTRY: 116.204.74.41:3000/red-future
steps:
- uses: gitea/actions/checkout@v4
# 1. 初始化 Docker Buildx
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
# 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
# 4. 修改后的SSH部署步骤核心上传仓库内deploy.yaml到K3s临时目录
- name: SSH部署K3s
run: |
mkdir -p ~/.ssh
echo "${{ secrets.K3S_PEM_KEY }}" > k3s.pem
chmod 600 k3s.pem
# 关键1上传当前仓库根目录的deploy.yaml到K3s服务器/tmp目录
# 若deploy.yaml在仓库k8s子目录改为 ./k8s/deploy.yaml
scp -i k3s.pem -o StrictHostKeyChecking=no ./deploy.yaml root@${K3S_HOST}:/tmp/
# 关键2执行kubectl指向临时文件补充命名空间避免找不到资源
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