Skip to content

Build: Better Parallelization#64

Open
kyler-lb wants to merge 2 commits into
mainfrom
kyler/el8-el9-v2-race
Open

Build: Better Parallelization#64
kyler-lb wants to merge 2 commits into
mainfrom
kyler/el8-el9-v2-race

Conversation

@kyler-lb

@kyler-lb kyler-lb commented Jun 19, 2026

Copy link
Copy Markdown

When building el8/el9 targets in parallel the two targets would collide on their shared directory. This splits them such that they can build in parallel.

For testing I built the full light-app:packages-core-el8/el9 targets with v2 with force and no checkout.

Depends-On: https://github.com/LightBitsLabs/lb_containers/pull/152

Issue: LBM1-45815

el8/el9 shared build/dist (raced on rm/rpmbuild) and the deb used 'sudo alien' which left a root-owned scratch dir a later non-root rm couldn't clear. Make RPMOUT_DIR per-distro (build/dist/$*), and build the deb with 'fakeroot alien' in an isolated mktemp scratch (no sudo/chown).

Signed-off-by: kyler <kyler@lightbitslabs.com>
Issue: LBM1-45815
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@kyler-lb kyler-lb requested a review from anton-lb June 19, 2026 20:10
@coderabbitai

coderabbitai Bot commented Jun 19, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The Makefile's packaging targets are refactored to use architecture-scoped output directories. discovery-rpms-% computes a per-arch RPMOUT_DIR under build/dist/$*, depends on build/dist and build/discovery-client, cleans only the arch-specific directory, and runs rpmbuild with _rpmdir pointing to that directory. discovery-client-debs-% replaces the single discovery-client-debs target with an arch-specific variant that defines DEB_WORK under build/deb/$*, builds the RPM into a temp subdirectory within DEB_WORK, converts it to DEBs using fakeroot alien in an isolated mktemp scratch directory, copies the resulting .deb files into DEB_WORK, and cleans up the temp directory. install-discovery-client-packages-% updates its artifact source paths to copy RPMs from build/dist/$*/x86_64/ and DEBs from build/deb/$*.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • LightBitsLabs/discovery-client#56: Modifies the same discovery-client-debs Makefile target, adjusting the RPM-to-DEB conversion via alien and .deb file output handling.
  • LightBitsLabs/discovery-client#61: Overlaps at the same discovery-client-debs and install-discovery-client-packages-% targets, touching the alien conversion and artifact copy logic.

Suggested reviewers

  • ron-lb
  • davidf-lb
  • yant-lb
  • shaharz-lb
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The title 'Build: Better Parallelization' is vague and doesn't specifically indicate the changeset involves refactoring Makefile targets to enable parallel building of el8/el9 distributions. Consider a more specific title like 'Makefile: Separate arch-specific build artifacts for parallel el8/el9 builds' to better communicate the primary change.
✅ Passed checks (4 passed)
Check name Status Explanation
Description check ✅ Passed The description clearly explains the parallelization collision issue, the solution of splitting into per-distro targets, and references the tested scenarios and related issue.
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 kyler/el8-el9-v2-race

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

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🧹 Nitpick comments (2)
Makefile (2)

152-153: 💤 Low value

Optional: Declare discovery-client-debs as a PHONY target.

