docker.yml 29 KB

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