1
0

docker.yml 9.4 KB

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