Since discovery-client-debs is not a file target (it's a task that produces files in different locations), we should declare it as .PHONY to ensure Make always runs it regardless of filesystem state.

📝 Suggested addition

Near other .PHONY declarations in the Makefile:

.PHONY: discovery-client-debs
🤖 Prompt for 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.

In `@Makefile` around lines 152 - 153, The discovery-client-debs target is not
declared as a PHONY target, which can cause Make to skip execution if a file or
directory with that name already exists. Add discovery-client-debs to the PHONY
declarations in the Makefile by either adding it to an existing .PHONY line
along with other non-file targets, or creating a new .PHONY:
discovery-client-debs declaration near the other .PHONY declarations in the
file.

Source: Linters/SAST tools


168-168: ⚡ Quick win

Consider using a shared variable for the RPM output path.

Line 168 hardcodes build/dist/$*/x86_64/ which duplicates the directory structure from RPMOUT_DIR in discovery-rpms-% (line 147). While this works, it creates a maintenance risk if we ever change the output directory structure—we'd need to update both locations.

♻️ Suggested approach: Define a shared Make function

At the top of the Makefile (in the global scope), define:

rpm_out_dir = $(WORKSPACE_TOP)/discovery-client/build/dist/$1

Then update both targets:

-discovery-rpms-%: RPMOUT_DIR = $(WORKSPACE_TOP)/discovery-client/build/dist/$*
+discovery-rpms-%: RPMOUT_DIR = $(call rpm_out_dir,$*)
-	$(Q)cp build/dist/$*/x86_64/discovery-client*el*.rpm $(COMPONENT_PATH)/
+	$(Q)cp $(call rpm_out_dir,$*)/x86_64/discovery-client*el*.rpm $(COMPONENT_PATH)/

This ensures both targets use the same path pattern and reduces the risk of divergence.

🤖 Prompt for 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.

In `@Makefile` at line 168, The hardcoded path build/dist/$*/x86_64/ in the cp
command duplicates the directory structure already defined in RPMOUT_DIR within
the discovery-rpms-% target, creating maintenance risk. Define a shared Make
function at the top of the Makefile (in global scope) named rpm_out_dir that
accepts a parameter and returns the full path pattern incorporating
WORKSPACE_TOP, discovery-client, build/dist, and the component parameter. Then
update both the cp command in this target and the RPMOUT_DIR definition in
discovery-rpms-% to use this shared function instead of hardcoding the path.
🤖 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 `@Makefile`:
- Around line 152-158: The discovery-client-debs target uses the global
RPMOUT_DIR variable to locate the RPM file, but the actual RPM is built in an
el8-specific subdirectory that is not accounted for in the current path. Fix
this by adding a target-specific RPMOUT_DIR variable assignment for the
discovery-client-debs target that includes the el8 subdirectory in the path,
matching where the discovery-rpms-el8 target actually creates the RPM file. This
will ensure the alien conversion command on line 156 can correctly locate the
RPM file at the expected location.

---

Nitpick comments:
In `@Makefile`:
- Around line 152-153: The discovery-client-debs target is not declared as a
PHONY target, which can cause Make to skip execution if a file or directory with
that name already exists. Add discovery-client-debs to the PHONY declarations in
the Makefile by either adding it to an existing .PHONY line along with other
non-file targets, or creating a new .PHONY: discovery-client-debs declaration
near the other .PHONY declarations in the file.
- Line 168: The hardcoded path build/dist/$*/x86_64/ in the cp command
duplicates the directory structure already defined in RPMOUT_DIR within the
discovery-rpms-% target, creating maintenance risk. Define a shared Make
function at the top of the Makefile (in global scope) named rpm_out_dir that
accepts a parameter and returns the full path pattern incorporating
WORKSPACE_TOP, discovery-client, build/dist, and the component parameter. Then
update both the cp command in this target and the RPMOUT_DIR definition in
discovery-rpms-% to use this shared function instead of hardcoding the path.
🪄 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: 8c7dadc1-30f5-4b78-a651-5fd2a0fbe347

📥 Commits

Reviewing files that changed from the base of the PR and between 8841f04 and 33830cb.

📒 Files selected for processing (1)
  • Makefile

Comment thread Makefile Outdated
@kyler-lb kyler-lb changed the title Fix: Better Parallelization Build: Better Parallelization Jun 19, 2026
discovery-client-debs was shared by both package components, so concurrent el8/el9 builds still raced on the deb's rpmbuild --clean output (build/dist/x86_64) and the deb copy. Make it per-distro (discovery-client-debs-%) into build/deb/$*; install copies the per-distro deb.

Signed-off-by: kyler <kyler@lightbitslabs.com>
Issue: LBM1-45815
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@kyler-lb

Copy link
Copy Markdown
Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 19, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot 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.

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 `@Makefile`:
- Around line 152-161: The discovery-client-debs-% target is missing an explicit
prerequisite on build/discovery-client, which causes direct invocation to fail
if the binary hasn't been built. Additionally, the temporary directory created
in deb_scratch variable will leak if fakeroot alien fails because the && chain
exits before the cleanup command executes. Add build/discovery-client as a
prerequisite dependency to the discovery-client-debs-% target declaration, and
refactor the command block to ensure the rm -rf $$deb_scratch cleanup executes
regardless of whether fakeroot alien succeeds or fails, such as by using a trap
statement or restructuring the command logic.
🪄 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: 1706ba72-298c-4bb0-ab3d-4e4af5bd0812

📥 Commits

Reviewing files that changed from the base of the PR and between 33830cb and 52c932f.

📒 Files selected for processing (1)
  • Makefile

Comment thread Makefile
Comment on lines +152 to +161
# Per-distro work dir so concurrent el8/el9 deb builds don't share a path.
discovery-client-debs-%: VERSION = $(or $(LIGHTOS_VERSION),$(DEFAULT_REL))
discovery-client-debs-%: DEB_WORK = $(WORKSPACE_TOP)/discovery-client/build/deb/$*
discovery-client-debs-%:
$(Q) rm -rf $(DEB_WORK)
$(Q) rpmbuild -bb --clean --define="version ${VERSION}" --define="_builddir `pwd`" --define="dist $(DISCOVERY_CLIENT_RELEASE)" --define "_rpmdir $(DEB_WORK)/rpm" discovery-client.spec
$(Q) deb_scratch=`mktemp -d` && \
( cd $$deb_scratch && fakeroot alien --to-deb -v -k $(DEB_WORK)/rpm/x86_64/discovery-client-${VERSION}-${DISCOVERY_CLIENT_RELEASE}.x86_64.rpm ) && \
cp $$deb_scratch/*.deb $(DEB_WORK)/ && \
rm -rf $$deb_scratch

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Missing prerequisite for direct invocation and temp directory may leak on failure.

The discovery-client-debs-% target runs rpmbuild but doesn't declare a dependency on build/discovery-client. While this works transitively through discovery-packages-el* (which depends on discovery-rpms-%), a direct make discovery-client-debs-el8 invocation would fail if the binary hasn't been built yet. Additionally, if fakeroot alien fails, the && chain exits and $$deb_scratch won't be cleaned up.

🛠️ Suggested fix with trap for cleanup and explicit dependency
 # Per-distro work dir so concurrent el8/el9 deb builds don't share a path.
 discovery-client-debs-%: VERSION = $(or $(LIGHTOS_VERSION),$(DEFAULT_REL))
 discovery-client-debs-%: DEB_WORK = $(WORKSPACE_TOP)/discovery-client/build/deb/$*
-discovery-client-debs-%:
+discovery-client-debs-%: build/discovery-client
 	$(Q) rm -rf $(DEB_WORK)
 	$(Q) rpmbuild -bb --clean --define="version ${VERSION}" --define="_builddir `pwd`" --define="dist $(DISCOVERY_CLIENT_RELEASE)" --define "_rpmdir $(DEB_WORK)/rpm" discovery-client.spec
-	$(Q) deb_scratch=`mktemp -d` && \
-		( cd $$deb_scratch && fakeroot alien --to-deb -v -k $(DEB_WORK)/rpm/x86_64/discovery-client-${VERSION}-${DISCOVERY_CLIENT_RELEASE}.x86_64.rpm ) && \
-		cp $$deb_scratch/*.deb $(DEB_WORK)/ && \
-		rm -rf $$deb_scratch
+	$(Q) deb_scratch=`mktemp -d`; \
+		trap "rm -rf $$deb_scratch" EXIT; \
+		( cd $$deb_scratch && fakeroot alien --to-deb -v -k $(DEB_WORK)/rpm/x86_64/discovery-client-${VERSION}-${DISCOVERY_CLIENT_RELEASE}.x86_64.rpm ) && \
+		cp $$deb_scratch/*.deb $(DEB_WORK)/
🧰 Tools
🪛 checkmake (0.3.2)

[warning] 155-155: Target body for "discovery-client-debs-%" exceeds allowed length of 5 lines (6).

(maxbodylength)


[warning] 153-153: Target "discovery-client-debs-%" should be declared PHONY.

(phonydeclared)


[warning] 154-154: Target "discovery-client-debs-%" should be declared PHONY.

(phonydeclared)


[warning] 154-154: Target "discovery-client-debs-%" defined multiple times (lines 153 and 154).

(uniquetargets)


[warning] 155-155: Target "discovery-client-debs-%" defined multiple times (lines 153 and 155).

(uniquetargets)

🤖 Prompt for 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.

In `@Makefile` around lines 152 - 161, The discovery-client-debs-% target is
missing an explicit prerequisite on build/discovery-client, which causes direct
invocation to fail if the binary hasn't been built. Additionally, the temporary
directory created in deb_scratch variable will leak if fakeroot alien fails
because the && chain exits before the cleanup command executes. Add
build/discovery-client as a prerequisite dependency to the
discovery-client-debs-% target declaration, and refactor the command block to
ensure the rm -rf $$deb_scratch cleanup executes regardless of whether fakeroot
alien succeeds or fails, such as by using a trap statement or restructuring the
command logic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant