docker-publish.yml 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. name: Docker
  2. on:
  3. push:
  4. branches: [ "main" ]
  5. paths:
  6. - 'Dockerfile'
  7. - 'frontend/Dockerfile'
  8. - 'frontend/**'
  9. - 'requirements.txt'
  10. - 'VERSION'
  11. - '**.py'
  12. pull_request:
  13. branches: [ "main" ]
  14. paths:
  15. - 'Dockerfile'
  16. - 'frontend/Dockerfile'
  17. - 'frontend/**'
  18. - 'requirements.txt'
  19. - 'VERSION'
  20. - '**.py'
  21. # Allow manual trigger on any branch
  22. workflow_dispatch:
  23. inputs:
  24. branch:
  25. description: 'Branch to build from'
  26. required: false
  27. default: ''
  28. env:
  29. REGISTRY: ghcr.io
  30. jobs:
  31. build-backend:
  32. if: github.event_name != 'pull_request' || github.actor == 'tuanchris'
  33. runs-on: ubuntu-latest
  34. permissions:
  35. contents: read
  36. packages: write
  37. id-token: write
  38. steps:
  39. - name: Checkout repository
  40. uses: actions/checkout@v4
  41. - name: Set up Docker Buildx
  42. uses: docker/setup-buildx-action@v3
  43. - name: Log into registry ${{ env.REGISTRY }}
  44. uses: docker/login-action@v3
  45. with:
  46. registry: ${{ env.REGISTRY }}
  47. username: ${{ github.actor }}
  48. password: ${{ secrets.GITHUB_TOKEN }}
  49. - name: Extract Docker metadata
  50. id: meta
  51. uses: docker/metadata-action@v5
  52. with:
  53. images: ${{ env.REGISTRY }}/${{ github.repository }}
  54. - name: Build and push backend image
  55. uses: docker/build-push-action@v5
  56. with:
  57. context: .
  58. push: true
  59. tags: ${{ steps.meta.outputs.tags }}
  60. labels: ${{ steps.meta.outputs.labels }}
  61. platforms: linux/amd64,linux/arm64
  62. cache-from: type=gha,scope=backend
  63. cache-to: type=gha,mode=max,scope=backend
  64. build-frontend:
  65. if: github.event_name != 'pull_request' || github.actor == 'tuanchris'
  66. runs-on: ubuntu-latest
  67. permissions:
  68. contents: read
  69. packages: write
  70. id-token: write
  71. steps:
  72. - name: Checkout repository
  73. uses: actions/checkout@v4
  74. - name: Set up Docker Buildx
  75. uses: docker/setup-buildx-action@v3
  76. - name: Log into registry ${{ env.REGISTRY }}
  77. uses: docker/login-action@v3
  78. with:
  79. registry: ${{ env.REGISTRY }}
  80. username: ${{ github.actor }}
  81. password: ${{ secrets.GITHUB_TOKEN }}
  82. - name: Extract Docker metadata
  83. id: meta
  84. uses: docker/metadata-action@v5
  85. with:
  86. images: ${{ env.REGISTRY }}/${{ github.repository }}-frontend
  87. - name: Build and push frontend image
  88. uses: docker/build-push-action@v5
  89. with:
  90. context: ./frontend
  91. file: ./frontend/Dockerfile
  92. push: true
  93. tags: ${{ steps.meta.outputs.tags }}
  94. labels: ${{ steps.meta.outputs.labels }}
  95. platforms: linux/amd64,linux/arm64
  96. cache-from: type=gha,scope=frontend
  97. cache-to: type=gha,mode=max,scope=frontend