docker.yml 7.5 KB

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