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

55 lines
2.1 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替换为你的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. 核心修改2登录Gitea内置镜像仓库替换原DockerHub登录
- name: Login to Gitea Registry
uses: docker/login-action@v3
with:
registry: 116.204.74.41:3000 # Gitea镜像仓库地址
username: ${{ secrets.GITEA_USER }} # 需在Gitea配置该密钥
password: ${{ secrets.GITEA_PWD }} # 需在Gitea配置该密钥
# 3. 构建+推送启用缓存适配Gitea仓库
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
push: true
# 镜像标签Gitea仓库地址/项目名:提交SHA唯一标识
tags: ${{ env.REGISTRY }}/${{ env.APP_NAME }}:${{ gitea.sha }}
# 缓存配置适配Gitea仓库
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. 核心修改3上传仓库内deploy.yaml到K3s解决路径不存在
- 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