docker.yml 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750
  1. ---
  2. # Handle building docker images both for CI checks and for eleases.
  3. #
  4. # The case of releaases is unfortunately rather complicated, as Docker
  5. # tooling does not have great support for handling of multiarch images
  6. # published to multiple registries. As a result, we have to build the
  7. # images, export the cache, and then _rebuild_ the images using the exported
  8. # cache but with different output parameters for buildx. We also need to
  9. # do the second build step as a separate job for each registry so that a
  10. # failure to publish one place won’t break publishing elsewhere.
  11. name: Docker
  12. on:
  13. push:
  14. branches:
  15. - master
  16. pull_request: null
  17. workflow_dispatch:
  18. inputs:
  19. version:
  20. description: Version Tag
  21. default: nightly
  22. required: true
  23. env:
  24. DISABLE_TELEMETRY: 1
  25. concurrency:
  26. group: docker-${{ github.ref }}-${{ github.event_name }}
  27. cancel-in-progress: true
  28. jobs:
  29. file-check: # Check what files changed if we’re being run in a PR or on a push.
  30. name: Check Modified Files
  31. runs-on: ubuntu-latest
  32. outputs:
  33. run: ${{ steps.check-run.outputs.run }}
  34. skip-go: ${{ steps.check-go.outputs.skip-go }}
  35. steps:
  36. - name: Checkout
  37. id: checkout
  38. if: github.event_name != 'workflow_dispatch'
  39. uses: actions/checkout@v4
  40. with:
  41. fetch-depth: 0
  42. submodules: recursive
  43. - name: Check source files
  44. id: check-source-files
  45. if: github.event_name != 'workflow_dispatch'
  46. uses: tj-actions/changed-files@v44
  47. with:
  48. since_last_remote_commit: ${{ github.event_name != 'pull_request' }}
  49. files: |
  50. **/*.c
  51. **/*.cc
  52. **/*.h
  53. **/*.hh
  54. **/*.in
  55. **/*.patch
  56. src/aclk/aclk-schemas/
  57. src/ml/dlib/
  58. src/fluent-bit/
  59. src/web/server/h2o/libh2o/
  60. files_ignore: |
  61. netdata.spec.in
  62. **/*.md
  63. - name: Check build system files
  64. id: check-build-files
  65. if: github.event_name != 'workflow_dispatch'
  66. uses: tj-actions/changed-files@v44
  67. with:
  68. since_last_remote_commit: ${{ github.event_name != 'pull_request' }}
  69. files: |
  70. .dockerignore
  71. CMakeLists.txt
  72. netdata-installer.sh
  73. .github/workflows/docker.yml
  74. .github/scripts/docker-test.sh
  75. .github/scripts/gen-docker-tags.py
  76. .github/scripts/gen-docker-imagetool-args.py
  77. packaging/cmake/
  78. packaging/docker/
  79. packaging/installer/
  80. packaging/runtime-check.sh
  81. packaging/*.version
  82. packaging/*.checksums
  83. files_ignore: |
  84. **/*.md
  85. - name: List all changed files in pattern
  86. continue-on-error: true
  87. if: github.event_name != 'workflow_dispatch'
  88. env:
  89. CHANGED_SOURCE_FILES: ${{ steps.check-source-files.outputs.all_changed_files }}
  90. CHANGED_BUILD_FILES: ${{ steps.check-build-files.outputs.all_changed_files }}
  91. run: |
  92. for file in ${CHANGED_SOURCE_FILES} ${CHANGED_BUILD_FILES} ; do
  93. echo "$file was changed"
  94. done
  95. - name: Check Run
  96. id: check-run
  97. run: |
  98. if [ "${{ steps.check-source-files.outputs.any_modified }}" == "true" ] || [ "${{ steps.check-build-files.outputs.any_modified }}" == "true" ] || [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
  99. echo 'run=true' >> "${GITHUB_OUTPUT}"
  100. else
  101. echo 'run=false' >> "${GITHUB_OUTPUT}"
  102. fi
  103. - name: Check Go
  104. id: check-go
  105. env:
  106. OTHER_CHANGED_FILES: ${{ steps.check-source-files.outputs.other_changed_files }}
  107. run: |
  108. if [ '${{ github.event_name }}' == 'pull_request' ]; then
  109. if echo "${OTHER_CHANGED_FILES}" | grep -q '.*/(.*\.go|go\.mod|go\.sum)$' || [ "${{ steps.check-build-files.outputs.any_modified }}" == "true" ]; then
  110. echo 'skip-go=' >> "${GITHUB_OUTPUT}"
  111. else
  112. echo 'skip-go=--disable-go' >> "${GITHUB_OUTPUT}"
  113. fi
  114. else
  115. echo 'skip-go=' >> "${GITHUB_OUTPUT}"
  116. fi
  117. build-images:
  118. name: Build Docker Images
  119. needs:
  120. - file-check
  121. runs-on: ubuntu-latest
  122. strategy:
  123. matrix:
  124. platform:
  125. - linux/amd64
  126. - linux/i386
  127. - linux/arm/v7
  128. - linux/arm64
  129. - linux/ppc64le
  130. # Fail fast on releases, but run everything to completion on other triggers.
  131. fail-fast: ${{ github.event_name == 'workflow_dispatch' }}
  132. steps:
  133. - name: Skip Check
  134. id: skip
  135. if: needs.file-check.outputs.run != 'true'
  136. run: echo "SKIPPED"
  137. - name: Checkout
  138. id: checkout
  139. if: needs.file-check.outputs.run == 'true'
  140. uses: actions/checkout@v4
  141. with:
  142. fetch-depth: 0
  143. submodules: recursive
  144. - name: Generate Artifact Name
  145. id: artifact-name
  146. if: github.repository == 'netdata/netdata' && needs.file-check.outputs.run == 'true' && github.event_name == 'workflow_dispatch'
  147. run: echo "platform=$(echo ${{ matrix.platform }} | tr '/' '-' | cut -f 2- -d '-')" >> "${GITHUB_OUTPUT}"
  148. - name: Mark image as official
  149. id: env
  150. if: github.repository == 'netdata/netdata' && needs.file-check.outputs.run == 'true' && github.event_name == 'workflow_dispatch'
  151. run: echo "OFFICIAL_IMAGE=true" >> "${GITHUB_ENV}"
  152. - name: Setup QEMU
  153. id: qemu
  154. if: matrix.platform != 'linux/i386' && matrix.platform != 'linux/amd64' && needs.file-check.outputs.run == 'true'
  155. uses: docker/setup-qemu-action@v3
  156. - name: Setup Buildx
  157. id: prepare
  158. if: needs.file-check.outputs.run == 'true'
  159. uses: docker/setup-buildx-action@v3
  160. - name: Build Image
  161. id: build
  162. if: needs.file-check.outputs.run == 'true'
  163. uses: docker/build-push-action@v5
  164. with:
  165. platforms: ${{ matrix.platform }}
  166. tags: netdata/netdata:test
  167. load: true
  168. cache-to: type=local,dest=/tmp/build-cache,mode=max
  169. build-args: |
  170. OFFICIAL_IMAGE=${{ env.OFFICIAL_IMAGE }}
  171. EXTRA_INSTALL_OPTS=${{ needs.file-check.outputs.skip-go }}
  172. - name: Test Image
  173. id: test
  174. if: needs.file-check.outputs.run == 'true' && matrix.platform == 'linux/amd64'
  175. run: .github/scripts/docker-test.sh
  176. - name: Upload Cache
  177. id: upload-cache
  178. if: github.repository == 'netdata/netdata' && needs.file-check.outputs.run == 'true' && github.event_name == 'workflow_dispatch'
  179. uses: actions/upload-artifact@v4
  180. with:
  181. name: cache-${{ steps.artifact-name.outputs.platform }}
  182. path: /tmp/build-cache/*
  183. retention-days: 1
  184. - name: Failure Notification
  185. uses: rtCamp/action-slack-notify@v2
  186. env:
  187. SLACK_COLOR: 'danger'
  188. SLACK_FOOTER: ''
  189. SLACK_ICON_EMOJI: ':github-actions:'
  190. SLACK_TITLE: 'Docker build failed:'
  191. SLACK_USERNAME: 'GitHub Actions'
  192. SLACK_MESSAGE: |-
  193. ${{ github.repository }}: Building or testing Docker image for ${{ matrix.platform }} failed.
  194. Checkout: ${{ steps.checkout.outcome }}
  195. Determine artifact name: ${{ steps.artifact-name.outcome }}
  196. Setup environment: ${{ steps.env.outcome }}
  197. Setup QEMU: ${{ steps.qemu.outcome }}
  198. Setup buildx: ${{ steps.prepare.outcome }}
  199. Build image: ${{ steps.build.outcome }}
  200. Test image: ${{ steps.test.outcome }}
  201. Upload build cache: ${{ steps.upload-cache.outcome }}
  202. SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL }}
  203. if: >-
  204. ${{
  205. failure()
  206. && github.event_name != 'pull_request'
  207. && github.repository == 'netdata/netdata'
  208. && needs.file-check.outputs.run == 'true'
  209. }}
  210. gen-tags:
  211. name: Generate Docker Tags
  212. runs-on: ubuntu-latest
  213. if: github.event_name == 'workflow_dispatch'
  214. outputs:
  215. tags: ${{ steps.tag.outputs.tags }}
  216. steps:
  217. - name: Checkout
  218. id: checkout
  219. uses: actions/checkout@v4
  220. - name: Generate Tags
  221. id: tag
  222. run: |
  223. if [ ${{ github.event_name }} = 'workflow_dispatch' ]; then
  224. echo "tags=$(.github/scripts/gen-docker-tags.py ${{ github.event_name }} ${{ github.event.inputs.version }})" >> "${GITHUB_OUTPUT}"
  225. else
  226. echo "tags=$(.github/scripts/gen-docker-tags.py ${{ github.event_name }} '')" >> "${GITHUB_OUTPUT}"
  227. fi
  228. build-images-docker-hub:
  229. name: Push Images to Docker Hub
  230. if: github.event_name == 'workflow_dispatch'
  231. needs:
  232. - build-images
  233. - gen-tags
  234. strategy:
  235. matrix:
  236. platform:
  237. - linux/amd64
  238. - linux/i386
  239. - linux/arm/v7
  240. - linux/arm64
  241. - linux/ppc64le
  242. runs-on: ubuntu-latest
  243. steps:
  244. - name: Checkout
  245. id: checkout
  246. uses: actions/checkout@v4
  247. with:
  248. fetch-depth: 0
  249. submodules: recursive
  250. - name: Generate Artifact Name
  251. id: artifact-name
  252. run: echo "platform=$(echo ${{ matrix.platform }} | tr '/' '-' | cut -f 2- -d '-')" >> "${GITHUB_OUTPUT}"
  253. - name: Download Cache
  254. id: fetch-cache
  255. uses: actions/download-artifact@v4
  256. with:
  257. name: cache-${{ steps.artifact-name.outputs.platform }}
  258. path: /tmp/build-cache
  259. - name: Mark image as official
  260. id: env
  261. if: github.repository == 'netdata/netdata'
  262. run: echo "OFFICIAL_IMAGE=true" >> "${GITHUB_ENV}"
  263. - name: Setup QEMU
  264. id: qemu
  265. if: matrix.platform != 'linux/i386' && matrix.platform != 'linux/amd64'
  266. uses: docker/setup-qemu-action@v3
  267. - name: Setup Buildx
  268. id: prepare
  269. uses: docker/setup-buildx-action@v3
  270. - name: Registry Login
  271. id: login
  272. if: github.repository == 'netdata/netdata'
  273. uses: docker/login-action@v3
  274. with:
  275. username: ${{ secrets.DOCKER_HUB_USERNAME }}
  276. password: ${{ secrets.DOCKER_HUB_PASSWORD }}
  277. - name: Build Image
  278. id: build
  279. uses: docker/build-push-action@v5
  280. with:
  281. platforms: ${{ matrix.platform }}
  282. cache-from: type=local,src=/tmp/build-cache
  283. outputs: type=image,name=netdata/netdata,push-by-digest=true,name-canonical=true,push=true
  284. build-args: OFFICIAL_IMAGE=${{ env.OFFICIAL_IMAGE }}
  285. - name: Export Digest
  286. id: export-digest
  287. if: github.repository == 'netdata/netdata'
  288. run: |
  289. mkdir -p /tmp/digests
  290. digest="${{ steps.build.outputs.digest }}"
  291. touch "/tmp/digests/${digest#sha256:}"
  292. - name: Upload digest
  293. id: upload-digest
  294. if: github.repository == 'netdata/netdata'
  295. uses: actions/upload-artifact@v4
  296. with:
  297. name: docker-digests-${{ steps.artifact-name.outputs.platform }}
  298. path: /tmp/digests/*
  299. if-no-files-found: error
  300. retention-days: 1
  301. - name: Failure Notification
  302. uses: rtCamp/action-slack-notify@v2
  303. env:
  304. SLACK_COLOR: 'danger'
  305. SLACK_FOOTER: ''
  306. SLACK_ICON_EMOJI: ':github-actions:'
  307. SLACK_TITLE: 'Docker Hub upload failed:'
  308. SLACK_USERNAME: 'GitHub Actions'
  309. SLACK_MESSAGE: |-
  310. ${{ github.repository }}: Creating or uploading Docker image for ${{ matrix.platform }} on Docker Hub failed.
  311. Checkout: ${{ steps.checkout.outcome }}
  312. Determine artifact name: ${{ steps.artifact-name.outcome }}
  313. Fetch build cache: ${{ steps.fetch-cache.outcome }}
  314. Setup environment: ${{ steps.env.outcome }}
  315. Setup QEMU: ${{ steps.qemu.outcome }}
  316. Setup buildx: ${{ steps.prepare.outcome }}
  317. Login to registry: ${{ steps.login.outcome }}
  318. Build image: ${{ steps.build.outcome }}
  319. Export digest: ${{ steps.export-digest.outcome }}
  320. Upload digest: ${{ steps.upload-digest.outcome }}
  321. SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL }}
  322. if: >-
  323. ${{
  324. failure()
  325. && github.repository == 'netdata/netdata'
  326. }}
  327. publish-docker-hub:
  328. name: Consolidate and tag images for DockerHub
  329. if: github.event_name == 'workflow_dispatch'
  330. needs:
  331. - build-images-docker-hub
  332. - gen-tags
  333. runs-on: ubuntu-latest
  334. steps:
  335. - name: Checkout
  336. id: checkout
  337. uses: actions/checkout@v4
  338. - name: Download digests
  339. id: fetch-digests
  340. uses: actions/download-artifact@v4
  341. with:
  342. path: /tmp/digests
  343. pattern: docker-digests-*
  344. merge-multiple: true
  345. - name: Setup Buildx
  346. id: prepare
  347. uses: docker/setup-buildx-action@v3
  348. - name: Registry Login
  349. id: login
  350. if: github.repository == 'netdata/netdata'
  351. uses: docker/login-action@v3
  352. with:
  353. username: ${{ secrets.DOCKER_HUB_USERNAME }}
  354. password: ${{ secrets.DOCKER_HUB_PASSWORD }}
  355. - name: Create and Push Manifest
  356. id: manifest
  357. if: github.repository == 'netdata/netdata'
  358. run: docker buildx imagetools create $(.github/scripts/gen-docker-imagetool-args.py /tmp/digests '' "${{ needs.gen-tags.outputs.tags }}")
  359. - name: Failure Notification
  360. uses: rtCamp/action-slack-notify@v2
  361. env:
  362. SLACK_COLOR: 'danger'
  363. SLACK_FOOTER: ''
  364. SLACK_ICON_EMOJI: ':github-actions:'
  365. SLACK_TITLE: 'Publishing Docker images to Docker Hub failed:'
  366. SLACK_USERNAME: 'GitHub Actions'
  367. SLACK_MESSAGE: |-
  368. ${{ github.repository }}: Publishing Docker images to Docker Hub failed.
  369. Checkout: ${{ steps.checkout.outcome }}
  370. Download digests: ${{ steps.fetch-digests.outcome }}
  371. Setup buildx: ${{ steps.prepare.outcome }}
  372. Login to registry: ${{ steps.login.outcome }}
  373. Create and push manifest: ${{ steps.manifest.outcome }}
  374. SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL }}
  375. if: >-
  376. ${{
  377. failure()
  378. && github.repository == 'netdata/netdata'
  379. }}
  380. build-images-quay:
  381. name: Push Images to Quay.io
  382. if: github.event_name == 'workflow_dispatch'
  383. needs:
  384. - build-images
  385. - gen-tags
  386. strategy:
  387. matrix:
  388. platform:
  389. - linux/amd64
  390. - linux/i386
  391. - linux/arm/v7
  392. - linux/arm64
  393. - linux/ppc64le
  394. runs-on: ubuntu-latest
  395. steps:
  396. - name: Checkout
  397. id: checkout
  398. uses: actions/checkout@v4
  399. with:
  400. fetch-depth: 0
  401. submodules: recursive
  402. - name: Generate Artifact Name
  403. id: artifact-name
  404. run: echo "platform=$(echo ${{ matrix.platform }} | tr '/' '-' | cut -f 2- -d '-')" >> "${GITHUB_OUTPUT}"
  405. - name: Download Cache
  406. id: fetch-cache
  407. uses: actions/download-artifact@v4
  408. with:
  409. name: cache-${{ steps.artifact-name.outputs.platform }}
  410. path: /tmp/build-cache
  411. - name: Mark image as official
  412. id: env
  413. if: github.repository == 'netdata/netdata'
  414. run: echo "OFFICIAL_IMAGE=true" >> "${GITHUB_ENV}"
  415. - name: Setup QEMU
  416. id: qemu
  417. if: matrix.platform != 'linux/i386' && matrix.platform != 'linux/amd64'
  418. uses: docker/setup-qemu-action@v3
  419. - name: Setup Buildx
  420. id: prepare
  421. uses: docker/setup-buildx-action@v3
  422. - name: Registry Login
  423. id: login
  424. if: github.repository == 'netdata/netdata'
  425. uses: docker/login-action@v3
  426. with:
  427. registry: quay.io
  428. username: ${{ secrets.NETDATABOT_QUAY_USERNAME }}
  429. password: ${{ secrets.NETDATABOT_QUAY_TOKEN }}
  430. - name: Build Image
  431. id: build
  432. uses: docker/build-push-action@v5
  433. with:
  434. platforms: ${{ matrix.platform }}
  435. cache-from: type=local,src=/tmp/build-cache
  436. build-args: OFFICIAL_IMAGE=${{ env.OFFICIAL_IMAGE }}
  437. outputs: type=image,name=quay.io/netdata/netdata,push-by-digest=true,name-canonical=true,push=true
  438. - name: Export Digest
  439. id: export-digest
  440. if: github.repository == 'netdata/netdata'
  441. run: |
  442. mkdir -p /tmp/digests
  443. digest="${{ steps.build.outputs.digest }}"
  444. touch "/tmp/digests/${digest#sha256:}"
  445. - name: Upload digest
  446. id: upload-digest
  447. if: github.repository == 'netdata/netdata'
  448. uses: actions/upload-artifact@v4
  449. with:
  450. name: quay-digests-${{ steps.artifact-name.outputs.platform }}
  451. path: /tmp/digests/*
  452. if-no-files-found: error
  453. retention-days: 1
  454. - name: Failure Notification
  455. uses: rtCamp/action-slack-notify@v2
  456. env:
  457. SLACK_COLOR: 'danger'
  458. SLACK_FOOTER: ''
  459. SLACK_ICON_EMOJI: ':github-actions:'
  460. SLACK_TITLE: 'Quay.io upload failed:'
  461. SLACK_USERNAME: 'GitHub Actions'
  462. SLACK_MESSAGE: |-
  463. ${{ github.repository }}: Creating or uploading Docker image for ${{ matrix.platform }} on Quay.io failed.
  464. Checkout: ${{ steps.checkout.outcome }}
  465. Determine artifact name: ${{ steps.artifact-name.outcome }}
  466. Fetch build cache: ${{ steps.fetch-cache.outcome }}
  467. Setup environment: ${{ steps.env.outcome }}
  468. Setup QEMU: ${{ steps.qemu.outcome }}
  469. Setup buildx: ${{ steps.prepare.outcome }}
  470. Login to registry: ${{ steps.login.outcome }}
  471. Build image: ${{ steps.build.outcome }}
  472. Export digest: ${{ steps.export-digest.outcome }}
  473. Upload digest: ${{ steps.upload-digest.outcome }}
  474. SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL }}
  475. if: >-
  476. ${{
  477. failure()
  478. && github.repository == 'netdata/netdata'
  479. }}
  480. publish-quay:
  481. name: Consolidate and tag images for Quay.io
  482. if: github.event_name == 'workflow_dispatch'
  483. needs:
  484. - build-images-quay
  485. - gen-tags
  486. runs-on: ubuntu-latest
  487. steps:
  488. - name: Checkout
  489. id: checkout
  490. uses: actions/checkout@v4
  491. - name: Download digests
  492. id: fetch-digests
  493. uses: actions/download-artifact@v4
  494. with:
  495. path: /tmp/digests
  496. pattern: quay-digests-*
  497. merge-multiple: true
  498. - name: Setup Buildx
  499. id: prepare
  500. uses: docker/setup-buildx-action@v3
  501. - name: Registry Login
  502. id: login
  503. if: github.repository == 'netdata/netdata'
  504. uses: docker/login-action@v3
  505. with:
  506. registry: quay.io
  507. username: ${{ secrets.NETDATABOT_QUAY_USERNAME }}
  508. password: ${{ secrets.NETDATABOT_QUAY_TOKEN }}
  509. - name: Create and Push Manifest
  510. id: manifest
  511. if: github.repository == 'netdata/netdata'
  512. run: docker buildx imagetools create $(.github/scripts/gen-docker-imagetool-args.py /tmp/digests 'quay.io' "${{ needs.gen-tags.outputs.tags }}")
  513. - name: Failure Notification
  514. uses: rtCamp/action-slack-notify@v2
  515. env:
  516. SLACK_COLOR: 'danger'
  517. SLACK_FOOTER: ''
  518. SLACK_ICON_EMOJI: ':github-actions:'
  519. SLACK_TITLE: 'Publishing Docker images on Quay.io failed:'
  520. SLACK_USERNAME: 'GitHub Actions'
  521. SLACK_MESSAGE: |-
  522. ${{ github.repository }}: Publishing Docker images on Quay.io failed.
  523. Checkout: ${{ steps.checkout.outcome }}
  524. Download digests: ${{ steps.fetch-digests.outcome }}
  525. Setup buildx: ${{ steps.prepare.outcome }}
  526. Login to registry: ${{ steps.login.outcome }}
  527. Create and push manifest: ${{ steps.manifest.outcome }}
  528. SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL }}
  529. if: >-
  530. ${{
  531. failure()
  532. && github.repository == 'netdata/netdata'
  533. }}
  534. build-images-ghcr:
  535. name: Push Images to GHCR
  536. if: github.event_name == 'workflow_dispatch'
  537. needs:
  538. - build-images
  539. - gen-tags
  540. strategy:
  541. matrix:
  542. platform:
  543. - linux/amd64
  544. - linux/i386
  545. - linux/arm/v7
  546. - linux/arm64
  547. - linux/ppc64le
  548. runs-on: ubuntu-latest
  549. steps:
  550. - name: Checkout
  551. id: checkout
  552. uses: actions/checkout@v4
  553. with:
  554. fetch-depth: 0
  555. submodules: recursive
  556. - name: Generate Artifact Name
  557. id: artifact-name
  558. run: echo "platform=$(echo ${{ matrix.platform }} | tr '/' '-' | cut -f 2- -d '-')" >> "${GITHUB_OUTPUT}"
  559. - name: Download Cache
  560. id: fetch-cache
  561. uses: actions/download-artifact@v4
  562. with:
  563. name: cache-${{ steps.artifact-name.outputs.platform }}
  564. path: /tmp/build-cache
  565. - name: Mark image as official
  566. id: env
  567. if: github.repository == 'netdata/netdata'
  568. run: echo "OFFICIAL_IMAGE=true" >> "${GITHUB_ENV}"
  569. - name: Setup QEMU
  570. id: qemu
  571. if: matrix.platform != 'linux/i386' && matrix.platform != 'linux/amd64'
  572. uses: docker/setup-qemu-action@v3
  573. - name: Setup Buildx
  574. id: prepare
  575. uses: docker/setup-buildx-action@v3
  576. - name: Registry Login
  577. id: login
  578. if: github.repository == 'netdata/netdata'
  579. uses: docker/login-action@v3
  580. with:
  581. registry: ghcr.io
  582. username: ${{ github.repository_owner }}
  583. password: ${{ secrets.GITHUB_TOKEN }}
  584. - name: Build Image
  585. id: build
  586. uses: docker/build-push-action@v5
  587. with:
  588. platforms: ${{ matrix.platform }}
  589. cache-from: type=local,src=/tmp/build-cache
  590. build-args: OFFICIAL_IMAGE=${{ env.OFFICIAL_IMAGE }}
  591. outputs: type=image,name=ghcr.io/netdata/netdata,push-by-digest=true,name-canonical=true,push=true
  592. - name: Export Digest
  593. id: export-digest
  594. if: github.repository == 'netdata/netdata'
  595. run: |
  596. mkdir -p /tmp/digests
  597. digest="${{ steps.build.outputs.digest }}"
  598. touch "/tmp/digests/${digest#sha256:}"
  599. - name: Upload digest
  600. id: upload-digest
  601. if: github.repository == 'netdata/netdata'
  602. uses: actions/upload-artifact@v4
  603. with:
  604. name: ghcr-digests-${{ steps.artifact-name.outputs.platform }}
  605. path: /tmp/digests/*
  606. if-no-files-found: error
  607. retention-days: 1
  608. - name: Failure Notification
  609. uses: rtCamp/action-slack-notify@v2
  610. env:
  611. SLACK_COLOR: 'danger'
  612. SLACK_FOOTER: ''
  613. SLACK_ICON_EMOJI: ':github-actions:'
  614. SLACK_TITLE: 'GHCR upload failed:'
  615. SLACK_USERNAME: 'GitHub Actions'
  616. SLACK_MESSAGE: |-
  617. ${{ github.repository }}: Creating or uploading Docker image for ${{ matrix.platform }} on GHCR failed.
  618. Checkout: ${{ steps.checkout.outcome }}
  619. Determine artifact name: ${{ steps.artifact-name.outcome }}
  620. Fetch build cache: ${{ steps.fetch-cache.outcome }}
  621. Setup environment: ${{ steps.env.outcome }}
  622. Setup QEMU: ${{ steps.qemu.outcome }}
  623. Setup buildx: ${{ steps.prepare.outcome }}
  624. Login to registry: ${{ steps.login.outcome }}
  625. Build image: ${{ steps.build.outcome }}
  626. Export digest: ${{ steps.export-digest.outcome }}
  627. Upload digest: ${{ steps.upload-digest.outcome }}
  628. SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL }}
  629. if: >-
  630. ${{
  631. failure()
  632. && github.repository == 'netdata/netdata'
  633. }}
  634. publish-ghcr:
  635. name: Consolidate and tag images for GHCR
  636. if: github.event_name == 'workflow_dispatch'
  637. needs:
  638. - build-images-ghcr
  639. - gen-tags
  640. runs-on: ubuntu-latest
  641. steps:
  642. - name: Checkout
  643. id: checkout
  644. uses: actions/checkout@v4
  645. - name: Download digests
  646. id: fetch-digests
  647. uses: actions/download-artifact@v4
  648. with:
  649. path: /tmp/digests
  650. pattern: ghcr-digests-*
  651. merge-multiple: true
  652. - name: Setup Buildx
  653. id: prepare
  654. uses: docker/setup-buildx-action@v3
  655. - name: Registry Login
  656. id: login
  657. if: github.repository == 'netdata/netdata'
  658. uses: docker/login-action@v3
  659. with:
  660. registry: ghcr.io
  661. username: ${{ github.repository_owner }}
  662. password: ${{ secrets.GITHUB_TOKEN }}
  663. - name: Create and Push Manifest
  664. id: manifest
  665. if: github.repository == 'netdata/netdata'
  666. run: docker buildx imagetools create $(.github/scripts/gen-docker-imagetool-args.py /tmp/digests 'ghcr.io' "${{ needs.gen-tags.outputs.tags }}")
  667. - name: Failure Notification
  668. uses: rtCamp/action-slack-notify@v2
  669. env:
  670. SLACK_COLOR: 'danger'
  671. SLACK_FOOTER: ''
  672. SLACK_ICON_EMOJI: ':github-actions:'
  673. SLACK_TITLE: 'Publishing Docker images on GHCR failed:'
  674. SLACK_USERNAME: 'GitHub Actions'
  675. SLACK_MESSAGE: |-
  676. ${{ github.repository }}: Publishing Docker images on GHCR failed.
  677. Checkout: ${{ steps.checkout.outcome }}
  678. Download digests: ${{ steps.fetch-digests.outcome }}
  679. Setup buildx: ${{ steps.prepare.outcome }}
  680. Login to registry: ${{ steps.login.outcome }}
  681. Create and push manifest: ${{ steps.manifest.outcome }}
  682. SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL }}
  683. if: >-
  684. ${{
  685. failure()
  686. && github.repository == 'netdata/netdata'
  687. }}
  688. trigger-subsequent-workflows:
  689. if: github.event_name == 'workflow_dispatch'
  690. name: Trigger subsquent workflows for newly added versions
  691. needs:
  692. - publish-docker-hub
  693. - gen-tags
  694. runs-on: ubuntu-latest
  695. steps:
  696. - name: Checkout
  697. id: checkout
  698. uses: actions/checkout@v4
  699. with:
  700. submodules: recursive
  701. - name: Trigger Helmchart PR
  702. if: github.event_name == 'workflow_dispatch' && github.event.inputs.version != 'nightly' && github.repository == 'netdata/netdata'
  703. id: trigger-helmchart
  704. uses: benc-uk/workflow-dispatch@v1
  705. with:
  706. token: ${{ secrets.NETDATABOT_GITHUB_TOKEN }}
  707. repo: netdata/helmchart
  708. workflow: Agent Version PR
  709. ref: refs/heads/master
  710. inputs: '{"agent_version": "v${{ inputs.version }}"}'
  711. - name: Trigger MSI build
  712. if: github.event_name == 'workflow_dispatch' && github.event.inputs.version != 'nightly' && github.repository == 'netdata/netdata'
  713. id: trigger-msi
  714. uses: benc-uk/workflow-dispatch@v1
  715. with:
  716. token: ${{ secrets.NETDATABOT_GITHUB_TOKEN }}
  717. repo: netdata/msi-installer
  718. workflow: Build
  719. ref: refs/heads/master
  720. inputs: '{"tag": "stable", "pwd": "${{ secrets.MSI_CODE_SIGNING_PASSWORD }}"}'
  721. - name: Failure Notification
  722. uses: rtCamp/action-slack-notify@v2
  723. env:
  724. SLACK_COLOR: 'danger'
  725. SLACK_FOOTER: ''
  726. SLACK_ICON_EMOJI: ':github-actions:'
  727. SLACK_TITLE: ':'
  728. SLACK_USERNAME: 'GitHub Actions'
  729. SLACK_MESSAGE: |-
  730. ${{ github.repository }}: Version cascade failed
  731. Checkout: ${{ steps.checkout.outcome }}
  732. Trigger Helmchart PR: ${{ steps.trigger-helmchart.outcome }}
  733. Trigger MSI build: ${{ steps.trigger-msi.outcome }}
  734. SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL }}
  735. if: >-
  736. ${{
  737. failure()
  738. && github.event_name != 'pull_request'
  739. && startsWith(github.ref, 'refs/heads/master')
  740. && github.repository == 'netdata/netdata'
  741. }}