Files
admin-ui/.gitea/workflows/deploy.yml
Workflow config file is invalid. Please check your config file: yaml: line 38: did not find expected key
2026-05-23 16:28:44 +08:00

53 lines
2.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:
runs-on: ubuntu-latest
env:
K3S_HOST: 121.37.117.181
APP_NAME: ${{ gitea.repo_name }}
REGISTRY: 你的镜像仓库地址 # 比如 docker.io/你的用户名
steps:
- uses: gitea/actions/checkout@v4
# 1. 初始化 Docker Buildx
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
# 2. 登录镜像仓库(按需)
- 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
# 4. 核心修改先上传deploy.yaml到K3s服务器再执行kubectl
- name: SSH部署K3s
run:
mkdir -p ~/.ssh
echo "${{ secrets.K3S_PEM_KEY }}" > k3s.pem
chmod 600 k3s.pem
# 关键1把Gitea仓库里的deploy.yaml上传到K3s服务器临时目录/tmp
# 注意如果你的deploy.yaml不在仓库根目录要修改./deploy.yaml为实际路径
scp -i k3s.pem -o StrictHostKeyChecking=no ./deploy.yaml root@${K3S_HOST}:/tmp/
# 关键2执行kubectl时指向临时目录的文件而非不存在的/k8s/
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