model_deploy.yml 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. # 模型部署CI/CD流程
  2. name: Model Deploy
  3. on:
  4. push:
  5. branches: [ main ]
  6. paths:
  7. - 'models/**'
  8. workflow_dispatch:
  9. inputs:
  10. model_name:
  11. description: 'Model to deploy'
  12. required: true
  13. default: 'nlp_bert'
  14. type: choice
  15. options:
  16. - nlp_bert
  17. - vision_resnet
  18. - recommender_v2
  19. environment:
  20. description: 'Deployment environment'
  21. required: true
  22. default: 'staging'
  23. type: choice
  24. options:
  25. - staging
  26. - production
  27. jobs:
  28. deploy:
  29. runs-on: ubuntu-latest
  30. environment: ${{ github.event.inputs.environment || 'staging' }}
  31. steps:
  32. - name: Checkout code
  33. uses: actions/checkout@v3
  34. - name: Set up Docker Buildx
  35. uses: docker/setup-buildx-action@v2
  36. - name: Login to Container Registry
  37. uses: docker/login-action@v2
  38. with:
  39. registry: ghcr.io
  40. username: ${{ github.actor }}
  41. password: ${{ secrets.GITHUB_TOKEN }}
  42. - name: Extract metadata
  43. id: meta
  44. uses: docker/metadata-action@v4
  45. with:
  46. images: ghcr.io/${{ github.repository }}/${{ github.event.inputs.model_name || 'nlp_bert' }}
  47. tags: |
  48. type=ref,event=branch
  49. type=ref,event=pr
  50. type=sha,prefix={{branch}}-
  51. type=raw,value=latest,enable={{is_default_branch}}
  52. - name: Build and push Docker image
  53. uses: docker/build-push-action@v4
  54. with:
  55. context: models/${{ github.event.inputs.model_name || 'nlp_bert' }}
  56. push: true
  57. tags: ${{ steps.meta.outputs.tags }}
  58. labels: ${{ steps.meta.outputs.labels }}
  59. cache-from: type=gha
  60. cache-to: type=gha,mode=max
  61. - name: Deploy to Kubernetes
  62. if: github.event.inputs.environment == 'production'
  63. run: |
  64. echo "Deploying to Kubernetes production environment"
  65. # 这里添加Kubernetes部署脚本
  66. # kubectl apply -f k8s/${{ github.event.inputs.model_name || 'nlp_bert' }}/
  67. - name: Deploy to Docker Compose
  68. if: github.event.inputs.environment == 'staging'
  69. run: |
  70. echo "Deploying to Docker Compose staging environment"
  71. # 这里添加Docker Compose部署脚本
  72. # docker-compose -f docker-compose.staging.yml up -d
  73. - name: Run health checks
  74. run: |
  75. echo "Running health checks for ${{ github.event.inputs.model_name || 'nlp_bert' }}"
  76. # 这里添加健康检查脚本
  77. # curl -f http://localhost:8000/health || exit 1
  78. - name: Notify deployment status
  79. if: always()
  80. run: |
  81. if [ "${{ job.status }}" == "success" ]; then
  82. echo "✅ Deployment successful"
  83. else
  84. echo "❌ Deployment failed"
  85. fi