docker.yml 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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: Build and push images
  53. uses: docker/build-push-action@v5
  54. with:
  55. context: .
  56. platforms: linux/amd64,linux/arm64,linux/arm/v7
  57. push: true
  58. tags: |
  59. gogs/gogs:latest
  60. ghcr.io/gogs/gogs:latest
  61. - name: Send email on failure
  62. uses: dawidd6/action-send-mail@v3
  63. if: ${{ failure() }}
  64. with:
  65. server_address: smtp.mailgun.org
  66. server_port: 465
  67. username: ${{ secrets.SMTP_USERNAME }}
  68. password: ${{ secrets.SMTP_PASSWORD }}
  69. subject: GitHub Actions (${{ github.repository }}) job result
  70. to: github-actions-8ce6454@unknwon.io
  71. from: GitHub Actions (${{ github.repository }})
  72. reply_to: noreply@unknwon.io
  73. body: |
  74. The job "${{ github.job }}" of ${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }} completed with "${{ job.status }}".
  75. View the job run at: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
  76. buildx-pull-request:
  77. if: ${{ github.event_name == 'pull_request'}}
  78. runs-on: ubuntu-latest
  79. permissions:
  80. contents: read
  81. steps:
  82. - name: Checkout code
  83. uses: actions/checkout@v4
  84. - name: Set up Docker Buildx
  85. id: buildx
  86. uses: docker/setup-buildx-action@v2
  87. with:
  88. config-inline: |
  89. [worker.oci]
  90. max-parallelism = 2
  91. - name: Inspect builder
  92. run: |
  93. echo "Name: ${{ steps.buildx.outputs.name }}"
  94. echo "Endpoint: ${{ steps.buildx.outputs.endpoint }}"
  95. echo "Status: ${{ steps.buildx.outputs.status }}"
  96. echo "Flags: ${{ steps.buildx.outputs.flags }}"
  97. echo "Platforms: ${{ steps.buildx.outputs.platforms }}"
  98. - name: Compute short commit SHA
  99. id: short-sha
  100. uses: benjlevesque/short-sha@v2.1
  101. - name: Build and push images
  102. uses: docker/build-push-action@v5
  103. with:
  104. context: .
  105. platforms: linux/amd64
  106. push: true
  107. tags: |
  108. ttl.sh/gogs/gogs-${{ steps.short-sha.outputs.sha }}:1d
  109. # Updates to the following section needs to be synced to all release branches within their lifecycles.
  110. buildx-release:
  111. if: ${{ github.event_name == 'release' }}
  112. runs-on: ubuntu-latest
  113. permissions:
  114. actions: write
  115. contents: read
  116. packages: write
  117. steps:
  118. - name: Compute image tag name
  119. run: echo "IMAGE_TAG=$(echo $GITHUB_REF_NAME | cut -c 2-)" >> $GITHUB_ENV
  120. - name: Checkout code
  121. uses: actions/checkout@v4
  122. - name: Set up QEMU
  123. uses: docker/setup-qemu-action@v3
  124. with:
  125. platforms: linux/amd64,linux/arm64,linux/arm/v7
  126. - name: Set up Docker Buildx
  127. id: buildx
  128. uses: docker/setup-buildx-action@v3
  129. - name: Inspect builder
  130. run: |
  131. echo "Name: ${{ steps.buildx.outputs.name }}"
  132. echo "Endpoint: ${{ steps.buildx.outputs.endpoint }}"
  133. echo "Status: ${{ steps.buildx.outputs.status }}"
  134. echo "Flags: ${{ steps.buildx.outputs.flags }}"
  135. echo "Platforms: ${{ steps.buildx.outputs.platforms }}"
  136. - name: Login to Docker Hub
  137. uses: docker/login-action@v3
  138. with:
  139. username: ${{ secrets.DOCKERHUB_USERNAME }}
  140. password: ${{ secrets.DOCKERHUB_TOKEN }}
  141. - name: Login to GitHub Container registry
  142. uses: docker/login-action@v3
  143. with:
  144. registry: ghcr.io
  145. username: ${{ github.repository_owner }}
  146. password: ${{ secrets.GITHUB_TOKEN }}
  147. - name: Build and push images
  148. uses: docker/build-push-action@v5
  149. with:
  150. context: .
  151. platforms: linux/amd64,linux/arm64,linux/arm/v7
  152. push: true
  153. tags: |
  154. gogs/gogs:${{ env.IMAGE_TAG }}
  155. ghcr.io/gogs/gogs:${{ env.IMAGE_TAG }}
  156. - name: Send email on failure
  157. uses: dawidd6/action-send-mail@v3
  158. if: ${{ failure() }}
  159. with:
  160. server_address: smtp.mailgun.org
  161. server_port: 465
  162. username: ${{ secrets.SMTP_USERNAME }}
  163. password: ${{ secrets.SMTP_PASSWORD }}
  164. subject: GitHub Actions (${{ github.repository }}) job result
  165. to: github-actions-8ce6454@unknwon.io
  166. from: GitHub Actions (${{ github.repository }})
  167. reply_to: noreply@unknwon.io
  168. body: |
  169. The job "${{ github.job }}" of ${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }} completed with "${{ job.status }}".
  170. View the job run at: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}