Files
admin-ui/.gitea/workflows/deploy.yml
张斌 172659369c
Some checks failed
全局K3s部署 / deploy (push) Failing after 1s
dockerfile
2026-05-23 17:06:02 +08:00

63 lines
2.5 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 }}
# ========== 必须修改1替换为你的实际镜像仓库地址 ==========
# 若用DockerHub改为你的DockerHub用户名如 docker.io/zhangsan
# 若用Gitea内置仓库改为 116.204.74.41:3000/red-future
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适配你的镜像仓库登录二选一 ==========
# 选项A用Gitea内置镜像仓库推荐和你的代码仓库统一
- 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配置该密钥
# 选项B用DockerHub若坚持用注释掉上面的Gitea登录启用下面这段
# - name: Login to DockerHub
# uses: docker/login-action@v3
# with:
# username: ${{ secrets.DOCKER_USER }}
# password: ${{ secrets.DOCKER_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
# ========== 核心修复:解决/k8s/deploy.yaml不存在 ==========
- name: SSH部署K3s
run: |
mkdir -p ~/.ssh
echo "${{ secrets.K3S_PEM_KEY }}" > k3s.pem
chmod 600 k3s.pem
# 第一步上传仓库根目录的deploy.yaml到K3s临时目录
scp -i k3s.pem -o StrictHostKeyChecking=no ./deploy.yaml root@${K3S_HOST}:/tmp/
# 第二步执行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