Skip to content

Allow building a stemcell with a custom agent (jammy)#508

Open
mkocher wants to merge 1 commit intoubuntu-jammyfrom
custom-agent-jammy
Open

Allow building a stemcell with a custom agent (jammy)#508
mkocher wants to merge 1 commit intoubuntu-jammyfrom
custom-agent-jammy

Conversation

@mkocher
Copy link
Copy Markdown
Member

@mkocher mkocher commented Apr 2, 2026

Set BOSH_AGENT_BIN_PATH=./bosh-agent to provide a bosh agent binary to be injected into the stemcell being built. Useful when doing agent development work.

I don't love environment variables, but since this is only a development flow it doesn't seem like it makes much sense as a rake task argument.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 2, 2026

📝 Walkthrough

Walkthrough

Adds optional support for injecting a prebuilt bosh-agent into development stemcell builds via the BOSH_AGENT_BIN_PATH environment variable; updates README, passes the variable through build environment generation, and conditionally uses the provided binary in the build script.

Changes

Cohort / File(s) Summary
Documentation
README.md
Adds note documenting BOSH_AGENT_BIN_PATH for development stemcell builds.
Build Environment Configuration
bosh-stemcell/lib/bosh/stemcell/build_environment.rb
command_env now merges proxy, build-time, and passthrough environment settings. Adds private passthrough_settings_from_environment to include BOSH_AGENT_BIN_PATH (case-insensitive) in emitted env.
Stemcell Build Script
stemcell_builder/stages/bosh_go_agent/apply.sh
Accepts BOSH_AGENT_BIN_PATH; normalizes and validates path, and when set copies the provided binary into the workspace as bosh-agent instead of downloading. Preserves original download flow when unset.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 I hopped into the build today,
A binary tucked neatly in my hay,
Set BOSH_AGENT_BIN_PATH, give it a pat,
I copied it in — no download spat.
Stemcells dance, and I munch away.

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: allowing custom agent injection during stemcell builds, with the ubuntu-jammy context.
Description check ✅ Passed The description directly explains the purpose and usage of BOSH_AGENT_BIN_PATH environment variable and its intended use case for agent development.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch custom-agent-jammy

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 RuboCop (1.86.0)
bosh-stemcell/lib/bosh/stemcell/build_environment.rb

Error: The Layout/IndentHash cop has been renamed to Layout/FirstHashElementIndentation.
(obsolete configuration found in .rubocop.yml, please update it)
The Metrics/LineLength cop has been moved to Layout/LineLength.
(obsolete configuration found in .rubocop.yml, please update it)
The Style/BracesAroundHashParameters cop has been removed. Please use and/or instead.
(obsolete configuration found in .rubocop.yml, please update it)

Warning

Review ran into problems

🔥 Problems

Timed out fetching pipeline failures after 30000ms


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.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@README.md`:
- Around line 93-94: Remove the trailing space at the end of the sentence "While
building a stemcell for development purposes it is possible to set the
BOSH_AGENT_BIN_PATH environment variable to inject an agent binary into the
stemcell instead of downloading one." in README.md; edit the line (no code
change otherwise) so there is no trailing whitespace character at the end of
that paragraph.

In `@stemcell_builder/stages/bosh_go_agent/apply.sh`:
- Around line 43-49: Quote the variable expansions to prevent word-splitting:
when reading the bosh_agent_version use bosh_agent_version="$(cat
"${assets_dir}/bosh-agent-version")" (quote ${assets_dir}), and update the meta4
invocation to quote the path and generated filename like
--metalink="${assets_dir}/metalink.meta4" and
--file="bosh-agent-${bosh_agent_version}-linux-amd64"; keep existing quoting for
"${BOSH_AGENT_BIN_PATH}" in the cp call. This ensures assets_dir and
bosh_agent_version are safely expanded in apply.sh.
🪄 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: ASSERTIVE

Plan: Pro

Run ID: 43212182-52bf-41fb-88ea-cfb479d52bd0

📥 Commits

Reviewing files that changed from the base of the PR and between 96c7f29 and 391d3c5.

📒 Files selected for processing (3)
  • README.md
  • bosh-stemcell/lib/bosh/stemcell/build_environment.rb
  • stemcell_builder/stages/bosh_go_agent/apply.sh

Set BOSH_AGENT_BIN_PATH=./bosh-agent to provide a bosh agent binary
to be injected into the stemcell being built. Useful when doing agent
development work.
@mkocher mkocher force-pushed the custom-agent-jammy branch from 391d3c5 to d59c2ac Compare April 2, 2026 08:02
@mkocher mkocher requested a review from aramprice April 2, 2026 08:03
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@bosh-stemcell/lib/bosh/stemcell/build_environment.rb`:
- Around line 238-242: passthrough_settings_from_environment currently returns
environment keys with their original casing which can emit lowercase keys (e.g.,
bosh_agent_bin_path) and break downstream checks; update
passthrough_settings_from_environment so it emits keys normalized to uppercase
(e.g., BOSH_AGENT_BIN_PATH) while retaining their values: when selecting keys
from environment (using the existing keep list and environment.select),
transform the selected key names to upcase before returning so apply.sh and
other consumers will see the expected uppercase variable names.
- Around line 103-106: Add unit specs for the new passthrough merge path to
cover BOSH_AGENT_BIN_PATH presence, absence and casing for the command_env
behavior: in the existing describe for `#command_env` add contexts that set the
subject's env to include 'BOSH_AGENT_BIN_PATH' (e.g. '/tmp/bosh-agent') and
assert command_env includes "BOSH_AGENT_BIN_PATH='/tmp/bosh-agent'"; another
context with env = {} asserting command_env does not include
'BOSH_AGENT_BIN_PATH='; and an additional context that verifies behavior for
alternate casing (e.g. 'bosh_agent_bin_path' or 'Bosh_Agent_Bin_Path') to
document whether passthrough_settings_from_environment/hash_as_bash_env treats
keys case-sensitively. Ensure these specs exercise command_env,
passthrough_settings_from_environment and hash_as_bash_env so regressions are
caught.
🪄 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: ASSERTIVE

