1
0

docker.yml 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  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: dawidd6/action-send-mail@2cea9617b09d79a095af21254fbcb7ae95903dde # v3.12.0
  71. if: ${{ failure() }}
  72. with:
  73. server_address: smtp.mailgun.org
  74. server_port: 465
  75. username: ${{ secrets.SMTP_USERNAME }}
  76. password: ${{ secrets.SMTP_PASSWORD }}
  77. subject: GitHub Actions (${{ github.repository }}) job result
  78. to: github-actions-8ce6454@unknwon.io
  79. from: GitHub Actions (${{ github.repository }})
  80. reply_to: noreply@unknwon.io
  81. body: |
  82. The job "${{ github.job }}" of ${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }} completed with "${{ job.status }}".
  83. View the job run at: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
  84. buildx-next:
  85. if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' && github.repository == 'gogs/gogs' }}
  86. concurrency:
  87. group: ${{ github.workflow }}-next-${{ github.ref }}
  88. cancel-in-progress: true
  89. runs-on: ubuntu-latest
  90. permissions:
  91. actions: write
  92. contents: read
  93. packages: write
  94. steps:
  95. - name: Checkout code
  96. uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
  97. - name: Set up QEMU
  98. uses: docker/setup-qemu-action@c7c53464625b32c7a7e944ae62b3e17d2b600130 # v3.7.0
  99. with:
  100. platforms: linux/amd64,linux/arm64,linux/arm/v7
  101. - name: Set up Docker Buildx
  102. id: buildx
  103. uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3.11.1
  104. - name: Inspect builder
  105. run: |
  106. echo "Name: ${{ steps.buildx.outputs.name }}"
  107. echo "Endpoint: ${{ steps.buildx.outputs.endpoint }}"
  108. echo "Status: ${{ steps.buildx.outputs.status }}"
  109. echo "Flags: ${{ steps.buildx.outputs.flags }}"
  110. echo "Platforms: ${{ steps.buildx.outputs.platforms }}"
  111. - name: Login to Docker Hub
  112. uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6.0
  113. with:
  114. username: ${{ secrets.DOCKERHUB_USERNAME }}
  115. password: ${{ secrets.DOCKERHUB_TOKEN }}
  116. - name: Login to GitHub Container registry
  117. uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6.0
  118. with:
  119. registry: ghcr.io
  120. username: ${{ github.repository_owner }}
  121. password: ${{ secrets.GITHUB_TOKEN }}
  122. - name: Login to DigitalOcean Container registry
  123. uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6.0
  124. with:
  125. registry: registry.digitalocean.com
  126. username: ${{ secrets.DIGITALOCEAN_USERNAME }}
  127. password: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}
  128. - name: Build and push next-gen images
  129. uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0
  130. with:
  131. context: .
  132. file: Dockerfile.next
  133. platforms: linux/amd64,linux/arm64,linux/arm/v7
  134. push: true
  135. tags: |
  136. gogs/gogs:next-latest
  137. ghcr.io/gogs/gogs:next-latest
  138. registry.digitalocean.com/gogs/gogs:next-latest
  139. - name: Scan for container vulnerabilities
  140. uses: aquasecurity/trivy-action@b6643a29fecd7f34b3597bc6acb0a98b03d33ff8 # 0.33.1
  141. with:
  142. image-ref: gogs/gogs:next-latest
  143. exit-code: '1'
  144. - name: Send email on failure
  145. uses: dawidd6/action-send-mail@2cea9617b09d79a095af21254fbcb7ae95903dde # v3.12.0
  146. if: ${{ failure() }}
  147. with:
  148. server_address: smtp.mailgun.org
  149. server_port: 465
  150. username: ${{ secrets.SMTP_USERNAME }}
  151. password: ${{ secrets.SMTP_PASSWORD }}
  152. subject: GitHub Actions (${{ github.repository }}) job result
  153. to: github-actions-8ce6454@unknwon.io
  154. from: GitHub Actions (${{ github.repository }})
  155. reply_to: noreply@unknwon.io
  156. body: |
  157. The job "${{ github.job }}" of ${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }} completed with "${{ job.status }}".
  158. View the job run at: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
  159. deploy-demo:
  160. if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' && github.repository == 'gogs/gogs' }}
  161. needs: buildx-next
  162. runs-on: ubuntu-latest
  163. permissions:
  164. contents: read
  165. steps:
  166. - name: Configure kubectl
  167. run: |
  168. mkdir -p ~/.kube
  169. echo "${KUBECONFIG}" | base64 -d > ~/.kube/config
  170. env:
  171. KUBECONFIG: ${{ secrets.DIGITALOCEAN_K8S_CLUSTER_KUBECONFIG }}
  172. - name: Restart gogs-demo deployment
  173. timeout-minutes: 5
  174. run: |
  175. set -ex
  176. kubectl rollout restart deployment gogs-demo -n gogs
  177. kubectl rollout status deployment gogs-demo -n gogs
  178. - name: Send email on failure
  179. uses: dawidd6/action-send-mail@2cea9617b09d79a095af21254fbcb7ae95903dde # v3.12.0
  180. if: ${{ failure() }}
  181. with:
  182. server_address: smtp.mailgun.org
  183. server_port: 465
  184. username: ${{ secrets.SMTP_USERNAME }}
  185. password: ${{ secrets.SMTP_PASSWORD }}
  186. subject: GitHub Actions (${{ github.repository }}) job result
  187. to: github-actions-8ce6454@unknwon.io
  188. from: GitHub Actions (${{ github.repository }})
  189. reply_to: noreply@unknwon.io
  190. body: |
  191. The job "${{ github.job }}" of ${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }} completed with "${{ job.status }}".
  192. View the job run at: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
  193. buildx-pull-request:
  194. if: ${{ github.event_name == 'pull_request'}}
  195. runs-on: ubuntu-latest
  196. permissions:
  197. contents: read
  198. steps:
  199. - name: Checkout code
  200. uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
  201. - name: Set up Docker Buildx
  202. id: buildx
  203. uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3.11.1
  204. with:
  205. config-inline: |
  206. [worker.oci]
  207. max-parallelism = 2
  208. - name: Inspect builder
  209. run: |
  210. echo "Name: ${{ steps.buildx.outputs.name }}"
  211. echo "Endpoint: ${{ steps.buildx.outputs.endpoint }}"
  212. echo "Status: ${{ steps.buildx.outputs.status }}"
  213. echo "Flags: ${{ steps.buildx.outputs.flags }}"
  214. echo "Platforms: ${{ steps.buildx.outputs.platforms }}"
  215. - name: Compute short commit SHA
  216. id: short-sha
  217. uses: benjlevesque/short-sha@599815c8ee942a9616c92bcfb4f947a3b670ab0b # v3.0
  218. - name: Build and push images
  219. uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0
  220. with:
  221. context: .
  222. platforms: linux/amd64
  223. push: true
  224. tags: |
  225. ttl.sh/gogs/gogs-${{ steps.short-sha.outputs.sha }}:7d
  226. - name: Scan for container vulnerabilities
  227. uses: aquasecurity/trivy-action@b6643a29fecd7f34b3597bc6acb0a98b03d33ff8 # 0.33.1
  228. with:
  229. image-ref: ttl.sh/gogs/gogs-${{ steps.short-sha.outputs.sha }}:7d
  230. exit-code: '1'
  231. buildx-next-pull-request:
  232. if: ${{ github.event_name == 'pull_request'}}
  233. runs-on: ubuntu-latest
  234. permissions:
  235. contents: read
  236. steps:
  237. - name: Checkout code
  238. uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
  239. - name: Set up Docker Buildx
  240. id: buildx
  241. uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3.11.1
  242. with:
  243. config-inline: |
  244. [worker.oci]
  245. max-parallelism = 2
  246. - name: Inspect builder
  247. run: |
  248. echo "Name: ${{ steps.buildx.outputs.name }}"
  249. echo "Endpoint: ${{ steps.buildx.outputs.endpoint }}"
  250. echo "Status: ${{ steps.buildx.outputs.status }}"
  251. echo "Flags: ${{ steps.buildx.outputs.flags }}"
  252. echo "Platforms: ${{ steps.buildx.outputs.platforms }}"
  253. - name: Compute short commit SHA
  254. id: short-sha
  255. uses: benjlevesque/short-sha@599815c8ee942a9616c92bcfb4f947a3b670ab0b # v3.0
  256. - name: Build and push next-gen images
  257. uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0
  258. with:
  259. context: .
  260. file: Dockerfile.next
  261. platforms: linux/amd64
  262. push: true
  263. tags: |
  264. ttl.sh/gogs/gogs-next-${{ steps.short-sha.outputs.sha }}:7d
  265. - name: Scan for container vulnerabilities
  266. uses: aquasecurity/trivy-action@b6643a29fecd7f34b3597bc6acb0a98b03d33ff8 # 0.33.1
  267. with:
  268. image-ref: ttl.sh/gogs/gogs-next-${{ steps.short-sha.outputs.sha }}:7d
  269. exit-code: '1'
  270. # Updates to the following section needs to be synced to all release branches within their lifecycles.
  271. buildx-release:
  272. if: ${{ github.event_name == 'release' }}
  273. runs-on: ubuntu-latest
  274. permissions:
  275. actions: write
  276. contents: read
  277. packages: write
  278. steps:
  279. - name: Compute image tag name
  280. run: echo "IMAGE_TAG=$(echo $GITHUB_REF_NAME | cut -c 2-)" >> $GITHUB_ENV
  281. - name: Checkout code
  282. uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
  283. - name: Set up QEMU
  284. uses: docker/setup-qemu-action@c7c53464625b32c7a7e944ae62b3e17d2b600130 # v3.7.0
  285. with:
  286. platforms: linux/amd64,linux/arm64,linux/arm/v7
  287. - name: Set up Docker Buildx
  288. id: buildx
  289. uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3.11.1
  290. - name: Inspect builder
  291. run: |
  292. echo "Name: ${{ steps.buildx.outputs.name }}"
  293. echo "Endpoint: ${{ steps.buildx.outputs.endpoint }}"
  294. echo "Status: ${{ steps.buildx.outputs.status }}"
  295. echo "Flags: ${{ steps.buildx.outputs.flags }}"
  296. echo "Platforms: ${{ steps.buildx.outputs.platforms }}"
  297. - name: Login to Docker Hub
  298. uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6.0
  299. with:
  300. username: ${{ secrets.DOCKERHUB_USERNAME }}
  301. password: ${{ secrets.DOCKERHUB_TOKEN }}
  302. - name: Login to GitHub Container registry
  303. uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6.0
  304. with:
  305. registry: ghcr.io
  306. username: ${{ github.repository_owner }}
  307. password: ${{ secrets.GITHUB_TOKEN }}
  308. - name: Build and push images
  309. uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0
  310. with:
  311. context: .
  312. platforms: linux/amd64,linux/arm64,linux/arm/v7
  313. push: true
  314. tags: |
  315. gogs/gogs:${{ env.IMAGE_TAG }}
  316. ghcr.io/gogs/gogs:${{ env.IMAGE_TAG }}
  317. - name: Send email on failure
  318. uses: dawidd6/action-send-mail@2cea9617b09d79a095af21254fbcb7ae95903dde # v3.12.0
  319. if: ${{ failure() }}
  320. with:
  321. server_address: smtp.mailgun.org
  322. server_port: 465
  323. username: ${{ secrets.SMTP_USERNAME }}
  324. password: ${{ secrets.SMTP_PASSWORD }}
  325. subject: GitHub Actions (${{ github.repository }}) job result
  326. to: github-actions-8ce6454@unknwon.io
  327. from: GitHub Actions (${{ github.repository }})
  328. reply_to: noreply@unknwon.io
  329. body: |
  330. The job "${{ github.job }}" of ${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }} completed with "${{ job.status }}".
  331. View the job run at: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
  332. # Updates to the following section needs to be synced to all release branches within their lifecycles.
  333. buildx-next-release:
  334. if: ${{ github.event_name == 'release' }}
  335. runs-on: ubuntu-latest
  336. permissions:
  337. actions: write
  338. contents: read
  339. packages: write
  340. steps:
  341. - name: Compute image tag name
  342. run: echo "IMAGE_TAG=$(echo $GITHUB_REF_NAME | cut -c 2-)" >> $GITHUB_ENV
  343. - name: Checkout code
  344. uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
  345. - name: Set up QEMU
  346. uses: docker/setup-qemu-action@c7c53464625b32c7a7e944ae62b3e17d2b600130 # v3.7.0
  347. with:
  348. platforms: linux/amd64,linux/arm64,linux/arm/v7
  349. - name: Set up Docker Buildx
  350. id: buildx
  351. uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3.11.1
  352. - name: Inspect builder
  353. run: |
  354. echo "Name: ${{ steps.buildx.outputs.name }}"
  355. echo "Endpoint: ${{ steps.buildx.outputs.endpoint }}"
  356. echo "Status: ${{ steps.buildx.outputs.status }}"
  357. echo "Flags: ${{ steps.buildx.outputs.flags }}"
  358. echo "Platforms: ${{ steps.buildx.outputs.platforms }}"
  359. - name: Login to Docker Hub
  360. uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6.0
  361. with:
  362. username: ${{ secrets.DOCKERHUB_USERNAME }}
  363. password: ${{ secrets.DOCKERHUB_TOKEN }}
  364. - name: Login to GitHub Container registry
  365. uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6.0
  366. with:
  367. registry: ghcr.io
  368. username: ${{ github.repository_owner }}
  369. password: ${{ secrets.GITHUB_TOKEN }}
  370. - name: Build and push next-gen images
  371. uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0
  372. with:
  373. context: .
  374. file: Dockerfile.next
  375. platforms: linux/amd64,linux/arm64,linux/arm/v7
  376. push: true
  377. tags: |
  378. gogs/gogs:next-${{ env.IMAGE_TAG }}
  379. ghcr.io/gogs/gogs:next-${{ env.IMAGE_TAG }}
  380. - name: Send email on failure
  381. uses: dawidd6/action-send-mail@2cea9617b09d79a095af21254fbcb7ae95903dde # v3.12.0
  382. if: ${{ failure() }}
  383. with:
  384. server_address: smtp.mailgun.org
  385. server_port: 465
  386. username: ${{ secrets.SMTP_USERNAME }}
  387. password: ${{ secrets.SMTP_PASSWORD }}
  388. subject: GitHub Actions (${{ github.repository }}) job result
  389. to: github-actions-8ce6454@unknwon.io
  390. from: GitHub Actions (${{ github.repository }})
  391. reply_to: noreply@unknwon.io
  392. body: |
  393. The job "${{ github.job }}" of ${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }} completed with "${{ job.status }}".
  394. View the job run at: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
  395. digitalocean-gc:
  396. if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' && github.repository == 'gogs/gogs' }}
  397. needs: buildx-next
  398. permissions:
  399. contents: read
  400. uses: ./.github/workflows/digitalocean_gc.yml
  401. secrets: inherit
  402. digitalocean-gc-pull-request:
  403. if: ${{ github.event_name == 'pull_request' && github.repository == 'gogs/gogs' }}
  404. needs: buildx-next-pull-request
  405. permissions:
  406. contents: read
  407. uses: ./.github/workflows/digitalocean_gc.yml
  408. secrets: inherit