forked from berkshelf/berkshelf
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: nikhil2611 <[email protected]>
- Loading branch information
1 parent
656eb61
commit b13f5f9
Showing
2 changed files
with
164 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
$ErrorActionPreference = "Stop" | ||
$PSDefaultParameterValues['*:ErrorAction']='Stop' | ||
|
||
$pkg_name="berkshelf" | ||
$pkg_origin="ngupta26" | ||
$pkg_version=$(Get-Content "$PLAN_CONTEXT/../VERSION") | ||
$pkg_revision="1" | ||
$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 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 berkshelf.gemspec | ||
Write-BuildLine " ** Using gem to install" | ||
gem install berkshelf-*.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 berkshelf with precise version pins" | ||
Write-BuildLine "** generating binstubs for berkshelf with precise version pins $project_root $pkg_prefix/bin " | ||
Invoke-Expression -Command "appbundler.bat $project_root $pkg_prefix/bin berkshelf" | ||
If ($lastexitcode -ne 0) { Exit $lastexitcode } | ||
Write-BuildLine " ** Running the berkshelf 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 "*berkshelf*" } ` | ||
| 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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
pkg_name=berkshelf | ||
pkg_origin=ngupta26 | ||
pkg_version="8.0.15" | ||
pkg_description="Manage Chef Infra cookbooks and cookbook dependencies" | ||
pkg_license=('Apache-2.0') | ||
pkg_deps=( | ||
core/ruby31 | ||
core/bash | ||
) | ||
pkg_build_deps=( | ||
core/gcc | ||
core/make | ||
) | ||
pkg_bin_dirs=(bin) | ||
|
||
# Setup environment variables for Ruby Gems | ||
do_setup_environment() { | ||
build_line "Setting up GEM_HOME and GEM_PATH" | ||
export GEM_HOME="$pkg_prefix/lib" | ||
export GEM_PATH="$GEM_HOME" | ||
} | ||
|
||
# Unpack the source files into the cache directory | ||
do_unpack() { | ||
local unpack_dir="$HAB_CACHE_SRC_PATH/$pkg_dirname" | ||
build_line "Creating unpack directory: $unpack_dir" | ||
mkdir -pv "$unpack_dir" | ||
cp -RT "$PLAN_CONTEXT"/.. "$unpack_dir/" | ||
} | ||
|
||
# Build the gem from the gemspec file | ||
do_build() { | ||
build_line "Building the gem from the gemspec file" | ||
pushd "$HAB_CACHE_SRC_PATH/$pkg_dirname" > /dev/null | ||
gem build berkshelf.gemspec | ||
popd > /dev/null | ||
} | ||
|
||
# Install the built gem into the package directory | ||
do_install() { | ||
build_line "Installing the gem" | ||
pushd "$HAB_CACHE_SRC_PATH/$pkg_dirname" > /dev/null | ||
gem install berkshelf-*.gem --no-document | ||
popd > /dev/null | ||
|
||
wrap_berkshelf_bin | ||
} | ||
|
||
# Create a wrapper script to properly set paths and execute the berkshelf command | ||
wrap_berkshelf_bin() { | ||
local bin="$pkg_prefix/bin/berks" | ||
local real_bin="$GEM_HOME/gems/berkshelf-${pkg_version}/bin/berks" | ||
build_line "Adding wrapper $bin to $real_bin" | ||
|
||
# build_line "Creating wrapper script: $bin" | ||
cat <<EOF > "$bin" | ||
#!$(pkg_path_for core/bash)/bin/bash | ||
set -e | ||
# Set the PATH for berkshelf to include necessary 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" | ||
# Execute the berkshelf binary | ||
exec $(pkg_path_for core/ruby31)/bin/ruby $real_bin "\$@" | ||
EOF | ||
|
||
# Ensure the wrapper script is executable | ||
chmod -v 755 "$bin" | ||
} | ||
|
||
# No additional stripping needed | ||
do_strip() { | ||
return 0 | ||
} |