ci/cd调整

This commit is contained in:
2026-06-02 15:43:16 +08:00
parent ccbf6de863
commit 68d9767bd8
6 changed files with 84 additions and 156 deletions

View File

@@ -1,68 +1,18 @@
name: 全局K3s部署
name: 部署 admin-ui 到 K3s
on:
push:
branches: [master]
branches:
- main
jobs:
deploy:
# ========== 核心修复替换为具体Ubuntu版本解决运行期匹配问题 ==========
runs-on: ubuntu-24.04
env:
# 从组织级Secrets读取不用在仓库重复配置
K3S_HOST: ${{ secrets.K3S_HOST }}
APP_NAME: ${{ gitea.repo_name }}
# 补充若后续要推送镜像需替换为实际镜像仓库地址比如你的Gitea镜像仓库
REGISTRY: 116.204.74.41:3000/red-future
runs-on: ubuntu-latest
steps:
# ========== 核心新增国内Git代理彻底解决GitHub拉取慢 ==========
- name: 配置国内GitHub代理加速
- name: 拉取代码
uses: actions/checkout@v4
- name: 部署到 K3s
run: |
# 全局Git代理所有GitHub请求走国内镜像站
git config --global url."https://ghproxy.com/https://github.com/".insteadOf "https://github.com/"
# 可选替换Ubuntu源为清华源加速依赖安装
sed -i 's/archive.ubuntu.com/mirrors.tuna.tsinghua.edu.cn/g' /etc/apt/sources.list
apt update -y
# ========== 核心修改替换checkout源避开GitHub ==========
- name: 拉取代码Gitea官方源
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. 可选:登录镜像仓库(若需推送镜像,取消注释并配置密钥)
# - name: Login to Gitea Registry
# uses: docker/login-action@v3
# with:
# registry: 116.204.74.41:3000
# username: ${{ secrets.GITEA_USER }}
# password: ${{ secrets.GITEA_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. 修复后的SSH部署步骤解决路径+命名空间问题)
- name: SSH部署K3s
run: |
mkdir -p ~/.ssh
echo "${{ secrets.K3S_PEM_KEY }}" > k3s.pem
chmod 600 k3s.pem
# ========== 修正1上传仓库根目录的deploy.yaml到K3s临时目录 ==========
scp -i k3s.pem -o StrictHostKeyChecking=no ./deploy.yaml root@${K3S_HOST}:/tmp/
# ========== 修正2kubectl指向临时文件+补充命名空间 ==========
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
kubectl apply -f k8s/
kubectl rollout restart deployment admin-ui