1
0

docker.yml 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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@v4
  28. - name: Set up QEMU
  29. uses: docker/setup-qemu-action@v3
  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@v3
  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@v3
  44. with:
  45. username: ${{ secrets.DOCKERHUB_USERNAME }}
  46. password: ${{ secrets.DOCKERHUB_TOKEN }}
  47. - name: Login to GitHub Container registry
  48. uses: docker/login-action@v3
  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@v3
  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@v5
  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@master
  71. with:
  72. image-ref: gogs/gogs:latest
  73. exit-code: '1'
  74. - name: Send email on failure
  75. uses: dawidd6/action-send-mail@v3
  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: Install doctl
  97. uses: digitalocean/action-doctl@v2
  98. with:
  99. token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}
  100. - name: Configure kubectl
  101. run: doctl kubernetes cluster kubeconfig save ${{ secrets.DIGITALOCEAN_K8S_CLUSTER_ID }}
  102. - name: Restart gogs-demo deployment
  103. run: |
  104. kubectl rollout restart deployment gogs-demo -n gogs
  105. kubectl rollout status deployment gogs-demo -n gogs
  106. - name: Send email on failure
  107. uses: dawidd6/action-send-mail@v3
  108. if: ${{ failure() }}
  109. with:
  110. server_address: smtp.mailgun.org
  111. server_port: 465
  112. username: ${{ secrets.SMTP_USERNAME }}
  113. password: ${{ secrets.SMTP_PASSWORD }}
  114. subject: GitHub Actions (${{ github.repository }}) job result
  115. to: github-actions-8ce6454@unknwon.io
  116. from: GitHub Actions (${{ github.repository }})
  117. reply_to: noreply@unknwon.io
  118. body: |
  119. The job "${{ github.job }}" of ${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }} completed with "${{ job.status }}".
  120. View the job run at: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
  121. buildx-pull-request:
  122. if: ${{ github.event_name == 'pull_request'}}
  123. runs-on: ubuntu-latest
  124. permissions:
  125. contents: read
  126. steps:
  127. - name: Checkout code
  128. uses: actions/checkout@v4
  129. - name: Set up Docker Buildx
  130. id: buildx
  131. uses: docker/setup-buildx-action@v2
  132. with:
  133. config-inline: |
  134. [worker.oci]
  135. max-parallelism = 2
  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: Compute short commit SHA
  144. id: short-sha
  145. uses: benjlevesque/short-sha@v2.1
  146. - name: Build and push images
  147. uses: docker/build-push-action@v5
  148. with:
  149. context: .
  150. platforms: linux/amd64
  151. push: true
  152. tags: |
  153. ttl.sh/gogs/gogs-${{ steps.short-sha.outputs.sha }}:1d
  154. - name: Scan for container vulnerabilities
  155. uses: aquasecurity/trivy-action@master
  156. with:
  157. image-ref: ttl.sh/gogs/gogs-${{ steps.short-sha.outputs.sha }}:1d
  158. exit-code: '1'
  159. # Updates to the following section needs to be synced to all release branches within their lifecycles.
  160. buildx-release:
  161. if: ${{ github.event_name == 'release' }}
  162. runs-on: ubuntu-latest
  163. permissions:
  164. actions: write
  165. contents: read
  166. packages: write
  167. steps:
  168. - name: Compute image tag name
  169. run: echo "IMAGE_TAG=$(echo $GITHUB_REF_NAME | cut -c 2-)" >> $GITHUB_ENV
  170. - name: Checkout code
  171. uses: actions/checkout@v4
  172. - name: Set up QEMU
  173. uses: docker/setup-qemu-action@v3
  174. with:
  175. platforms: linux/amd64,linux/arm64,linux/arm/v7
  176. - name: Set up Docker Buildx
  177. id: buildx
  178. uses: docker/setup-buildx-action@v3
  179. - name: Inspect builder
  180. run: |
  181. echo "Name: ${{ steps.buildx.outputs.name }}"
  182. echo "Endpoint: ${{ steps.buildx.outputs.endpoint }}"
  183. echo "Status: ${{ steps.buildx.outputs.status }}"
  184. echo "Flags: ${{ steps.buildx.outputs.flags }}"
  185. echo "Platforms: ${{ steps.buildx.outputs.platforms }}"
  186. - name: Login to Docker Hub
  187. uses: docker/login-action@v3
  188. with:
  189. username: ${{ secrets.DOCKERHUB_USERNAME }}
  190. password: ${{ secrets.DOCKERHUB_TOKEN }}
  191. - name: Login to GitHub Container registry
  192. uses: docker/login-action@v3
  193. with:
  194. registry: ghcr.io
  195. username: ${{ github.repository_owner }}
  196. password: ${{ secrets.GITHUB_TOKEN }}
  197. - name: Build and push images
  198. uses: docker/build-push-action@v5
  199. with:
  200. context: .
  201. platforms: linux/amd64,linux/arm64,linux/arm/v7
  202. push: true
  203. tags: |
  204. gogs/gogs:${{ env.IMAGE_TAG }}
  205. ghcr.io/gogs/gogs:${{ env.IMAGE_TAG }}
  206. - name: Send email on failure
  207. uses: dawidd6/action-send-mail@v3
  208. if: ${{ failure() }}
  209. with:
  210. server_address: smtp.mailgun.org
  211. server_port: 465
  212. username: ${{ secrets.SMTP_USERNAME }}
  213. password: ${{ secrets.SMTP_PASSWORD }}
  214. subject: GitHub Actions (${{ github.repository }}) job result
  215. to: github-actions-8ce6454@unknwon.io
  216. from: GitHub Actions (${{ github.repository }})
  217. reply_to: noreply@unknwon.io
  218. body: |
  219. The job "${{ github.job }}" of ${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }} completed with "${{ job.status }}".
  220. View the job run at: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}