docker.yml 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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/cancel-workflow-action@0.9.1
  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: github-actions-8ce6454@unknwon.io
  75. from: GitHub Actions (${{ github.repository }})
  76. reply_to: noreply@unknwon.io
  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/short-sha@v1.2
  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. buildx-release:
  145. if: ${{ github.event_name == 'release' }}
  146. runs-on: ubuntu-latest
  147. permissions:
  148. actions: write
  149. contents: read
  150. packages: write
  151. steps:
  152. - name: Compute image tag name
  153. run: echo "IMAGE_TAG=$(echo $GITHUB_REF_NAME | cut -c 2-)" >> $GITHUB_ENV
  154. - name: Checkout code
  155. uses: actions/checkout@v2
  156. - name: Set up QEMU
  157. uses: docker/setup-qemu-action@v1
  158. - name: Set up Docker Buildx
  159. id: buildx
  160. uses: docker/setup-buildx-action@v1
  161. with:
  162. config-inline: |
  163. [worker.oci]
  164. max-parallelism = 2
  165. - name: Inspect builder
  166. run: |
  167. echo "Name: ${{ steps.buildx.outputs.name }}"
  168. echo "Endpoint: ${{ steps.buildx.outputs.endpoint }}"
  169. echo "Status: ${{ steps.buildx.outputs.status }}"
  170. echo "Flags: ${{ steps.buildx.outputs.flags }}"
  171. echo "Platforms: ${{ steps.buildx.outputs.platforms }}"
  172. - name: Login to Docker Hub
  173. uses: docker/login-action@v1
  174. with:
  175. username: ${{ secrets.DOCKERHUB_USERNAME }}
  176. password: ${{ secrets.DOCKERHUB_TOKEN }}
  177. - name: Login to GitHub Container registry
  178. uses: docker/login-action@v1
  179. with:
  180. registry: ghcr.io
  181. username: ${{ github.repository_owner }}
  182. password: ${{ secrets.GITHUB_TOKEN }}
  183. - name: Build and push images
  184. uses: docker/build-push-action@v2
  185. with:
  186. context: .
  187. platforms: linux/amd64,linux/arm64,linux/arm/v7
  188. push: true
  189. tags: |
  190. gogs/gogs:${{ env.IMAGE_TAG }}
  191. ghcr.io/gogs/gogs:${{ env.IMAGE_TAG }}
  192. - name: Send email on failure
  193. uses: dawidd6/action-send-mail@v3
  194. if: ${{ failure() }}
  195. with:
  196. server_address: smtp.mailgun.org
  197. server_port: 465
  198. username: ${{ secrets.SMTP_USERNAME }}
  199. password: ${{ secrets.SMTP_PASSWORD }}
  200. subject: GitHub Actions (${{ github.repository }}) job result
  201. to: github-actions-8ce6454@unknwon.io
  202. from: GitHub Actions (${{ github.repository }})
  203. reply_to: noreply@unknwon.io
  204. body: |
  205. The job "${{ github.job }}" of ${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }} completed with "${{ job.status }}".
  206. View the job run at: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}