docker-build.yml 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. name: Build and Push Docker Image
  2. on:
  3. push:
  4. branches: [ master, main ]
  5. workflow_dispatch:
  6. jobs:
  7. build-backend:
  8. runs-on: ubuntu-latest
  9. steps:
  10. - name: Checkout code
  11. uses: actions/checkout@v3
  12. - name: Set up Docker Buildx
  13. uses: docker/setup-buildx-action@v2
  14. - name: Log in to Docker Hub
  15. uses: docker/login-action@v2
  16. with:
  17. username: ${{ secrets.DOCKERHUB_USERNAME }}
  18. password: ${{ secrets.DOCKERHUB_TOKEN }}
  19. - name: Build and push backend
  20. uses: docker/build-push-action@v4
  21. with:
  22. context: ./backend
  23. file: ./backend/Dockerfile
  24. push: true
  25. tags: 537yaha/ai-cs-backend:latest
  26. platforms: linux/amd64,linux/arm64
  27. build-frontend:
  28. runs-on: ubuntu-latest
  29. steps:
  30. - name: Checkout code
  31. uses: actions/checkout@v3
  32. - name: Set up Docker Buildx
  33. uses: docker/setup-buildx-action@v2
  34. - name: Log in to Docker Hub
  35. uses: docker/login-action@v2
  36. with:
  37. username: ${{ secrets.DOCKERHUB_USERNAME }}
  38. password: ${{ secrets.DOCKERHUB_TOKEN }}
  39. - name: Build and push frontend
  40. uses: docker/build-push-action@v4
  41. with:
  42. context: ./frontend
  43. file: ./frontend/Dockerfile
  44. push: true
  45. tags: 537yaha/ai-cs-frontend:latest
  46. platforms: linux/amd64,linux/arm64
  47. # 前端统一走同域 /api(由反向代理转发到后端),无需在构建时注入 localhost/端口