docker.yml 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. name: Docker
  2. on:
  3. push:
  4. branches:
  5. - main
  6. pull_request:
  7. paths:
  8. - '.trivy.yaml'
  9. - 'Dockerfile'
  10. - 'docker/**'
  11. - '.github/workflows/docker.yml'
  12. release:
  13. types: [ published ]
  14. jobs:
  15. buildx:
  16. if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
  17. concurrency:
  18. group: ${{ github.workflow }}-${{ github.ref }}
  19. cancel-in-progress: true
  20. runs-on: ubuntu-latest
  21. permissions:
  22. actions: write
  23. contents: read
  24. packages: write
  25. steps:
  26. - name: Checkout code
  27. uses: actions/checkout@v4
  28. - name: Set up QEMU
  29. uses: docker/setup-qemu-action@v3
  30. with:
  31. platforms: linux/amd64,linux/arm64,linux/arm/v7
  32. - name: Set up Docker Buildx
  33. id: buildx
  34. uses: docker/setup-buildx-action@v3
  35. - name: Inspect builder
  36. run: |
  37. echo "Name: ${{ steps.buildx.outputs.name }}"
  38. echo "Endpoint: ${{ steps.buildx.outputs.endpoint }}"
  39. echo "Status: ${{ steps.buildx.outputs.status }}"
  40. echo "Flags: ${{ steps.buildx.outputs.flags }}"
  41. echo "Platforms: ${{ steps.buildx.outputs.platforms }}"
  42. - name: Login to Docker Hub
  43. uses: docker/login-action@v3
  44. with:
  45. username: ${{ secrets.DOCKERHUB_USERNAME }}
  46. password: ${{ secrets.DOCKERHUB_TOKEN }}
  47. - name: Login to GitHub Container registry
  48. uses: docker/login-action@v3
  49. with:
  50. registry: ghcr.io
  51. username: ${{ github.repository_owner }}
  52. password: ${{ secrets.GITHUB_TOKEN }}
  53. - name: Login to DigitalOcean Container registry
  54. uses: docker/login-action@v3
  55. with:
  56. registry: registry.digitalocean.com
  57. username: ${{ secrets.DIGITALOCEAN_USERNAME }}
  58. password: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}
  59. - name: Build and push images
  60. uses: docker/build-push-action@v5
  61. with:
  62. context: .
  63. platforms: linux/amd64,linux/arm64,linux/arm/v7
  64. push: true
  65. tags: |
  66. gogs/gogs:latest
  67. ghcr.io/gogs/gogs:latest
  68. registry.digitalocean.com/gogs/gogs:latest
  69. - name: Scan for container vulnerabilities
  70. uses: aquasecurity/trivy-action@master
  71. with:
  72. image-ref: gogs/gogs:latest
  73. exit-code: '1'
  74. - name: Send email on failure
  75. uses: dawidd6/action-send-mail@v3
  76. if: ${{ failure() }}
  77. with:
  78. server_address: smtp.mailgun.org
  79. server_port: 465
  80. username: ${{ secrets.SMTP_USERNAME }}
  81. password: ${{ secrets.SMTP_PASSWORD }}
  82. subject: GitHub Actions (${{ github.repository }}) job result
  83. to: github-actions-8ce6454@unknwon.io
  84. from: GitHub Actions (${{ github.repository }})
  85. reply_to: noreply@unknwon.io
  86. body: |
  87. The job "${{ github.job }}" of ${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }} completed with "${{ job.status }}".
  88. View the job run at: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
  89. buildx-pull-request:
  90. if: ${{ github.event_name == 'pull_request'}}
  91. runs-on: ubuntu-latest
  92. permissions:
  93. contents: read
  94. steps:
  95. - name: Checkout code
  96. uses: actions/checkout@v4
  97. - name: Set up Docker Buildx
  98. id: buildx
  99. uses: docker/setup-buildx-action@v2
  100. with:
  101. config-inline: |
  102. [worker.oci]
  103. max-parallelism = 2
  104. - name: Inspect builder
  105. run: |
  106. echo "Name: ${{ steps.buildx.outputs.name }}"
  107. echo "Endpoint: ${{ steps.buildx.outputs.endpoint }}"
  108. echo "Status: ${{ steps.buildx.outputs.status }}"
  109. echo "Flags: ${{ steps.buildx.outputs.flags }}"
  110. echo "Platforms: ${{ steps.buildx.outputs.platforms }}"
  111. - name: Compute short commit SHA
  112. id: short-sha
  113. uses: benjlevesque/short-sha@v2.1
  114. - name: Build and push images
  115. uses: docker/build-push-action@v5
  116. with:
  117. context: .
  118. platforms: linux/amd64
  119. push: true
  120. tags: |
  121. ttl.sh/gogs/gogs-${{ steps.short-sha.outputs.sha }}:1d
  122. - name: Scan for container vulnerabilities
  123. uses: aquasecurity/trivy-action@master
  124. with:
  125. image-ref: ttl.sh/gogs/gogs-${{ steps.short-sha.outputs.sha }}:1d
  126. exit-code: '1'
  127. # Updates to the following section needs to be synced to all release branches within their lifecycles.
  128. buildx-release:
  129. if: ${{ github.event_name == 'release' }}
  130. runs-on: ubuntu-latest
  131. permissions:
  132. actions: write
  133. contents: read
  134. packages: write
  135. steps:
  136. - name: Compute image tag name
  137. run: echo "IMAGE_TAG=$(echo $GITHUB_REF_NAME | cut -c 2-)" >> $GITHUB_ENV
  138. - name: Checkout code
  139. uses: actions/checkout@v4
  140. - name: Set up QEMU
  141. uses: docker/setup-qemu-action@v3
  142. with:
  143. platforms: linux/amd64,linux/arm64,linux/arm/v7
  144. - name: Set up Docker Buildx
  145. id: buildx
  146. uses: docker/setup-buildx-action@v3
  147. - name: Inspect builder
  148. run: |
  149. echo "Name: ${{ steps.buildx.outputs.name }}"
  150. echo "Endpoint: ${{ steps.buildx.outputs.endpoint }}"
  151. echo "Status: ${{ steps.buildx.outputs.status }}"
  152. echo "Flags: ${{ steps.buildx.outputs.flags }}"
  153. echo "Platforms: ${{ steps.buildx.outputs.platforms }}"
  154. - name: Login to Docker Hub
  155. uses: docker/login-action@v3
  156. with:
  157. username: ${{ secrets.DOCKERHUB_USERNAME }}
  158. password: ${{ secrets.DOCKERHUB_TOKEN }}
  159. - name: Login to GitHub Container registry
  160. uses: docker/login-action@v3
  161. with:
  162. registry: ghcr.io
  163. username: ${{ github.repository_owner }}
  164. password: ${{ secrets.GITHUB_TOKEN }}
  165. - name: Build and push images
  166. uses: docker/build-push-action@v5
  167. with:
  168. context: .
  169. platforms: linux/amd64,linux/arm64,linux/arm/v7
  170. push: true
  171. tags: |
  172. gogs/gogs:${{ env.IMAGE_TAG }}
  173. ghcr.io/gogs/gogs:${{ env.IMAGE_TAG }}
  174. - name: Send email on failure
  175. uses: dawidd6/action-send-mail@v3
  176. if: ${{ failure() }}
  177. with:
  178. server_address: smtp.mailgun.org
  179. server_port: 465
  180. username: ${{ secrets.SMTP_USERNAME }}
  181. password: ${{ secrets.SMTP_PASSWORD }}
  182. subject: GitHub Actions (${{ github.repository }}) job result
  183. to: github-actions-8ce6454@unknwon.io
  184. from: GitHub Actions (${{ github.repository }})
  185. reply_to: noreply@unknwon.io
  186. body: |
  187. The job "${{ github.job }}" of ${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }} completed with "${{ job.status }}".
  188. View the job run at: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}