Skip to content

Commit 2b6eb94

Browse files
author
Sachin
committed
plan file for linux and window
Signed-off-by: Sachin <[email protected]>
1 parent b46fcdc commit 2b6eb94

File tree

4 files changed

+169
-1
lines changed

4 files changed

+169
-1
lines changed

Gemfile

+5
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
11
source "https://rubygems.org"
2+
23
gemspec
4+
5+
group :development do
6+
gem 'appbundler'
7+
end

fauxhai-chef.gemspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ Gem::Specification.new do |spec|
1919
spec.require_paths = ["lib"]
2020

2121
spec.add_runtime_dependency "net-ssh"
22+
spec.add_runtime_dependency "ohai", ">= 13.0"
2223

2324
spec.add_development_dependency "chef", ">= 13.0"
24-
spec.add_development_dependency "ohai", ">= 13.0"
2525
spec.add_development_dependency "rake"
2626
spec.add_development_dependency "rspec", "~> 3.7"
2727
spec.add_development_dependency "rspec-its", "~> 1.2"

habitat/plan.ps1

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
$ErrorActionPreference = "Stop"
2+
$PSDefaultParameterValues['*:ErrorAction']='Stop'
3+
4+
$pkg_name="fauxhai"
5+
$pkg_origin="core"
6+
$pkg_version="9.3.16"
7+
$pkg_revision="1"
8+
$pkg_maintainer="The Chef Maintainers <[email protected]>"
9+
10+
$pkg_deps=@(
11+
"chef/ruby31-plus-devkit"
12+
"core/git"
13+
)
14+
$pkg_bin_dirs=@("bin"
15+
"vendor/bin")
16+
$project_root= (Resolve-Path "$PLAN_CONTEXT/../").Path
17+
18+
function Invoke-SetupEnvironment {
19+
Push-RuntimeEnv -IsPath GEM_PATH "$pkg_prefix/vendor"
20+
21+
Set-RuntimeEnv APPBUNDLER_ALLOW_RVM "true" # prevent appbundler from clearing out the carefully constructed runtime GEM_PATH
22+
Set-RuntimeEnv FORCE_FFI_YAJL "ext"
23+
Set-RuntimeEnv LANG "en_US.UTF-8"
24+
Set-RuntimeEnv LC_CTYPE "en_US.UTF-8"
25+
}
26+
27+
function Invoke-Build {
28+
try {
29+
$env:Path += ";c:\\Program Files\\Git\\bin"
30+
Push-Location $project_root
31+
$env:GEM_HOME = "$HAB_CACHE_SRC_PATH/$pkg_dirname/vendor"
32+
33+
Write-BuildLine " ** Configuring bundler for this build environment"
34+
bundle config --local without integration deploy maintenance
35+
bundle config --local jobs 4
36+
bundle config --local retry 5
37+
bundle config --local silence_root_warning 1
38+
Write-BuildLine " ** Using bundler to retrieve the Ruby dependencies"
39+
bundle install
40+
41+
gem build fauxhai-chef.gemspec
42+
Write-BuildLine " ** Using gem to install"
43+
gem install fauxhai-chef-*.gem --no-document
44+
45+
46+
If ($lastexitcode -ne 0) { Exit $lastexitcode }
47+
} finally {
48+
Pop-Location
49+
}
50+
}
51+
52+
function Invoke-Install {
53+
Write-BuildLine "** Copy built & cached gems to install directory"
54+
Copy-Item -Path "$HAB_CACHE_SRC_PATH/$pkg_dirname/*" -Destination $pkg_prefix -Recurse -Force -Exclude @("gem_make.out", "mkmf.log", "Makefile",
55+
"*/latest", "latest",
56+
"*/JSON-Schema-Test-Suite", "JSON-Schema-Test-Suite")
57+
58+
try {
59+
Push-Location $pkg_prefix
60+
bundle config --local gemfile $project_root/Gemfile
61+
Write-BuildLine "** generating binstubs for fauxhai-chef with precise version pins"
62+
Write-BuildLine "** generating binstubs for fauxhai-chef with precise version pins $project_root $pkg_prefix/bin "
63+
Invoke-Expression -Command "appbundler.bat $project_root $pkg_prefix/bin fauxhai-chef"
64+
If ($lastexitcode -ne 0) { Exit $lastexitcode }
65+
Write-BuildLine " ** Running the fauxhai-chef project's 'rake install' to install the path-based gems so they look like any other installed gem."
66+
67+
If ($lastexitcode -ne 0) { Exit $lastexitcode }
68+
} finally {
69+
Pop-Location
70+
}
71+
}
72+
73+
function Invoke-After {
74+
# We don't need the cache of downloaded .gem files ...
75+
Remove-Item $pkg_prefix/vendor/cache -Recurse -Force
76+
# We don't need the gem docs.
77+
Remove-Item $pkg_prefix/vendor/doc -Recurse -Force
78+
# We don't need to ship the test suites for every gem dependency,
79+
# only inspec's for package verification.
80+
Get-ChildItem $pkg_prefix/vendor/gems -Filter "spec" -Directory -Recurse -Depth 1 `
81+
| Where-Object -FilterScript { $_.FullName -notlike "*fauxhai-chef*" } `
82+
| Remove-Item -Recurse -Force
83+
# Remove the byproducts of compiling gems with extensions
84+
Get-ChildItem $pkg_prefix/vendor/gems -Include @("gem_make.out", "mkmf.log", "Makefile") -File -Recurse `
85+
| Remove-Item -Force
86+
}

habitat/plan.sh

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
pkg_name=fauxhai
2+
pkg_origin=chef
3+
pkg_version="9.3.16"
4+
pkg_description="Easily mock full ohai data"
5+
pkg_license=('Apache-2.0')
6+
pkg_deps=(
7+
core/ruby31
8+
core/bash
9+
)
10+
pkg_build_deps=(
11+
core/gcc
12+
core/make
13+
)
14+
pkg_bin_dirs=(bin)
15+
16+
# Setup environment variables for Ruby Gems
17+
do_setup_environment() {
18+
build_line "Setting up GEM_HOME and GEM_PATH"
19+
export GEM_HOME="$pkg_prefix/lib"
20+
export GEM_PATH="$GEM_HOME"
21+
}
22+
23+
# Unpack the source files into the cache directory
24+
do_unpack() {
25+
local unpack_dir="$HAB_CACHE_SRC_PATH/$pkg_dirname"
26+
build_line "Creating unpack directory: $unpack_dir"
27+
mkdir -pv "$unpack_dir"
28+
cp -RT "$PLAN_CONTEXT"/.. "$unpack_dir/"
29+
}
30+
31+
# Build the gem from the gemspec file
32+
do_build() {
33+
build_line "Building the gem from the gemspec file"
34+
pushd "$HAB_CACHE_SRC_PATH/$pkg_dirname" > /dev/null
35+
gem build fauxhai-chef.gemspec
36+
popd > /dev/null
37+
}
38+
39+
# Install the built gem into the package directory
40+
do_install() {
41+
build_line "Installing the gem"
42+
pushd "$HAB_CACHE_SRC_PATH/$pkg_dirname" > /dev/null
43+
gem install fauxhai-*.gem --no-document
44+
popd > /dev/null
45+
46+
wrap_fauxhai_bin
47+
}
48+
49+
# Create a wrapper script to properly set paths and execute the fauxhai command
50+
wrap_fauxhai_bin() {
51+
local bin="$pkg_prefix/bin/$pkg_name"
52+
local real_bin="$GEM_HOME/gems/fauxhai-chef-${pkg_version}/bin/fauxhai"
53+
54+
build_line "Creating wrapper script: $bin"
55+
cat <<EOF > "$bin"
56+
#!$(pkg_path_for core/bash)/bin/bash
57+
set -e
58+
59+
# Set the PATH for Fauxhai to include necessary binaries
60+
export PATH="/sbin:/usr/sbin:/usr/local/sbin:/usr/local/bin:/usr/bin:/bin:\$PATH"
61+
62+
# Set Ruby paths defined from 'do_setup_environment()'
63+
export GEM_HOME="$GEM_HOME"
64+
export GEM_PATH="$GEM_PATH"
65+
66+
# Execute the Fauxhai binary
67+
exec $(pkg_path_for core/ruby31)/bin/ruby $real_bin "\$@"
68+
EOF
69+
70+
# Ensure the wrapper script is executable
71+
chmod -v 755 "$bin"
72+
}
73+
74+
# No additional stripping needed
75+
do_strip() {
76+
return 0
77+
}

0 commit comments

Comments
 (0)