docker.yml 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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' }}
  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-release:
  118. if: ${{ github.event_name == 'release' }}
  119. runs-on: ubuntu-latest
  120. permissions:
  121. actions: write
  122. contents: read
  123. packages: write
  124. steps:
  125. - name: Compute image tag name
  126. run: echo "IMAGE_TAG=$(echo $GITHUB_REF_NAME | cut -c 2-)" >> $GITHUB_ENV
  127. - name: Checkout code
  128. uses: actions/checkout@v2
  129. - name: Set up QEMU
  130. uses: docker/setup-qemu-action@v1
  131. - name: Set up Docker Buildx
  132. id: buildx
  133. uses: docker/setup-buildx-action@v1
  134. with:
  135. config-inline: |
  136. [worker.oci]
  137. max-parallelism = 2
  138. - name: Inspect builder
  139. run: |
  140. echo "Name: ${{ steps.buildx.outputs.name }}"
  141. echo "Endpoint: ${{ steps.buildx.outputs.endpoint }}"
  142. echo "Status: ${{ steps.buildx.outputs.status }}"
  143. echo "Flags: ${{ steps.buildx.outputs.flags }}"
  144. echo "Platforms: ${{ steps.buildx.outputs.platforms }}"
  145. - name: Login to Docker Hub
  146. uses: docker/login-action@v1
  147. with:
  148. username: ${{ secrets.DOCKERHUB_USERNAME }}
  149. password: ${{ secrets.DOCKERHUB_TOKEN }}
  150. - name: Login to GitHub Container registry
  151. uses: docker/login-action@v1
  152. with:
  153. registry: ghcr.io
  154. username: ${{ github.repository_owner }}
  155. password: ${{ secrets.GITHUB_TOKEN }}
  156. - name: Build and push images
  157. uses: docker/build-push-action@v2
  158. with:
  159. context: .
  160. platforms: linux/amd64,linux/arm64,linux/arm/v7
  161. push: true
  162. tags: |
  163. gogs/gogs:${{ env.IMAGE_TAG }}
  164. ghcr.io/gogs/gogs:${{ env.IMAGE_TAG }}
  165. - name: Send email on failure
  166. uses: dawidd6/action-send-mail@v3
  167. if: ${{ failure() }}
  168. with:
  169. server_address: smtp.mailgun.org
  170. server_port: 465
  171. username: ${{ secrets.SMTP_USERNAME }}
  172. password: ${{ secrets.SMTP_PASSWORD }}
  173. subject: GitHub Actions (${{ github.repository }}) job result
  174. to: [email protected]
  175. from: GitHub Actions (${{ github.repository }})
  176. reply_to: [email protected]
  177. body: |
  178. The job "${{ github.job }}" of ${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }} completed with "${{ job.status }}".
  179. View the job run at: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}