images.yml 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. name: Build and Push Docker Images
  2. on:
  3. push:
  4. tags:
  5. - "v*"
  6. concurrency:
  7. group: ${{ github.workflow }}-${{ github.ref }}
  8. cancel-in-progress: false
  9. jobs:
  10. build-frontend:
  11. name: Build Frontend
  12. runs-on: ubuntu-latest
  13. environment: production
  14. permissions:
  15. contents: read
  16. packages: write
  17. security-events: write
  18. steps:
  19. - name: Checkout repository
  20. uses: actions/checkout@v6
  21. - name: Set up QEMU
  22. uses: docker/setup-qemu-action@v3
  23. - name: Set up Docker Buildx
  24. uses: docker/setup-buildx-action@v3
  25. - name: Login to Docker Hub
  26. uses: docker/login-action@v3
  27. with:
  28. username: ${{ secrets.DOCKERHUB_USERNAME }}
  29. password: ${{ secrets.DOCKERHUB_TOKEN }}
  30. - name: Login to GitHub Container Registry
  31. uses: docker/login-action@v3
  32. with:
  33. registry: ghcr.io
  34. username: ${{ github.actor }}
  35. password: ${{ secrets.GITHUB_TOKEN }}
  36. - name: Extract metadata
  37. id: meta
  38. uses: docker/metadata-action@v5
  39. with:
  40. images: |
  41. ${{ github.repository_owner }}/flowsint-app
  42. ghcr.io/${{ github.repository_owner }}/flowsint-app
  43. tags: |
  44. type=semver,pattern={{version}}
  45. type=semver,pattern={{major}}.{{minor}}
  46. type=raw,value=latest
  47. - name: Build and push
  48. uses: docker/build-push-action@v6
  49. with:
  50. context: ./flowsint-app
  51. file: ./flowsint-app/Dockerfile
  52. platforms: linux/amd64,linux/arm64
  53. push: true
  54. tags: ${{ steps.meta.outputs.tags }}
  55. labels: ${{ steps.meta.outputs.labels }}
  56. cache-from: type=gha
  57. cache-to: type=gha,mode=max
  58. provenance: true
  59. sbom: true
  60. - name: Run Trivy vulnerability scanner
  61. id: trivy
  62. uses: aquasecurity/trivy-action@v0.35.0
  63. with:
  64. image-ref: ghcr.io/${{ github.repository_owner }}/flowsint-app:${{ steps.meta.outputs.version }}
  65. format: "sarif"
  66. output: "trivy-frontend.sarif"
  67. severity: "CRITICAL,HIGH"
  68. - name: Upload Trivy scan results
  69. uses: github/codeql-action/upload-sarif@v4
  70. if: always() && steps.trivy.outcome == 'success'
  71. with:
  72. sarif_file: "trivy-frontend.sarif"
  73. build-backend:
  74. name: Build Backend
  75. runs-on: ubuntu-latest
  76. environment: production
  77. permissions:
  78. contents: read
  79. packages: write
  80. security-events: write
  81. steps:
  82. - name: Checkout repository
  83. uses: actions/checkout@v6
  84. - name: Set up QEMU
  85. uses: docker/setup-qemu-action@v3
  86. - name: Set up Docker Buildx
  87. uses: docker/setup-buildx-action@v3
  88. - name: Login to Docker Hub
  89. uses: docker/login-action@v3
  90. with:
  91. username: ${{ secrets.DOCKERHUB_USERNAME }}
  92. password: ${{ secrets.DOCKERHUB_TOKEN }}
  93. - name: Login to GitHub Container Registry
  94. uses: docker/login-action@v3
  95. with:
  96. registry: ghcr.io
  97. username: ${{ github.actor }}
  98. password: ${{ secrets.GITHUB_TOKEN }}
  99. - name: Extract metadata
  100. id: meta
  101. uses: docker/metadata-action@v5
  102. with:
  103. images: |
  104. ${{ github.repository_owner }}/flowsint-api
  105. ghcr.io/${{ github.repository_owner }}/flowsint-api
  106. tags: |
  107. type=semver,pattern={{version}}
  108. type=semver,pattern={{major}}.{{minor}}
  109. type=raw,value=latest
  110. - name: Build and push
  111. uses: docker/build-push-action@v6
  112. with:
  113. context: .
  114. file: ./flowsint-api/Dockerfile
  115. target: production
  116. platforms: linux/amd64,linux/arm64
  117. push: true
  118. tags: ${{ steps.meta.outputs.tags }}
  119. labels: ${{ steps.meta.outputs.labels }}
  120. cache-from: type=gha
  121. cache-to: type=gha,mode=max
  122. provenance: true
  123. sbom: true
  124. - name: Run Trivy vulnerability scanner
  125. id: trivy
  126. uses: aquasecurity/trivy-action@v0.35.0
  127. with:
  128. image-ref: ghcr.io/${{ github.repository_owner }}/flowsint-api:${{ steps.meta.outputs.version }}
  129. format: "sarif"
  130. output: "trivy-backend.sarif"
  131. severity: "CRITICAL,HIGH"
  132. - name: Upload Trivy scan results
  133. uses: github/codeql-action/upload-sarif@v4
  134. if: always() && steps.trivy.outcome == 'success'
  135. with:
  136. sarif_file: "trivy-backend.sarif"
  137. security-summary:
  138. name: Security Summary
  139. runs-on: ubuntu-latest
  140. needs: [build-frontend, build-backend]
  141. if: always()
  142. steps:
  143. - name: Summary
  144. run: |
  145. echo "## Build Summary" >> $GITHUB_STEP_SUMMARY
  146. echo "" >> $GITHUB_STEP_SUMMARY
  147. echo "| Image | Status |" >> $GITHUB_STEP_SUMMARY
  148. echo "|-------|--------|" >> $GITHUB_STEP_SUMMARY
  149. echo "| Frontend | ${{ needs.build-frontend.result }} |" >> $GITHUB_STEP_SUMMARY
  150. echo "| Backend | ${{ needs.build-backend.result }} |" >> $GITHUB_STEP_SUMMARY
  151. echo "" >> $GITHUB_STEP_SUMMARY
  152. echo "Security scans uploaded to GitHub Security tab." >> $GITHUB_STEP_SUMMARY