1
0

docker.yml 7.6 KB

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