1
0

docker.yml 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  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 tags
  253. run: |
  254. IMAGE_TAG=$(echo $GITHUB_REF_NAME | cut -c 2-)
  255. echo "IMAGE_TAG=$IMAGE_TAG" >> $GITHUB_ENV
  256. TAGS="gogs/gogs:$IMAGE_TAG
  257. ghcr.io/gogs/gogs:$IMAGE_TAG"
  258. # Add minor version tag for stable releases (no prerelease suffix per semver).
  259. if [[ ! "$IMAGE_TAG" =~ - ]]; then
  260. MINOR_TAG=$(echo "$IMAGE_TAG" | cut -d. -f1,2)
  261. TAGS="$TAGS
  262. gogs/gogs:$MINOR_TAG
  263. ghcr.io/gogs/gogs:$MINOR_TAG"
  264. fi
  265. echo "TAGS<<EOF" >> $GITHUB_ENV
  266. echo "$TAGS" >> $GITHUB_ENV
  267. echo "EOF" >> $GITHUB_ENV
  268. - name: Checkout code
  269. uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
  270. - name: Set up QEMU
  271. uses: docker/setup-qemu-action@c7c53464625b32c7a7e944ae62b3e17d2b600130 # v3.7.0
  272. with:
  273. platforms: linux/amd64,linux/arm64,linux/arm/v7
  274. - name: Set up Docker Buildx
  275. id: buildx
  276. uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3.11.1
  277. - name: Inspect builder
  278. run: |
  279. echo "Name: ${{ steps.buildx.outputs.name }}"
  280. echo "Endpoint: ${{ steps.buildx.outputs.endpoint }}"
  281. echo "Status: ${{ steps.buildx.outputs.status }}"
  282. echo "Flags: ${{ steps.buildx.outputs.flags }}"
  283. echo "Platforms: ${{ steps.buildx.outputs.platforms }}"
  284. - name: Login to Docker Hub
  285. uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6.0
  286. with:
  287. username: ${{ secrets.DOCKERHUB_USERNAME }}
  288. password: ${{ secrets.DOCKERHUB_TOKEN }}
  289. - name: Login to GitHub Container registry
  290. uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6.0
  291. with:
  292. registry: ghcr.io
  293. username: ${{ github.repository_owner }}
  294. password: ${{ secrets.GITHUB_TOKEN }}
  295. - name: Build and push images
  296. uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0
  297. with:
  298. context: .
  299. platforms: linux/amd64,linux/arm64,linux/arm/v7
  300. push: true
  301. tags: ${{ env.TAGS }}
  302. - name: Send email on failure
  303. uses: unknwon/send-email-on-failure@89339a1bc93f4ad1d30f3b7e4911fcba985c9adb # v1
  304. if: ${{ failure() }}
  305. with:
  306. smtp_username: ${{ secrets.SMTP_USERNAME }}
  307. smtp_password: ${{ secrets.SMTP_PASSWORD }}
  308. # Updates to the following section needs to be synced to all release branches within their lifecycles.
  309. buildx-next-release:
  310. if: ${{ github.event_name == 'release' }}
  311. runs-on: ubuntu-latest
  312. permissions:
  313. actions: write
  314. contents: read
  315. packages: write
  316. steps:
  317. - name: Compute image tags
  318. run: |
  319. IMAGE_TAG=$(echo $GITHUB_REF_NAME | cut -c 2-)
  320. echo "IMAGE_TAG=$IMAGE_TAG" >> $GITHUB_ENV
  321. TAGS="gogs/gogs:next-$IMAGE_TAG
  322. ghcr.io/gogs/gogs:next-$IMAGE_TAG"
  323. # Add minor version tag for stable releases (no prerelease suffix per semver).
  324. if [[ ! "$IMAGE_TAG" =~ - ]]; then
  325. MINOR_TAG=$(echo "$IMAGE_TAG" | cut -d. -f1,2)
  326. TAGS="$TAGS
  327. gogs/gogs:next-$MINOR_TAG
  328. ghcr.io/gogs/gogs:next-$MINOR_TAG"
  329. fi
  330. echo "TAGS<<EOF" >> $GITHUB_ENV
  331. echo "$TAGS" >> $GITHUB_ENV
  332. echo "EOF" >> $GITHUB_ENV
  333. - name: Checkout code
  334. uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
  335. - name: Set up QEMU
  336. uses: docker/setup-qemu-action@c7c53464625b32c7a7e944ae62b3e17d2b600130 # v3.7.0
  337. with:
  338. platforms: linux/amd64,linux/arm64,linux/arm/v7
  339. - name: Set up Docker Buildx
  340. id: buildx
  341. uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3.11.1
  342. - name: Inspect builder
  343. run: |
  344. echo "Name: ${{ steps.buildx.outputs.name }}"
  345. echo "Endpoint: ${{ steps.buildx.outputs.endpoint }}"
  346. echo "Status: ${{ steps.buildx.outputs.status }}"
  347. echo "Flags: ${{ steps.buildx.outputs.flags }}"
  348. echo "Platforms: ${{ steps.buildx.outputs.platforms }}"
  349. - name: Login to Docker Hub
  350. uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6.0
  351. with:
  352. username: ${{ secrets.DOCKERHUB_USERNAME }}
  353. password: ${{ secrets.DOCKERHUB_TOKEN }}
  354. - name: Login to GitHub Container registry
  355. uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6.0
  356. with:
  357. registry: ghcr.io
  358. username: ${{ github.repository_owner }}
  359. password: ${{ secrets.GITHUB_TOKEN }}
  360. - name: Build and push next-gen images
  361. uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0
  362. with:
  363. context: .
  364. file: Dockerfile.next
  365. platforms: linux/amd64,linux/arm64,linux/arm/v7
  366. push: true
  367. tags: ${{ env.TAGS }}
  368. - name: Send email on failure
  369. uses: unknwon/send-email-on-failure@89339a1bc93f4ad1d30f3b7e4911fcba985c9adb # v1
  370. if: ${{ failure() }}
  371. with:
  372. smtp_username: ${{ secrets.SMTP_USERNAME }}
  373. smtp_password: ${{ secrets.SMTP_PASSWORD }}
  374. digitalocean-gc:
  375. if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' && github.repository == 'gogs/gogs' }}
  376. needs: buildx-next
  377. permissions:
  378. contents: read
  379. uses: ./.github/workflows/digitalocean_gc.yml
  380. secrets: inherit
  381. digitalocean-gc-pull-request:
  382. if: ${{ github.event_name == 'pull_request' && github.repository == 'gogs/gogs' }}
  383. needs: buildx-next-pull-request
  384. permissions:
  385. contents: read
  386. uses: ./.github/workflows/digitalocean_gc.yml
  387. secrets: inherit