Skip to content

Commit 5de1dea

Browse files
nikhil2611Copilot
andauthored
CHEF-35087 - Use appbundler in hab packaging and install latest Habitat in Windows test (#341)
* using appbundler to pin versions and removed harcoded hab version in windows test pipeline Signed-off-by: nikhil2611 <ngupta@progress.com> * align plan.sh and binstub_patch.rb with chef's appbundler pattern - Simplified binstub_patch.rb to match chef/chef (only GEM_PATH + APPBUNDLER_ALLOW_RVM) - Updated do_setup_environment to use push_runtime_env/set_runtime_env - Fixed do_prepare to use proper /usr/bin/env symlink pattern with do_end cleanup - Reordered do_install: fix_interpreter vendor/bin -> appbundler -> sed binstub_patch - Reference external binstub_patch.rb file instead of inline generation - Removed fix_interpreter on bin/* (not needed, matches chef pattern) Signed-off-by: nikhil2611 <ngupta@progress.com> * Remove CHEF-35087 scan fix changes that belong in PR #342 Reverts addressable version bump, cleanup_lint_roller chef-cli addition, and .github directory removal logic from this PR as they are handled separately in PR #342. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: nikhil2611 <ngupta@progress.com> * Remove unnecessary core/sed from pkg_build_deps sed is already available in the Habitat Studio base environment, so an explicit dependency is not required. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: nikhil2611 <ngupta@progress.com> * Restore .github removal in plan.ps1 and addressable version in gemspec - Restore .github directories removal from vendored gems in plan.ps1 - Restore addressable dependency to >= 2.9.0, < 3.0 in gemspec (these changes were already merged and should not be reverted) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: nikhil2611 <ngupta@progress.com> * Fix do_install: use cleanup_gem_lockfiles.rb instead of cleanup_lint_roller.rb cleanup_lint_roller.rb does not exist in this repo. The equivalent script is cleanup_gem_lockfiles.rb which removes stray Gemfile.lock files from vendored gems. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: nikhil2611 <ngupta@progress.com> --------- Signed-off-by: nikhil2611 <ngupta@progress.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent ed11f7b commit 5de1dea

4 files changed

Lines changed: 61 additions & 55 deletions

File tree

.expeditor/buildkite/artifact.habitat.test.ps1

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ $env:HAB_BLDR_CHANNEL = "base-2025"
99
$env:HAB_REFRESH_CHANNEL = "base-2025"
1010
$env:CHEF_LICENSE = 'accept-no-persist'
1111
$env:HAB_LICENSE = 'accept-no-persist'
12-
$HabitatVersion = if ($env:HAB_VERSION) { $env:HAB_VERSION } else { '1.6.1245' }
1312
$Plan = 'chef-cli'
1413

1514
Write-Host "--- system details"
@@ -28,20 +27,8 @@ function Stop-HabProcess {
2827

2928
# Installing Habitat
3029
function Install-Habitat {
31-
param(
32-
[Parameter(Mandatory = $true)]
33-
[string]$Version
34-
)
35-
Write-Host "Downloading and installing Habitat version $Version..."
36-
$installScriptUrl = 'https://raw.githubusercontent.com/habitat-sh/habitat/main/components/hab/install.ps1'
37-
$installScriptPath = Join-Path $env:TEMP "hab-install-$Version.ps1"
38-
Invoke-WebRequest -Uri $installScriptUrl -OutFile $installScriptPath
39-
try {
40-
& $installScriptPath -Version $Version
41-
}
42-
finally {
43-
Remove-Item $installScriptPath -Force -ErrorAction SilentlyContinue
44-
}
30+
Write-Host "Downloading and installing Habitat..."
31+
Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://raw.githubusercontent.com/habitat-sh/habitat/main/components/hab/install.ps1'))
4532
}
4633

4734
try {
@@ -64,7 +51,7 @@ catch {
6451
}
6552
}
6653

67-
Install-Habitat -Version $HabitatVersion
54+
Install-Habitat
6855
Write-Host "******************************************************************"
6956
Write-Host "** What is My Hab Version after installation? $(hab --version)"
7057
Write-Host "******************************************************************"
@@ -81,9 +68,6 @@ Write-Host "--- Generating fake origin key"
8168
hab origin key generate $env:HAB_ORIGIN
8269

8370
Write-Host "--- Building $Plan"
84-
Write-Host "******************************************************************"
85-
Write-Host "** What is My Project Root as determined by git rev? $(git rev-parse --show-toplevel)"
86-
Write-Host "******************************************************************"
8771
$project_root = "$(git rev-parse --show-toplevel)"
8872
Set-Location $project_root
8973

binstub_patch.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
unless ENV["APPBUNDLER_ALLOW_RVM"]
2+
ENV["APPBUNDLER_ALLOW_RVM"] = "true"
3+
ENV["GEM_PATH"] = [File.expand_path(File.join(__dir__, "..", "vendor")), ENV["GEM_PATH"]].compact.join(File::PATH_SEPARATOR)
4+
end

habitat/plan.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,4 +113,4 @@ function Invoke-After {
113113
# Remove .github directories from vendored gems to avoid CVE false positives
114114
Get-ChildItem $pkg_prefix/vendor/gems -Filter ".github" -Directory -Recurse `
115115
| Remove-Item -Recurse -Force
116-
}
116+
}

habitat/plan.sh

Lines changed: 53 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,40 @@ pkg_origin=chef
55
ruby_pkg="core/ruby3_4"
66
pkg_deps=(${ruby_pkg} core/coreutils core/libarchive)
77
pkg_build_deps=(
8-
core/make
9-
core/sed
10-
core/gcc
11-
core/git
12-
)
8+
core/make
9+
core/gcc
10+
core/git
11+
)
1312
pkg_bin_dirs=(bin)
1413

1514
do_setup_environment() {
16-
build_line 'Setting GEM_HOME="$pkg_prefix/vendor"'
17-
export GEM_HOME="$pkg_prefix/vendor"
15+
push_runtime_env GEM_PATH "${pkg_prefix}/vendor"
1816

19-
build_line "Setting GEM_PATH=$GEM_HOME"
20-
export GEM_PATH="$GEM_HOME"
17+
set_runtime_env APPBUNDLER_ALLOW_RVM "true" # prevent appbundler from clearing out the carefully constructed runtime GEM_PATH
18+
set_runtime_env LANG "en_US.UTF-8"
19+
set_runtime_env LC_CTYPE "en_US.UTF-8"
2120
}
21+
2222
do_prepare() {
23-
ln -sf "$(pkg_interpreter_for core/ruby3_4 bin/ruby)" "$(pkg_interpreter_for core/coreutils bin/env)"
23+
if [[ ! -f /usr/bin/env ]]; then
24+
ln -s "$(pkg_interpreter_for core/coreutils bin/env)" /usr/bin/env
25+
fi
2426
}
27+
2528
pkg_version() {
2629
cat "$SRC_PATH/VERSION"
2730
}
31+
2832
do_before() {
2933
update_pkg_version
3034
}
35+
3136
do_unpack() {
3237
mkdir -pv "$HAB_CACHE_SRC_PATH/$pkg_dirname"
3338
cp -RT "$PLAN_CONTEXT"/.. "$HAB_CACHE_SRC_PATH/$pkg_dirname/"
3439
}
35-
do_build() {
3640

41+
do_build() {
3742
export GEM_HOME="$pkg_prefix/vendor"
3843

3944
build_line "Setting GEM_PATH=$GEM_HOME"
@@ -48,51 +53,57 @@ do_build() {
4853
ruby ./cleanup_gem_lockfiles.rb
4954
ruby ./post-bundle-install.rb
5055
}
56+
5157
do_install() {
5258

53-
# Copy NOTICE.TXT to the package directory
59+
# Copy NOTICE to the package directory
5460
if [[ -f "$PLAN_CONTEXT/../NOTICE" ]]; then
5561
build_line "Copying NOTICE to package directory"
5662
cp "$PLAN_CONTEXT/../NOTICE" "$pkg_prefix/"
5763
else
5864
build_line "Warning: NOTICE not found at $PLAN_CONTEXT/../NOTICE"
5965
fi
6066

61-
export GEM_HOME="$pkg_prefix/vendor"
67+
export GEM_HOME="$pkg_prefix/vendor"
6268

6369
build_line "Setting GEM_PATH=$GEM_HOME"
6470
export GEM_PATH="$GEM_HOME"
6571
gem install chef-cli-*.gem --no-document
66-
set_runtime_env "GEM_PATH" "${pkg_prefix}/vendor"
67-
wrap_ruby_bin
68-
rm -rf $GEM_PATH/cache/
69-
rm -rf $GEM_PATH/bundler
70-
rm -rf $GEM_PATH/doc
71-
}
72-
wrap_ruby_bin() {
73-
local bin="$pkg_prefix/bin/$pkg_name"
74-
local real_bin="$GEM_HOME/gems/chef-cli-${pkg_version}/bin/chef-cli"
75-
build_line "Adding wrapper $bin to $real_bin"
76-
cat <<EOF > "$bin"
72+
ruby ./cleanup_gem_lockfiles.rb
73+
74+
build_line "** fixing binstub shebangs"
75+
fix_interpreter "${pkg_prefix}/vendor/bin/*" "$ruby_pkg" bin/ruby
76+
77+
build_line "** generating binstubs for chef-cli with precise version pins"
78+
"${pkg_prefix}/vendor/bin/appbundler" . "$pkg_prefix/bin" chef-cli
79+
80+
build_line "** patching binstubs to allow running directly"
81+
for binstub in ${pkg_prefix}/bin/*; do
82+
sed -i "/require \"rubygems\"/r ${PLAN_CONTEXT}/../binstub_patch.rb" "$binstub"
83+
done
84+
85+
build_line "** creating wrapper for runtime environment"
86+
mkdir -p "$pkg_prefix/libexec"
87+
mv "$pkg_prefix/bin/chef-cli" "$pkg_prefix/libexec/chef-cli"
88+
cat <<EOF > "$pkg_prefix/bin/chef-cli"
7789
#!$(pkg_path_for core/bash)/bin/bash
7890
set -e
7991
80-
# Set binary path that allows InSpec to use non-Hab pkg binaries
81-
# Include Ruby bin directory so chef-cli exec can find gem, etc.
8292
export PATH="$(pkg_path_for ${ruby_pkg})/bin:/sbin:/usr/sbin:/usr/local/sbin:/usr/local/bin:/usr/bin:/bin:$pkg_prefix/vendor/bin:\$PATH"
83-
84-
# Set library path for FFI-based gems (ffi-libarchive) to find native libraries
8593
export LD_LIBRARY_PATH="$(pkg_path_for core/libarchive)/lib:\$LD_LIBRARY_PATH"
94+
export GEM_HOME="$pkg_prefix/vendor"
95+
export GEM_PATH="$pkg_prefix/vendor"
8696
87-
# Set Ruby paths defined from 'do_setup_environment()'
88-
export GEM_HOME="$pkg_prefix/vendor"
89-
export GEM_PATH="$GEM_PATH"
90-
91-
exec $(pkg_path_for ${ruby_pkg})/bin/ruby $real_bin \$@
97+
exec $(pkg_path_for ${ruby_pkg})/bin/ruby $pkg_prefix/libexec/chef-cli "\$@"
9298
EOF
93-
chmod -v 755 "$bin"
99+
chmod -v 755 "$pkg_prefix/bin/chef-cli"
100+
101+
rm -rf $GEM_PATH/cache/
102+
rm -rf $GEM_PATH/bundler
103+
rm -rf $GEM_PATH/doc
94104
}
95105

106+
96107
do_after() {
97108
build_line "Removing .github directories from vendored gems..."
98109
find "$pkg_prefix/vendor/gems" -type d -name ".github" \
@@ -102,4 +113,11 @@ do_after() {
102113

103114
do_strip() {
104115
return 0
105-
}
116+
}
117+
118+
do_end() {
119+
if [[ "$(readlink /usr/bin/env)" = "$(pkg_interpreter_for core/coreutils bin/env)" ]]; then
120+
build_line "Removing the symlink we created for '/usr/bin/env'"
121+
rm /usr/bin/env
122+
fi
123+
}

0 commit comments

Comments
 (0)