docker.yml 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. name: Docker
  2. on:
  3. push:
  4. branches:
  5. - main
  6. pull_request:
  7. paths:
  8. - '.trivy.yaml'
  9. - 'Dockerfile'
  10. - 'Dockerfile.next'
  11. - 'docker/**'
  12. - 'docker-next/**'
  13. - '.github/workflows/docker.yml'
  14. release:
  15. types: [ published ]
  16. jobs:
  17. buildx:
  18. if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' && github.repository == 'gogs/gogs' }}
  19. concurrency:
  20. group: ${{ github.workflow }}-${{ github.ref }}
  21. cancel-in-progress: true
  22. runs-on: ubuntu-latest
  23. permissions:
  24. actions: write
  25. contents: read
  26. packages: write
  27. steps:
  28. - name: Checkout code
  29. uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
  30. - name: Set up QEMU
  31. uses: docker/setup-qemu-action@c7c53464625b32c7a7e944ae62b3e17d2b600130 # v3.7.0
  32. with:
  33. platforms: linux/amd64,linux/arm64,linux/arm/v7
  34. - name: Set up Docker Buildx
  35. id: buildx
  36. uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3.11.1
  37. - name: Inspect builder
  38. run: |
  39. echo "Name: ${{ steps.buildx.outputs.name }}"
  40. echo "Endpoint: ${{ steps.buildx.outputs.endpoint }}"
  41. echo "Status: ${{ steps.buildx.outputs.status }}"
  42. echo "Flags: ${{ steps.buildx.outputs.flags }}"
  43. echo "Platforms: ${{ steps.buildx.outputs.platforms }}"
  44. - name: Login to Docker Hub
  45. uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6.0
  46. with:
  47. username: ${{ secrets.DOCKERHUB_USERNAME }}
  48. password: ${{ secrets.DOCKERHUB_TOKEN }}
  49. - name: Login to GitHub Container registry
  50. uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6.0
  51. with:
  52. registry: ghcr.io
  53. username: ${{ github.repository_owner }}
  54. password: ${{ secrets.GITHUB_TOKEN }}
  55. - name: Build and push images
  56. uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0
  57. with:
  58. context: .
  59. platforms: linux/amd64,linux/arm64,linux/arm/v7
  60. push: true
  61. tags: |
  62. gogs/gogs:latest
  63. ghcr.io/gogs/gogs:latest
  64. - name: Scan for container vulnerabilities
  65. uses: aquasecurity/trivy-action@b6643a29fecd7f34b3597bc6acb0a98b03d33ff8 # 0.33.1
  66. with:
  67. image-ref: gogs/gogs:latest
  68. exit-code: '1'
  69. - name: Send email on failure
  70. uses: unknwon/send-email-on-failure@89339a1bc93f4ad1d30f3b7e4911fcba985c9adb # v1
  71. if: ${{ failure() }}
  72. with:
  73. smtp_username: ${{ secrets.SMTP_USERNAME }}
  74. smtp_password: ${{ secrets.SMTP_PASSWORD }}
  75. buildx-next:
  76. if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' && github.repository == 'gogs/gogs' }}
  77. concurrency:
  78. group: ${{ github.workflow }}-next-${{ github.ref }}
  79. cancel-in-progress: true
  80. runs-on: ubuntu-latest
  81. permissions:
  82. actions: write
  83. contents: read
  84. packages: write
  85. steps:
  86. - name: Checkout code
  87. uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
  88. - name: Set up QEMU
  89. uses: docker/setup-qemu-action@c7c53464625b32c7a7e944ae62b3e17d2b600130 # v3.7.0
  90. with:
  91. platforms: linux/amd64,linux/arm64,linux/arm/v7
  92. - name: Set up Docker Buildx
  93. id: buildx
  94. uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3.11.1
  95. - name: Inspect builder
  96. run: |
  97. echo "Name: ${{ steps.buildx.outputs.name }}"
  98. echo "Endpoint: ${{ steps.buildx.outputs.endpoint }}"
  99. echo "Status: ${{ steps.buildx.outputs.status }}"
  100. echo "Flags: ${{ steps.buildx.outputs.flags }}"
  101. echo "Platforms: ${{ steps.buildx.outputs.platforms }}"
  102. - name: Login to Docker Hub
  103. uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6.0
  104. with:
  105. username: ${{ secrets.DOCKERHUB_USERNAME }}
  106. password: ${{ secrets.DOCKERHUB_TOKEN }}
  107. - name: Login to GitHub Container registry
  108. uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6.0
  109. with:
  110. registry: ghcr.io
  111. username: ${{ github.repository_owner }}
  112. password: ${{ secrets.GITHUB_TOKEN }}
  113. - name: Login to DigitalOcean Container registry
  114. uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6.0
  115. with:
  116. registry: registry.digitalocean.com
  117. username: ${{ secrets.DIGITALOCEAN_USERNAME }}
  118. password: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}
  119. - name: Build and push next-gen images
  120. uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0
  121. with:
  122. context: .
  123. file: Dockerfile.next
  124. platforms: linux/amd64,linux/arm64,linux/arm/v7
  125. push: true
  126. tags: |
  127. gogs/gogs:next-latest
  128. ghcr.io/gogs/gogs:next-latest
  129. registry.digitalocean.com/gogs/gogs:next-latest
  130. - name: Scan for container vulnerabilities
  131. uses: aquasecurity/trivy-action@b6643a29fecd7f34b3597bc6acb0a98b03d33ff8 # 0.33.1
  132. with:
  133. image-ref: gogs/gogs:next-latest
  134. exit-code: '1'
  135. - name: Send email on failure
  136. uses: unknwon/send-email-on-failure@89339a1bc93f4ad1d30f3b7e4911fcba985c9adb # v1
  137. if: ${{ failure() }}
  138. with:
  139. smtp_username: ${{ secrets.SMTP_USERNAME }}
  140. smtp_password: ${{ secrets.SMTP_PASSWORD }}
  141. deploy-demo:
  142. if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' && github.repository == 'gogs/gogs' }}
  143. needs: buildx-next
  144. runs-on: ubuntu-latest
  145. permissions:
  146. contents: read
  147. steps:
  148. - name: Configure kubectl
  149. run: |
  150. mkdir -p ~/.kube
  151. echo "${KUBECONFIG}" | base64 -d > ~/.kube/config
  152. env:
  153. KUBECONFIG: ${{ secrets.DIGITALOCEAN_K8S_CLUSTER_KUBECONFIG }}
  154. - name: Restart gogs-demo deployment
  155. timeout-minutes: 5
  156. run: |
  157. set -ex
  158. kubectl rollout restart deployment gogs-demo -n gogs
  159. kubectl rollout status deployment gogs-demo -n gogs
  160. - name: Send email on failure
  161. uses: unknwon/send-email-on-failure@89339a1bc93f4ad1d30f3b7e4911fcba985c9adb # v1
  162. if: ${{ failure() }}
  163. with:
  164. smtp_username: ${{ secrets.SMTP_USERNAME }}
  165. smtp_password: ${{ secrets.SMTP_PASSWORD }}
  166. buildx-pull-request:
  167. if: ${{ github.event_name == 'pull_request'}}
  168. runs-on: ubuntu-latest
  169. permissions:
  170. contents: read
  171. steps:
  172. - name: Checkout code
  173. uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
  174. - name: Set up Docker Buildx
  175. id: buildx
  176. uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3.11.1
  177. with:
  178. config-inline: |
  179. [worker.oci]
  180. max-parallelism = 2
  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: Compute short commit SHA
  189. id: short-sha
  190. uses: benjlevesque/short-sha@599815c8ee942a9616c92bcfb4f947a3b670ab0b # v3.0
  191. - name: Build and push images
  192. uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0
  193. with:
  194. context: .
  195. platforms: linux/amd64
  196. push: true
  197. tags: |
  198. ttl.sh/gogs/gogs-${{ steps.short-sha.outputs.sha }}:7d
  199. - name: Scan for container vulnerabilities
  200. uses: aquasecurity/trivy-action@b6643a29fecd7f34b3597bc6acb0a98b03d33ff8 # 0.33.1
  201. with:
  202. image-ref: ttl.sh/gogs/gogs-${{ steps.short-sha.outputs.sha }}:7d
  203. exit-code: '1'
  204. buildx-next-pull-request:
  205. if: ${{ github.event_name == 'pull_request'}}
  206. runs-on: ubuntu-latest
  207. permissions:
  208. contents: read
  209. steps:
  210. - name: Checkout code
  211. uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
  212. - name: Set up Docker Buildx
  213. id: buildx
  214. uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3.11.1
  215. with:
  216. config-inline: |
  217. [worker.oci]
  218. max-parallelism = 2
  219. - name: Inspect builder
  220. run: |
  221. echo "Name: ${{ steps.buildx.outputs.name }}"
  222. echo "Endpoint: ${{ steps.buildx.outputs.endpoint }}"
  223. echo "Status: ${{ steps.buildx.outputs.status }}"
  224. echo "Flags: ${{ steps.buildx.outputs.flags }}"
  225. echo "Platforms: ${{ steps.buildx.outputs.platforms }}"
  226. - name: Compute short commit SHA
  227. id: short-sha
  228. uses: benjlevesque/short-sha@599815c8ee942a9616c92bcfb4f947a3b670ab0b # v3.0
  229. - name: Build and push next-gen images
  230. uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0
  231. with:
  232. context: .
  233. file: Dockerfile.next
  234. platforms: linux/amd64
  235. push: true
  236. tags: |
  237. ttl.sh/gogs/gogs-next-${{ steps.short-sha.outputs.sha }}:7d
  238. - name: Scan for container vulnerabilities
  239. uses: aquasecurity/trivy-action@b6643a29fecd7f34b3597bc6acb0a98b03d33ff8 # 0.33.1
  240. with:
  241. image-ref: ttl.sh/gogs/gogs-next-${{ steps.short-sha.outputs.sha }}:7d
  242. exit-code: '1'
  243. # Updates to the following section needs to be synced to all release branches within their lifecycles.
  244. buildx-release:
  245. if: ${{ github.event_name == 'release' }}
  246. runs-on: ubuntu-latest
  247. permissions:
  248. actions: write
  249. contents: read
  250. packages: write
  251. steps:
  252. - name: Compute image tag name
  253. run: echo "IMAGE_TAG=$(echo $GITHUB_REF_NAME | cut -c 2-)" >> $GITHUB_ENV
  254. - name: Checkout code
  255. uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
  256. - name: Set up QEMU
  257. uses: docker/setup-qemu-action@c7c53464625b32c7a7e944ae62b3e17d2b600130 # v3.7.0
  258. with:
  259. platforms: linux/amd64,linux/arm64,linux/arm/v7
  260. - name: Set up Docker Buildx
  261. id: buildx
  262. uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3.11.1
  263. - name: Inspect builder
  264. run: |
  265. echo "Name: ${{ steps.buildx.outputs.name }}"
  266. echo "Endpoint: ${{ steps.buildx.outputs.endpoint }}"
  267. echo "Status: ${{ steps.buildx.outputs.status }}"
  268. echo "Flags: ${{ steps.buildx.outputs.flags }}"
  269. echo "Platforms: ${{ steps.buildx.outputs.platforms }}"
  270. - name: Login to Docker Hub
  271. uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6.0
  272. with:
  273. username: ${{ secrets.DOCKERHUB_USERNAME }}
  274. password: ${{ secrets.DOCKERHUB_TOKEN }}
  275. - name: Login to GitHub Container registry
  276. uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6.0
  277. with:
  278. registry: ghcr.io
  279. username: ${{ github.repository_owner }}
  280. password: ${{ secrets.GITHUB_TOKEN }}
  281. - name: Build and push images
  282. uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0
  283. with:
  284. context: .
  285. platforms: linux/amd64,linux/arm64,linux/arm/v7
  286. push: true
  287. tags: |
  288. gogs/gogs:${{ env.IMAGE_TAG }}
  289. ghcr.io/gogs/gogs:${{ env.IMAGE_TAG }}
  290. - name: Send email on failure
  291. uses: unknwon/send-email-on-failure@89339a1bc93f4ad1d30f3b7e4911fcba985c9adb # v1
  292. if: ${{ failure() }}
  293. with:
  294. smtp_username: ${{ secrets.SMTP_USERNAME }}
  295. smtp_password: ${{ secrets.SMTP_PASSWORD }}
  296. # Updates to the following section needs to be synced to all release branches within their lifecycles.
  297. buildx-next-release:
  298. if: ${{ github.event_name == 'release' }}
  299. runs-on: ubuntu-latest
  300. permissions:
  301. actions: write
  302. contents: read
  303. packages: write
  304. steps:
  305. - name: Compute image tag name
  306. run: echo "IMAGE_TAG=$(echo $GITHUB_REF_NAME | cut -c 2-)" >> $GITHUB_ENV
  307. - name: Checkout code
  308. uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
  309. - name: Set up QEMU
  310. uses: docker/setup-qemu-action@c7c53464625b32c7a7e944ae62b3e17d2b600130 # v3.7.0
  311. with:
  312. platforms: linux/amd64,linux/arm64,linux/arm/v7
  313. - name: Set up Docker Buildx
  314. id: buildx
  315. uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3.11.1
  316. - name: Inspect builder
  317. run: |
  318. echo "Name: ${{ steps.buildx.outputs.name }}"
  319. echo "Endpoint: ${{ steps.buildx.outputs.endpoint }}"
  320. echo "Status: ${{ steps.buildx.outputs.status }}"
  321. echo "Flags: ${{ steps.buildx.outputs.flags }}"
  322. echo "Platforms: ${{ steps.buildx.outputs.platforms }}"
  323. - name: Login to Docker Hub
  324. uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6.0
  325. with:
  326. username: ${{ secrets.DOCKERHUB_USERNAME }}
  327. password: ${{ secrets.DOCKERHUB_TOKEN }}
  328. - name: Login to GitHub Container registry
  329. uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6.0
  330. with:
  331. registry: ghcr.io
  332. username: ${{ github.repository_owner }}
  333. password: ${{ secrets.GITHUB_TOKEN }}
  334. - name: Build and push next-gen images
  335. uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0
  336. with:
  337. context: .
  338. file: Dockerfile.next
  339. platforms: linux/amd64,linux/arm64,linux/arm/v7
  340. push: true
  341. tags: |
  342. gogs/gogs:next-${{ env.IMAGE_TAG }}
  343. ghcr.io/gogs/gogs:next-${{ env.IMAGE_TAG }}
  344. - name: Send email on failure
  345. uses: unknwon/send-email-on-failure@89339a1bc93f4ad1d30f3b7e4911fcba985c9adb # v1
  346. if: ${{ failure() }}
  347. with:
  348. smtp_username: ${{ secrets.SMTP_USERNAME }}
  349. smtp_password: ${{ secrets.SMTP_PASSWORD }}
  350. digitalocean-gc:
  351. if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' && github.repository == 'gogs/gogs' }}
  352. needs: buildx-next
  353. permissions:
  354. contents: read
  355. uses: ./.github/workflows/digitalocean_gc.yml
  356. secrets: inherit
  357. digitalocean-gc-pull-request:
  358. if: ${{ github.event_name == 'pull_request' && github.repository == 'gogs/gogs' }}
  359. needs: buildx-next-pull-request
  360. permissions:
  361. contents: read
  362. uses: ./.github/workflows/digitalocean_gc.yml
  363. secrets: inherit