docker.yml 6.9 KB

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