Skip to content

Commit

Permalink
Hab plan file for windows and linux to build hab pkg
Browse files Browse the repository at this point in the history
Signed-off-by: nitin sanghi <[email protected]>
  • Loading branch information
sanghinitin committed Sep 17, 2024
1 parent 38116d1 commit 1c66f14
Show file tree
Hide file tree
Showing 3 changed files with 156 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ gemspec
# pull these gems from main of chef/chef so that we're testing against what we will release
gem "chef-config", git: "https://github.com/chef/chef", branch: "main", glob: "chef-config/chef-config.gemspec"
gem "chef-utils", git: "https://github.com/chef/chef", branch: "main", glob: "chef-utils/chef-utils.gemspec"

gem "appbundler"
# NOTE: do not submit PRs to add pry as a dep, add to your Gemfile.local
group :development do
gem "cookstyle", ">= 7.32.8"
Expand Down
92 changes: 92 additions & 0 deletions habitat/plan.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
$ErrorActionPreference = "Stop"
$PSDefaultParameterValues['*:ErrorAction']='Stop'

$pkg_name="ohai"
$pkg_origin="chef"
$pkg_version=$(Get-Content "$PLAN_CONTEXT/../VERSION")
$pkg_maintainer="The Chef Maintainers <[email protected]>"

$pkg_deps=@(
"chef/ruby31-plus-devkit"
"core/git"
)
$pkg_bin_dirs=@("bin"
"vendor/bin")
$project_root= (Resolve-Path "$PLAN_CONTEXT/../").Path

function pkg_version {
Get-Content "$SRC_PATH/VERSION"
}

function Invoke-Before {
Set-PkgVersion
}
function Invoke-SetupEnvironment {
Push-RuntimeEnv -IsPath GEM_PATH "$pkg_prefix/vendor"

Set-RuntimeEnv APPBUNDLER_ALLOW_RVM "true" # prevent appbundler from clearing out the carefully constructed runtime GEM_PATH
Set-RuntimeEnv FORCE_FFI_YAJL "ext"
Set-RuntimeEnv LANG "en_US.UTF-8"
Set-RuntimeEnv LC_CTYPE "en_US.UTF-8"
}

function Invoke-Build {
try {
$env:Path += ";c:\\Program Files\\Git\\bin"
Push-Location $project_root
$env:GEM_HOME = "$HAB_CACHE_SRC_PATH/$pkg_dirname/vendor"

Write-BuildLine " ** Configuring bundler for this build environment"
bundle config --local without integration deploy maintenance
bundle config --local jobs 4
bundle config --local retry 5
bundle config --local silence_root_warning 1
Write-BuildLine " ** Using bundler to retrieve the Ruby dependencies"
bundle install

gem build ohai.gemspec
Write-BuildLine " ** Using gem to install"
gem install ohai-*.gem --no-document


If ($lastexitcode -ne 0) { Exit $lastexitcode }
} finally {
Pop-Location
}
}

function Invoke-Install {
Write-BuildLine "** Copy built & cached gems to install directory"
Copy-Item -Path "$HAB_CACHE_SRC_PATH/$pkg_dirname/*" -Destination $pkg_prefix -Recurse -Force -Exclude @("gem_make.out", "mkmf.log", "Makefile",
"*/latest", "latest",
"*/JSON-Schema-Test-Suite", "JSON-Schema-Test-Suite")

try {
Push-Location $pkg_prefix
bundle config --local gemfile $project_root/Gemfile
Write-BuildLine "** generating binstubs for ohai with precise version pins"
Write-BuildLine "** generating binstubs for ohai with precise version pins $project_root $pkg_prefix/bin "
Invoke-Expression -Command "appbundler.bat $project_root $pkg_prefix/bin ohai"
If ($lastexitcode -ne 0) { Exit $lastexitcode }
Write-BuildLine " ** Running the ohai project's 'rake install' to install the path-based gems so they look like any other installed gem."

If ($lastexitcode -ne 0) { Exit $lastexitcode }
} finally {
Pop-Location
}
}

function Invoke-After {
# We don't need the cache of downloaded .gem files ...
Remove-Item $pkg_prefix/vendor/cache -Recurse -Force
# We don't need the gem docs.
Remove-Item $pkg_prefix/vendor/doc -Recurse -Force
# We don't need to ship the test suites for every gem dependency,
# only inspec's for package verification.
Get-ChildItem $pkg_prefix/vendor/gems -Filter "spec" -Directory -Recurse -Depth 1 `
| Where-Object -FilterScript { $_.FullName -notlike "*ohai*" } `
| Remove-Item -Recurse -Force
# 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
}
63 changes: 63 additions & 0 deletions habitat/plan.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
pkg_name=ohai
pkg_origin=chef
ruby_pkg="core/ruby31"
pkg_deps=(${ruby_pkg} core/coreutils)
pkg_build_deps=(
core/make
core/sed
core/gcc
)
pkg_bin_dirs=(bin)
do_setup_environment() {
build_line 'Setting GEM_HOME="$pkg_prefix/lib"'
export GEM_HOME="$pkg_prefix/lib"

build_line "Setting GEM_PATH=$GEM_HOME"
export GEM_PATH="$GEM_HOME"
}

pkg_version() {
cat "$SRC_PATH/VERSION"
}
do_before() {
update_pkg_version
}
do_unpack() {
mkdir -pv "$HAB_CACHE_SRC_PATH/$pkg_dirname"
cp -RT "$PLAN_CONTEXT"/.. "$HAB_CACHE_SRC_PATH/$pkg_dirname/"
}
do_build() {
pushd "$HAB_CACHE_SRC_PATH/$pkg_dirname/"
gem build ohai.gemspec
popd
}
do_install() {
pushd "$HAB_CACHE_SRC_PATH/$pkg_dirname/"
gem install ohai-*.gem --no-document
popd
wrap_ruby_bin
}
wrap_ruby_bin() {
local bin="$pkg_prefix/bin/$pkg_name"
local real_bin="$GEM_HOME/gems/ohai-${pkg_version}/bin/ohai"
build_line "Adding wrapper $bin to $real_bin"
cat <<EOF > "$bin"
#!$(pkg_path_for core/bash)/bin/bash
set -e
# Set binary path that allows ohai to use non-Hab pkg binaries
export PATH="/sbin:/usr/sbin:/usr/local/sbin:/usr/local/bin:/usr/bin:/bin:\$PATH"
# Set Ruby paths defined from 'do_setup_environment()'
export GEM_HOME="$GEM_HOME"
export GEM_PATH="$GEM_PATH"
exec $(pkg_path_for core/ruby31)/bin/ruby $real_bin \$@
EOF
chmod -v 755 "$bin"
}


do_strip() {
return 0
}

0 comments on commit 1c66f14

Please sign in to comment.