close
Skip to content

ci: cache GitHub runners from NetBox to github-runners.jq#328

Merged
igorpecovnik merged 1 commit into
mainfrom
netbox-github-runners-json
Jun 10, 2026
Merged

ci: cache GitHub runners from NetBox to github-runners.jq#328
igorpecovnik merged 1 commit into
mainfrom
netbox-github-runners-json

Conversation

@igorpecovnik

@igorpecovnik igorpecovnik commented Jun 10, 2026

Copy link
Copy Markdown
Member

What

Adds a step to the Cache servers JSONs workflow (.github/workflows/generate-servers-jsons.yml) that caches self-hosted GitHub runners from NetBox into data/servers/github-runners.jq, alongside the existing mirror lists.

Each entry is one runner host:

{
  "host": "ampere-1",
  "runners": 64,
  "vcpus": 128,
  "memory": 512000,
  "apt_proxy": "http://10.0.40.2:3142",
  "oci_cache": "10.0.40.2:5000",
  "redis_cache": "redis://10.0.40.2:6379"
}

Fields:

  • host — VM name
  • runnersrunners custom field (count)
  • vcpus — VM vCPUs, rounded to integer
  • memory — VM memory in MB (as NetBox stores it)
  • apt_proxy, oci_cache, redis_cache — custom fields, default "" when unset

How runners are selected

NetBox's virtual-machines endpoint ignores device_role (it's a Device filter), so a role query returns all active VMs. We instead fetch all active VMs and filter in jq on .role.name == "Userlevel runner", which reliably excludes unrelated roles (e.g. "Virtual machine").

Reliability hardening (both the new runner fetch and the existing mirror loop)

  • curl retry: --retry 5 --retry-delay 2 --retry-all-errors --fail, --connect-timeout 10 --max-time 60, -sS.
    • This also fixes the prior timeout 10 failure (exit 124) when NetBox's limit=0 response took >10s.
  • Empty-result guard: fails the run with a ::error:: annotation if NetBox returns no matching VMs, instead of committing an empty/broken list to the data branch.

Validation

Verified end-to-end via workflow runs on this branch — output committed to data/servers/github-runners.jq with correct counts and resource/cache fields (e.g. cats → 6 runners, 16 vcpus, 32768 MB).

@github-actions github-actions Bot added size/small PR with less then 50 lines 08 Milestone: Third quarter release GitHub Actions GitHub Actions code Needs review Seeking for review labels Jun 10, 2026
@coderabbitai

coderabbitai Bot commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@igorpecovnik, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 25 minutes and 15 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 8a479527-918a-4420-b75a-84084510058a

📥 Commits

Reviewing files that changed from the base of the PR and between 969f9b5 and 6b0cd98.

📒 Files selected for processing (1)
  • .github/workflows/generate-servers-jsons.yml

Walkthrough

This pull request extends a GitHub Actions workflow to generate an additional JSON artifact containing GitHub runner information from NetBox. The change adds a new workflow step that queries the NetBox API for "Userlevel runner" virtual machines, extracts the host name and runner count for each VM using a jq filter, saves the result to github-runners.jq, and validates the output is a non-empty JSON array. The curl request includes timeout and retry configurations to ensure reliable API interaction. The workflow summary step is extended to display the new artifact alongside previously generated JSON files.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title directly summarizes the main change: adding a step to cache GitHub runners from NetBox to a JSON file (github-runners.jq).
Description check ✅ Passed The description is detailed and relevant, explaining the what, how, reliability measures, and assumptions for the new workflow step.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch netbox-github-runners-json

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.github/workflows/generate-servers-jsons.yml:
- Around line 122-129: The curl command output is captured into the variable
response via command substitution which masks curl failures; modify the code
around the response="$(curl ...)" invocation to capture curl's exit status
and/or HTTP status explicitly and fail fast: run curl so you capture both output
and exit code (e.g., redirect curl output to a temp file or use "curl -sS ... -o
/tmp/resp && echo $?"), then if curl failed or returned a non-2xx HTTP status,
log the error and exit nonzero before piping to jq; ensure you still use
RUNNERS_JQ_FILTER on the validated response and write to runners_outfile only
after the curl success check.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 2c98ccc6-c7ce-4c83-813b-e2932369feee

📥 Commits

Reviewing files that changed from the base of the PR and between 4ce95bf and 969f9b5.

📒 Files selected for processing (1)
  • .github/workflows/generate-servers-jsons.yml

Comment thread .github/workflows/generate-servers-jsons.yml Outdated
@github-actions github-actions Bot added size/medium PR with more then 50 and less then 250 lines and removed size/small PR with less then 50 lines labels Jun 10, 2026
Add a step to the server-JSON generator that queries VMs with role
"Userlevel runner" and writes one entry per runner host to
github-runners.jq, committed under data/servers/ alongside the mirror
lists.

The virtual-machines endpoint ignores the `device_role` filter, so we
fetch all active VMs and select on .role.name == "Userlevel runner" in
jq. Each entry carries host, runners count, vcpus (rounded), memory (MB),
and the apt_proxy / oci_cache / redis_cache custom fields.

Both the new runner fetch and the existing mirror loop are hardened with
curl retry (--retry/--fail/--max-time, -sS) and an empty-result guard, so
a slow or empty NetBox response retries or fails loudly instead of timing
out (the old `timeout 10` exit 124) or committing a broken list.
@igorpecovnik igorpecovnik force-pushed the netbox-github-runners-json branch from 5acc15b to 6b0cd98 Compare June 10, 2026 08:53
@igorpecovnik igorpecovnik requested a review from iav June 10, 2026 08:54

@iav iav left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not "in the know", so I can't understand much.
But at first glance to an outsider, everything looks normal, it should work.
I also asked Claude to evaluate this pr in the context of the experience gained in the process of debugging my ccache-network and sccache extensions - he also generally approved, without any comments worth mentioning.

@github-actions github-actions Bot added the Ready to merge Reviewed, tested and ready for merge label Jun 10, 2026
@github-actions

Copy link
Copy Markdown

✅ This PR has been reviewed and approved — all set for merge!

@github-actions github-actions Bot removed the Needs review Seeking for review label Jun 10, 2026
@igorpecovnik

Copy link
Copy Markdown
Member Author

Its just preparing JSON for the next step - using it in the build process so we don't burn Netbox API calls.

@igorpecovnik igorpecovnik merged commit 432aa2d into main Jun 10, 2026
9 checks passed
@igorpecovnik igorpecovnik deleted the netbox-github-runners-json branch June 10, 2026 14:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

08 Milestone: Third quarter release GitHub Actions GitHub Actions code Ready to merge Reviewed, tested and ready for merge size/medium PR with more then 50 and less then 250 lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants