docker.yml 29 KB

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