Plan: Pro

Run ID: deb8ad65-5064-4558-9dac-b1496e5ed96c

📥 Commits

Reviewing files that changed from the base of the PR and between 391d3c5 and d59c2ac.

📒 Files selected for processing (3)
  • README.md
  • bosh-stemcell/lib/bosh/stemcell/build_environment.rb
  • stemcell_builder/stages/bosh_go_agent/apply.sh

Comment on lines +103 to +106
settings = proxy_settings_from_environment
.merge(build_time_settings)
.merge(passthrough_settings_from_environment)
"env #{hash_as_bash_env(settings)}"
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick | 🔵 Trivial

Add specs for the new passthrough merge path.

The command_env behavior changed but current specs don’t cover BOSH_AGENT_BIN_PATH presence/absence/casing, which makes regressions likely in this new flow.

✅ Suggested spec additions
# in bosh-stemcell/spec/bosh/stemcell/build_environment_spec.rb (describe '#command_env')

context 'when BOSH_AGENT_BIN_PATH is set' do
  let(:env) { { 'BOSH_AGENT_BIN_PATH' => '/tmp/bosh-agent' } }

  it 'includes BOSH_AGENT_BIN_PATH in command env' do
    expect(subject.command_env).to include("BOSH_AGENT_BIN_PATH='/tmp/bosh-agent'")
  end
end

context 'when BOSH_AGENT_BIN_PATH is not set' do
  let(:env) { {} }

  it 'does not include BOSH_AGENT_BIN_PATH' do
    expect(subject.command_env).not_to include('BOSH_AGENT_BIN_PATH=')
  end
end
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@bosh-stemcell/lib/bosh/stemcell/build_environment.rb` around lines 103 - 106,
Add unit specs for the new passthrough merge path to cover BOSH_AGENT_BIN_PATH
presence, absence and casing for the command_env behavior: in the existing
describe for `#command_env` add contexts that set the subject's env to include
'BOSH_AGENT_BIN_PATH' (e.g. '/tmp/bosh-agent') and assert command_env includes
"BOSH_AGENT_BIN_PATH='/tmp/bosh-agent'"; another context with env = {} asserting
command_env does not include 'BOSH_AGENT_BIN_PATH='; and an additional context
that verifies behavior for alternate casing (e.g. 'bosh_agent_bin_path' or
'Bosh_Agent_Bin_Path') to document whether
passthrough_settings_from_environment/hash_as_bash_env treats keys
case-sensitively. Ensure these specs exercise command_env,
passthrough_settings_from_environment and hash_as_bash_env so regressions are
caught.

Comment on lines +238 to +242
def passthrough_settings_from_environment
keep = %w(BOSH_AGENT_BIN_PATH)

environment.select { |k| keep.include?(k.upcase) }
end
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 | 🟠 Major

Normalize passthrough key casing to uppercase before emitting env.

Line 241 currently preserves caller key casing. If input is bosh_agent_bin_path, it will be emitted lowercase, but downstream apply.sh checks BOSH_AGENT_BIN_PATH uppercase only, so the custom-agent path is skipped unexpectedly.

🐛 Proposed fix
 def passthrough_settings_from_environment
-  keep = %w(BOSH_AGENT_BIN_PATH)
-
-  environment.select { |k| keep.include?(k.upcase) }
+  value = environment['BOSH_AGENT_BIN_PATH']
+  if value.nil?
+    pair = environment.find { |k, _v| k.upcase == 'BOSH_AGENT_BIN_PATH' }
+    value = pair&.last
+  end
+
+  value.nil? ? {} : { 'BOSH_AGENT_BIN_PATH' => value }
 end
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
def passthrough_settings_from_environment
keep = %w(BOSH_AGENT_BIN_PATH)
environment.select { |k| keep.include?(k.upcase) }
end
def passthrough_settings_from_environment
value = environment['BOSH_AGENT_BIN_PATH']
if value.nil?
pair = environment.find { |k, _v| k.upcase == 'BOSH_AGENT_BIN_PATH' }
value = pair&.last
end
value.nil? ? {} : { 'BOSH_AGENT_BIN_PATH' => value }
end
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@bosh-stemcell/lib/bosh/stemcell/build_environment.rb` around lines 238 - 242,
passthrough_settings_from_environment currently returns environment keys with
their original casing which can emit lowercase keys (e.g., bosh_agent_bin_path)
and break downstream checks; update passthrough_settings_from_environment so it
emits keys normalized to uppercase (e.g., BOSH_AGENT_BIN_PATH) while retaining
their values: when selecting keys from environment (using the existing keep list
and environment.select), transform the selected key names to upcase before
returning so apply.sh and other consumers will see the expected uppercase
variable names.

Copy link
Copy Markdown
Contributor

@rkoster rkoster left a comment

Choose a reason for hiding this comment

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

Don't like how intrusive these changes are. For iterating on an agent change I would highly recommend using the repack helper scripts here: https://github.com/cloudfoundry/bosh-linux-stemcell-builder/tree/ubuntu-jammy/scripts/repack-helpers

When working with the docker cpi a simple Dockerfile and the lite stemcell support (which just need a reference to a local image) also work really well.

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

Labels

None yet

Projects

Status: Waiting for Changes | Open for Contribution

Development

Successfully merging this pull request may close these issues.

3 participants