Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 3 additions & 19 deletions .expeditor/buildkite/artifact.habitat.test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ $env:HAB_BLDR_CHANNEL = "base-2025"
$env:HAB_REFRESH_CHANNEL = "base-2025"
$env:CHEF_LICENSE = 'accept-no-persist'
$env:HAB_LICENSE = 'accept-no-persist'
$HabitatVersion = if ($env:HAB_VERSION) { $env:HAB_VERSION } else { '1.6.1245' }
$Plan = 'chef-cli'

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

# Installing Habitat
function Install-Habitat {
param(
[Parameter(Mandatory = $true)]
[string]$Version
)
Write-Host "Downloading and installing Habitat version $Version..."
$installScriptUrl = 'https://raw.githubusercontent.com/habitat-sh/habitat/main/components/hab/install.ps1'
$installScriptPath = Join-Path $env:TEMP "hab-install-$Version.ps1"
Invoke-WebRequest -Uri $installScriptUrl -OutFile $installScriptPath
try {
& $installScriptPath -Version $Version
}
finally {
Remove-Item $installScriptPath -Force -ErrorAction SilentlyContinue
}
Write-Host "Downloading and installing Habitat..."
Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://raw.githubusercontent.com/habitat-sh/habitat/main/components/hab/install.ps1'))
}

try {
Expand All @@ -64,7 +51,7 @@ catch {
}
}

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

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

Expand Down
8 changes: 8 additions & 0 deletions binstub_patch.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
unless ENV["APPBUNDLER_ALLOW_RVM"]
ENV["APPBUNDLER_ALLOW_RVM"] = "true"
bin_path = __dir__
vendor_path = File.expand_path(File.join(bin_path, "..", "vendor"))
ENV["GEM_HOME"] = vendor_path
ENV["GEM_PATH"] = [vendor_path, ENV["GEM_PATH"]].compact.join(File::PATH_SEPARATOR)
ENV["PATH"] = [bin_path, File.join(vendor_path, "bin"), RbConfig::CONFIG["bindir"], ENV["PATH"]].compact.join(File::PATH_SEPARATOR)
end
2 changes: 1 addition & 1 deletion chef-cli.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Gem::Specification.new do |gem|
gem.add_dependency "minitar", "~> 1.0"
gem.add_dependency "chef", ">= 18.0", "< 20.0"
gem.add_dependency "solve", "> 2.0", "< 5.0"
gem.add_dependency "addressable", ">= 2.3.5", "< 2.9"
gem.add_dependency "addressable", ">= 2.9.0", "< 3.0"
gem.add_dependency "cookbook-omnifetch", "~> 0.5"
gem.add_dependency "diff-lcs", "~> 1.6" # Newer verions of chef-client require diff-lcs ~> 1.6
gem.add_dependency "pastel", "~> 0.7" # used for policyfile differ
Expand Down
2 changes: 1 addition & 1 deletion cleanup_lint_roller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require "rubygems"

# List of gems that ship with Gemfile.lock files that should be removed
GEMS_WITH_LOCKFILES = %w{lint_roller stackprof-webnav}.freeze
GEMS_WITH_LOCKFILES = %w{lint_roller stackprof-webnav chef-cli}.freeze

def cleanup_gem_lockfile(gem_name)
puts "Cleaning up #{gem_name} Gemfile.lock..."
Expand Down
3 changes: 3 additions & 0 deletions habitat/plan.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,7 @@ function Invoke-After {
# Remove the byproducts of compiling gems with extensions
Get-ChildItem $pkg_prefix/vendor/gems -Include @("gem_make.out", "mkmf.log", "Makefile") -File -Recurse `
| Remove-Item -Force
# Remove .github directories from vendored gems to avoid CVE false positives
Get-ChildItem $pkg_prefix/vendor/gems -Filter ".github" -Directory -Recurse `
| Remove-Item -Recurse -Force
}
65 changes: 42 additions & 23 deletions habitat/plan.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pkg_build_deps=(
core/make
core/sed
core/gcc
core/git
core/git
)
pkg_bin_dirs=(bin)

