docker.yml 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. name: Docker
  2. on:
  3. push:
  4. branches:
  5. - main
  6. pull_request:
  7. paths:
  8. - '.trivy.yaml'
  9. - 'Dockerfile'
  10. - 'docker/**'
  11. - '.github/workflows/docker.yml'
  12. release:
  13. types: [ published ]
  14. jobs:
  15. buildx:
  16. if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' && github.repository == 'gogs/gogs' }}
  17. concurrency:
  18. group: ${{ github.workflow }}-${{ github.ref }}
  19. cancel-in-progress: true
  20. runs-on: ubuntu-latest
  21. permissions:
  22. actions: write
  23. contents: read
  24. packages: write
  25. steps:
  26. - name: Checkout code
  27. uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
  28. - name: Set up QEMU
  29. uses: docker/setup-qemu-action@c7c53464625b32c7a7e944ae62b3e17d2b600130 # v3.7.0
  30. with:
  31. platforms: linux/amd64,linux/arm64,linux/arm/v7
  32. - name: Set up Docker Buildx
  33. id: buildx
  34. uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3.11.1
  35. - name: Inspect builder
  36. run: |
  37. echo "Name: ${{ steps.buildx.outputs.name }}"
  38. echo "Endpoint: ${{ steps.buildx.outputs.endpoint }}"
  39. echo "Status: ${{ steps.buildx.outputs.status }}"
  40. echo "Flags: ${{ steps.buildx.outputs.flags }}"
  41. echo "Platforms: ${{ steps.buildx.outputs.platforms }}"
  42. - name: Login to Docker Hub
  43. uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6.0
  44. with:
  45. username: ${{ secrets.DOCKERHUB_USERNAME }}
  46. password: ${{ secrets.DOCKERHUB_TOKEN }}
  47. - name: Login to GitHub Container registry
  48. uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6.0
  49. with:
  50. registry: ghcr.io
  51. username: ${{ github.repository_owner }}
  52. password: ${{ secrets.GITHUB_TOKEN }}
  53. - name: Login to DigitalOcean Container registry
  54. uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6.0
  55. with:
  56. registry: registry.digitalocean.com
  57. username: ${{ secrets.DIGITALOCEAN_USERNAME }}
  58. password: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}
  59. - name: Build and push images
  60. uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0
  61. with:
  62. context: .
  63. platforms: linux/amd64,linux/arm64,linux/arm/v7
  64. push: true
  65. tags: |
  66. gogs/gogs:latest
  67. ghcr.io/gogs/gogs:latest
  68. registry.digitalocean.com/gogs/gogs:latest
  69. - name: Scan for container vulnerabilities
  70. uses: aquasecurity/trivy-action@b6643a29fecd7f34b3597bc6acb0a98b03d33ff8 # 0.33.1
  71. with:
  72. image-ref: gogs/gogs:latest
  73. exit-code: '1'
  74. - name: Send email on failure
  75. uses: dawidd6/action-send-mail@2cea9617b09d79a095af21254fbcb7ae95903dde # v3.12.0
  76. if: ${{ failure() }}
  77. with:
  78. server_address: smtp.mailgun.org
  79. server_port: 465
  80. username: ${{ secrets.SMTP_USERNAME }}
  81. password: ${{ secrets.SMTP_PASSWORD }}
  82. subject: GitHub Actions (${{ github.repository }}) job result
  83. to: github-actions-8ce6454@unknwon.io
  84. from: GitHub Actions (${{ github.repository }})
  85. reply_to: noreply@unknwon.io
  86. body: |
  87. The job "${{ github.job }}" of ${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }} completed with "${{ job.status }}".
  88. View the job run at: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
  89. deploy-demo:
  90. if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' && github.repository == 'gogs/gogs' }}
  91. needs: buildx
  92. runs-on: ubuntu-latest
  93. permissions:
  94. contents: read
  95. steps:
  96. - name: Configure kubectl
  97. run: |
  98. mkdir -p ~/.kube
  99. echo "${KUBECONFIG}" | base64 -d > ~/.kube/config
  100. env:
  101. KUBECONFIG: ${{ secrets.DIGITALOCEAN_K8S_CLUSTER_KUBECONFIG }}
  102. - name: Restart gogs-demo deployment
  103. timeout-minutes: 5
  104. run: |
  105. set -ex
  106. kubectl rollout restart deployment gogs-demo -n gogs
  107. kubectl rollout status deployment gogs-demo -n gogs
  108. - name: Send email on failure
  109. uses: dawidd6/action-send-mail@2cea9617b09d79a095af21254fbcb7ae95903dde # v3.12.0
  110. if: ${{ failure() }}
  111. with:
  112. server_address: smtp.mailgun.org
  113. server_port: 465
  114. username: ${{ secrets.SMTP_USERNAME }}
  115. password: ${{ secrets.SMTP_PASSWORD }}
  116. subject: GitHub Actions (${{ github.repository }}) job result
  117. to: github-actions-8ce6454@unknwon.io
  118. from: GitHub Actions (${{ github.repository }})
  119. reply_to: noreply@unknwon.io
  120. body: |
  121. The job "${{ github.job }}" of ${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }} completed with "${{ job.status }}".
  122. View the job run at: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
  123. buildx-pull-request:
  124. if: ${{ github.event_name == 'pull_request'}}
  125. runs-on: ubuntu-latest
  126. permissions:
  127. contents: read
  128. steps:
  129. - name: Checkout code
  130. uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
  131. - name: Set up Docker Buildx
  132. id: buildx
  133. uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3.11.1
  134. with:
  135. config-inline: |
  136. [worker.oci]
  137. max-parallelism = 2
  138. - name: Inspect builder
  139. run: |
  140. echo "Name: ${{ steps.buildx.outputs.name }}"
  141. echo "Endpoint: ${{ steps.buildx.outputs.endpoint }}"
  142. echo "Status: ${{ steps.buildx.outputs.status }}"
  143. echo "Flags: ${{ steps.buildx.outputs.flags }}"
  144. echo "Platforms: ${{ steps.buildx.outputs.platforms }}"
  145. - name: Compute short commit SHA
  146. id: short-sha
  147. uses: benjlevesque/short-sha@599815c8ee942a9616c92bcfb4f947a3b670ab0b # v3.0
  148. - name: Build and push images
  149. uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0
  150. with:
  151. context: .
  152. platforms: linux/amd64
  153. push: true
  154. tags: |
  155. ttl.sh/gogs/gogs-${{ steps.short-sha.outputs.sha }}:1d
  156. - name: Scan for container vulnerabilities
  157. uses: aquasecurity/trivy-action@b6643a29fecd7f34b3597bc6acb0a98b03d33ff8 # 0.33.1
  158. with:
  159. image-ref: ttl.sh/gogs/gogs-${{ steps.short-sha.outputs.sha }}:1d
  160. exit-code: '1'
  161. # Updates to the following section needs to be synced to all release branches within their lifecycles.
  162. buildx-release:
  163. if: ${{ github.event_name == 'release' }}
  164. runs-on: ubuntu-latest
  165. permissions:
  166. actions: write
  167. contents: read
  168. packages: write
  169. steps:
  170. - name: Compute image tag name
  171. run: echo "IMAGE_TAG=$(echo $GITHUB_REF_NAME | cut -c 2-)" >> $GITHUB_ENV
  172. - name: Checkout code
  173. uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
  174. - name: Set up QEMU
  175. uses: docker/setup-qemu-action@c7c53464625b32c7a7e944ae62b3e17d2b600130 # v3.7.0
  176. with:
  177. platforms: linux/amd64,linux/arm64,linux/arm/v7
  178. - name: Set up Docker Buildx
  179. id: buildx
  180. uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3.11.1
  181. - name: Inspect builder
  182. run: |
  183. echo "Name: ${{ steps.buildx.outputs.name }}"
  184. echo "Endpoint: ${{ steps.buildx.outputs.endpoint }}"
  185. echo "Status: ${{ steps.buildx.outputs.status }}"
  186. echo "Flags: ${{ steps.buildx.outputs.flags }}"
  187. echo "Platforms: ${{ steps.buildx.outputs.platforms }}"
  188. - name: Login to Docker Hub
  189. uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6.0
  190. with:
  191. username: ${{ secrets.DOCKERHUB_USERNAME }}
  192. password: ${{ secrets.DOCKERHUB_TOKEN }}
  193. - name: Login to GitHub Container registry
  194. uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6.0
  195. with:
  196. registry: ghcr.io
  197. username: ${{ github.repository_owner }}
  198. password: ${{ secrets.GITHUB_TOKEN }}
  199. - name: Build and push images
  200. uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0
  201. with:
  202. context: .
  203. platforms: linux/amd64,linux/arm64,linux/arm/v7
  204. push: true
  205. tags: |
  206. gogs/gogs:${{ env.IMAGE_TAG }}
  207. ghcr.io/gogs/gogs:${{ env.IMAGE_TAG }}
  208. - name: Send email on failure
  209. uses: dawidd6/action-send-mail@2cea9617b09d79a095af21254fbcb7ae95903dde # v3.12.0
  210. if: ${{ failure() }}
  211. with:
  212. server_address: smtp.mailgun.org
  213. server_port: 465
  214. username: ${{ secrets.SMTP_USERNAME }}
  215. password: ${{ secrets.SMTP_PASSWORD }}
  216. subject: GitHub Actions (${{ github.repository }}) job result
  217. to: github-actions-8ce6454@unknwon.io
  218. from: GitHub Actions (${{ github.repository }})
  219. reply_to: noreply@unknwon.io
  220. body: |
  221. The job "${{ github.job }}" of ${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }} completed with "${{ job.status }}".
  222. View the job run at: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}