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