docker.yml 6.5 KB

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