Skip to content

Commit 391d3c5

Browse files
committed
Allow building a stemcell with a custom agent
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.
1 parent 96c7f29 commit 391d3c5

3 files changed

Lines changed: 28 additions & 3 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ The arguments to `stemcell:build_with_local_os_image` are:
9090
of the most recent release and add one, e.g.: "0.0.7" → "0.0.8". If not
9191
specified, it will default to "0000".
9292

93+
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.
94+
9395
### The Resulting Stemcell
9496

9597
You can find the resulting stemcell in the `tmp/` directory of the host, or in

bosh-stemcell/lib/bosh/stemcell/build_environment.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,10 @@ def stemcell_disk_size
100100
end
101101

102102
def command_env
103-
"env #{hash_as_bash_env(proxy_settings_from_environment.merge(build_time_settings))}"
103+
settings = proxy_settings_from_environment
104+
.merge(build_time_settings)
105+
.merge(passthrough_settings_from_environment)
106+
"env #{hash_as_bash_env(settings)}"
104107
end
105108

106109
private
@@ -232,6 +235,12 @@ def proxy_settings_from_environment
232235
environment.select { |k| keep.include?(k.upcase) }
233236
end
234237

238+
def passthrough_settings_from_environment
239+
keep = %w(BOSH_AGENT_BIN_PATH)
240+
241+
environment.select { |k| keep.include?(k.upcase) }
242+
end
243+
235244
def hash_as_bash_env(env)
236245
env.map { |k, v| "#{k}='#{v}'" }.join(' ')
237246
end

stemcell_builder/stages/bosh_go_agent/apply.sh

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@ rm -f /etc/service/monit
2323
ln -s /etc/sv/monit /etc/service/monit
2424
"
2525

26+
# Resolve BOSH_AGENT_BIN_PATH to absolute before cd changes the working directory
27+
if [[ -n "${BOSH_AGENT_BIN_PATH:-}" ]]; then
28+
BOSH_AGENT_BIN_PATH=$(readlink -f "${BOSH_AGENT_BIN_PATH}")
29+
if [[ ! -f "${BOSH_AGENT_BIN_PATH}" ]]; then
30+
echo "Error: BOSH_AGENT_BIN_PATH '${BOSH_AGENT_BIN_PATH}' does not exist or is not a regular file" >&2
31+
exit 1
32+
fi
33+
fi
34+
2635
# Alerts for monit config
2736
cp -a $assets_dir/alerts.monitrc $chroot/var/vcap/monit/alerts.monitrc
2837
cd $assets_dir
@@ -31,8 +40,13 @@ wget -O /usr/bin/meta4 https://github.com/dpb587/metalink/releases/download/v0.2
3140
&& echo "81a592eaf647358563f296aced845ac60d9061a45b30b852d1c3f3674720fe19 /usr/bin/meta4" | shasum -a 256 -c \
3241
&& chmod +x /usr/bin/meta4
3342

34-
bosh_agent_version=$(cat ${assets_dir}/bosh-agent-version)
35-
/usr/bin/meta4 file-download --metalink=${assets_dir}/metalink.meta4 --file=bosh-agent-${bosh_agent_version}-linux-amd64 bosh-agent
43+
if [[ -n "${BOSH_AGENT_BIN_PATH:-}" ]]; then
44+
echo "BOSH_AGENT_BIN_PATH is set — using custom bosh-agent binary from: ${BOSH_AGENT_BIN_PATH}"
45+
cp "${BOSH_AGENT_BIN_PATH}" bosh-agent
46+
else
47+
bosh_agent_version=$(cat ${assets_dir}/bosh-agent-version)
48+
/usr/bin/meta4 file-download --metalink=${assets_dir}/metalink.meta4 --file=bosh-agent-${bosh_agent_version}-linux-amd64 bosh-agent
49+
fi
3650

3751
mv bosh-agent $chroot/var/vcap/bosh/bin/
3852

0 commit comments

Comments
 (0)