docker.yml 6.3 KB

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