Expand Down Expand Up @@ -63,36 +63,55 @@ do_install() {
build_line "Setting GEM_PATH=$GEM_HOME"
export GEM_PATH="$GEM_HOME"
gem install chef-cli-*.gem --no-document
set_runtime_env "GEM_PATH" "${pkg_prefix}/vendor"
wrap_ruby_bin
rm -rf $GEM_PATH/cache/
rm -rf $GEM_PATH/bundler
rm -rf $GEM_PATH/doc
}
wrap_ruby_bin() {
local bin="$pkg_prefix/bin/$pkg_name"
local real_bin="$GEM_HOME/gems/chef-cli-${pkg_version}/bin/chef-cli"
build_line "Adding wrapper $bin to $real_bin"
cat <<EOF > "$bin"
ruby ./cleanup_lint_roller.rb

build_line "** generating binstubs for chef-cli with precise version pins"
"$(pkg_path_for $ruby_pkg)/bin/ruby" "${pkg_prefix}/vendor/bin/appbundler" . "$pkg_prefix/bin" chef-cli

build_line "** generating binstub_patch.rb"
cat > binstub_patch.rb <<'PATCH'
unless ENV["APPBUNDLER_ALLOW_RVM"]
ENV["APPBUNDLER_ALLOW_RVM"] = "true"
bin_path = __dir__
vendor_path = File.expand_path(File.join(bin_path, "..", "vendor"))
ENV["GEM_HOME"] = vendor_path
ENV["GEM_PATH"] = [vendor_path, ENV["GEM_PATH"]].compact.join(File::PATH_SEPARATOR)
ENV["PATH"] = [bin_path, File.join(vendor_path, "bin"), RbConfig::CONFIG["bindir"], ENV["PATH"]].compact.join(File::PATH_SEPARATOR)
end
PATCH

build_line "** patching binstubs to allow running directly"
for binstub in ${pkg_prefix}/bin/*; do
sed -i "/require \"rubygems\"/r binstub_patch.rb" "$binstub"
done

fix_interpreter "${pkg_prefix}/bin/*" "$ruby_pkg" bin/ruby

build_line "** creating wrapper for runtime environment"
mkdir -p "$pkg_prefix/libexec"
mv "$pkg_prefix/bin/chef-cli" "$pkg_prefix/libexec/chef-cli"
cat <<EOF > "$pkg_prefix/bin/chef-cli"
#!$(pkg_path_for core/bash)/bin/bash
set -e

# Set binary path that allows InSpec to use non-Hab pkg binaries
# Include Ruby bin directory so chef-cli exec can find gem, etc.
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"

# Set library path for FFI-based gems (ffi-libarchive) to find native libraries
export LD_LIBRARY_PATH="$(pkg_path_for core/libarchive)/lib:\$LD_LIBRARY_PATH"
export GEM_HOME="$pkg_prefix/vendor"
export GEM_PATH="$pkg_prefix/vendor"

# Set Ruby paths defined from 'do_setup_environment()'
export GEM_HOME="$pkg_prefix/vendor"
export GEM_PATH="$GEM_PATH"

exec $(pkg_path_for ${ruby_pkg})/bin/ruby $real_bin \$@
exec $(pkg_path_for ${ruby_pkg})/bin/ruby $pkg_prefix/libexec/chef-cli "\$@"
EOF
chmod -v 755 "$bin"
}
chmod -v 755 "$pkg_prefix/bin/chef-cli"

rm -rf $GEM_PATH/cache/
rm -rf $GEM_PATH/bundler
rm -rf $GEM_PATH/doc
}
do_after() {
build_line "Removing .github directories from vendored gems..."
find "$pkg_prefix/vendor/gems" -type d -name ".github" \
| while read github_dir; do rm -rf "$github_dir"; done
}

do_strip() {
return 0
Expand Down
Loading