958b6b48b2
- 修复变量名: github.sha → gitea.sha - 添加 Docker Registry 认证步骤 - kubectl 版本修正为 v1.30.0 - 添加部署超时控制(5 分钟) - 添加部署失败自动回滚机制 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
59 lines
1.8 KiB
YAML
59 lines
1.8 KiB
YAML
name: lpt-ai Build & Deploy
|
|
|
|
on:
|
|
workflow_dispatch:
|
|
inputs:
|
|
environment:
|
|
description: '部署环境'
|
|
required: true
|
|
type: choice
|
|
options:
|
|
- dev
|
|
- prod
|
|
|
|
env:
|
|
REGISTRY: 192.168.123.199:5000
|
|
APP: lpt-ai
|
|
REPO_URL: http://git.cat-shark.xyz/cat-shark/lpt-ai.git
|
|
|
|
jobs:
|
|
build-and-deploy:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout code
|
|
run: |
|
|
git clone $REPO_URL .
|
|
git checkout ${{ gitea.sha }}
|
|
|
|
- name: Login to Docker Registry
|
|
run: |
|
|
echo "${{ secrets.REGISTRY_PASSWORD }}" | docker login $REGISTRY -u "${{ secrets.REGISTRY_USERNAME }}" --password-stdin
|
|
|
|
- name: Build & Push Docker image
|
|
run: |
|
|
apk add --no-cache docker-cli
|
|
TAG=${{ gitea.sha }}
|
|
docker build -t $REGISTRY/$APP:$TAG -t $REGISTRY/$APP:${{ inputs.environment }} .
|
|
docker push $REGISTRY/$APP:$TAG
|
|
docker push $REGISTRY/$APP:${{ inputs.environment }}
|
|
|
|
- name: Setup kubectl
|
|
run: |
|
|
curl -sLO "https://dl.k8s.io/release/v1.30.0/bin/linux/amd64/kubectl"
|
|
chmod +x kubectl
|
|
mv kubectl /usr/local/bin/
|
|
mkdir -p ~/.kube
|
|
echo "${{ secrets.KUBECONFIG_B64 }}" | base64 -d > ~/.kube/config
|
|
|
|
- name: Deploy to K8s
|
|
run: |
|
|
TAG=${{ gitea.sha }}
|
|
kubectl set image deployment/$APP $APP=$REGISTRY/$APP:$TAG -n lpt-${{ inputs.environment }} --record
|
|
kubectl rollout status deployment/$APP -n lpt-${{ inputs.environment }} --timeout=5m
|
|
|
|
- name: Rollback on failure
|
|
if: failure()
|
|
run: |
|
|
kubectl rollout undo deployment/$APP -n lpt-${{ inputs.environment }}
|
|
kubectl rollout status deployment/$APP -n lpt-${{ inputs.environment }}
|