| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- # 模型部署CI/CD流程
- name: Model Deploy
- on:
- push:
- branches: [ main ]
- paths:
- - 'models/**'
- workflow_dispatch:
- inputs:
- model_name:
- description: 'Model to deploy'
- required: true
- default: 'nlp_bert'
- type: choice
- options:
- - nlp_bert
- - vision_resnet
- - recommender_v2
- environment:
- description: 'Deployment environment'
- required: true
- default: 'staging'
- type: choice
- options:
- - staging
- - production
- jobs:
- deploy:
- runs-on: ubuntu-latest
- environment: ${{ github.event.inputs.environment || 'staging' }}
-
- steps:
- - name: Checkout code
- uses: actions/checkout@v3
-
- - name: Set up Docker Buildx
- uses: docker/setup-buildx-action@v2
-
- - name: Login to Container Registry
- uses: docker/login-action@v2
- with:
- registry: ghcr.io
- username: ${{ github.actor }}
- password: ${{ secrets.GITHUB_TOKEN }}
-
- - name: Extract metadata
- id: meta
- uses: docker/metadata-action@v4
- with:
- images: ghcr.io/${{ github.repository }}/${{ github.event.inputs.model_name || 'nlp_bert' }}
- tags: |
- type=ref,event=branch
- type=ref,event=pr
- type=sha,prefix={{branch}}-
- type=raw,value=latest,enable={{is_default_branch}}
-
- - name: Build and push Docker image
- uses: docker/build-push-action@v4
- with:
- context: models/${{ github.event.inputs.model_name || 'nlp_bert' }}
- push: true
- tags: ${{ steps.meta.outputs.tags }}
- labels: ${{ steps.meta.outputs.labels }}
- cache-from: type=gha
- cache-to: type=gha,mode=max
-
- - name: Deploy to Kubernetes
- if: github.event.inputs.environment == 'production'
- run: |
- echo "Deploying to Kubernetes production environment"
- # 这里添加Kubernetes部署脚本
- # kubectl apply -f k8s/${{ github.event.inputs.model_name || 'nlp_bert' }}/
-
- - name: Deploy to Docker Compose
- if: github.event.inputs.environment == 'staging'
- run: |
- echo "Deploying to Docker Compose staging environment"
- # 这里添加Docker Compose部署脚本
- # docker-compose -f docker-compose.staging.yml up -d
-
- - name: Run health checks
- run: |
- echo "Running health checks for ${{ github.event.inputs.model_name || 'nlp_bert' }}"
- # 这里添加健康检查脚本
- # curl -f http://localhost:8000/health || exit 1
-
- - name: Notify deployment status
- if: always()
- run: |
- if [ "${{ job.status }}" == "success" ]; then
- echo "✅ Deployment successful"
- else
- echo "❌ Deployment failed"
- fi
|