From aa87212e9fc12e3ccd1257038fefb13c0df6a0a4 Mon Sep 17 00:00:00 2001 From: Miah Johnson Date: Mon, 16 Sep 2019 17:46:35 -0700 Subject: [PATCH] Basically cargo-copy https://github.com/chef/chef/blob/habiwindochef/habitat/plan.ps1 Thanks @robbkidd =) Signed-off-by: Miah Johnson --- habitat/plan.ps1 | 106 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 78 insertions(+), 28 deletions(-) diff --git a/habitat/plan.ps1 b/habitat/plan.ps1 index 2005f230a..263d0bfb9 100644 --- a/habitat/plan.ps1 +++ b/habitat/plan.ps1 @@ -1,48 +1,98 @@ $pkg_name="inspec" $pkg_origin="miah" $pkg_version=$(cat "$PLAN_CONTEXT/../VERSION") +$pkg_revision="1" $pkg_description="InSpec is an open-source testing framework for infrastructure with a human- and machine-readable language for specifying compliance, security and policy requirements." $pkg_upstream_url="https://www.inspec.io/" $pkg_maintainer="The Habitat Maintainers " $pkg_license=('Apache-2.0') + $pkg_deps=@( - "core/coreutils", - "core/cacerts", - "core/git", - "core/ruby", - "core/bash" -) -$pkg_build_deps=@( - "core/gcc", - "core/make", - "core/readline", - "core/sed" + "core/cacerts" + "robbkidd/ruby-plus-devkit/2.6.3" ) $pkg_bin_dirs=@("bin") +$project_root= (Resolve-Path "$PLAN_CONTEXT/../").Path -function Invoke-Unpack { - mkdir "$HAB_CACHE_SRC_PATH/$pkg_dirname" - Copy-Item "$PLAN_CONTEXT"/.. "$HAB_CACHE_SRC_PATH/$pkg_dirname/" -Recurse +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 -IsPath SSL_CERT_FILE "$(Get-HabPackagePath cacerts)/ssl/cert.pem" + Set-RuntimeEnv LANG "en_US.UTF-8" + Set-RuntimeEnv LC_CTYPE "en_US.UTF-8" } function Invoke-Build { - Push-Location "$HAB_CACHE_SRC_PATH/$pkg_dirname/" - gem build inspec.gemspec - Pop-Location - Push-Location "$HAB_CACHE_SRC_PATH/$pkg_dirname/inspec-bin" - gem build inspec-bin.gemspec - Pop-Location + try { + 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 + + Write-BuildLine " ** Using bundler to retrieve the Ruby dependencies" + bundle install + Write-BuildLine " ** Running the inspec project's 'rake install' to install the path-based gems so they look like any other installed gem." + bundle exec rake install # this needs to be 'bundle exec'd because a Rakefile makes reference to Bundler + Write-BuildLine " ** Also 'rake install' any gem sourced as a git reference." + foreach($git_gem in (Get-ChildItem "$env:GEM_HOME/bundler/gems")) { + try { + Push-Location $git_gem + Write-BuildLine " -- and $git_gem too" + rake install # this needs to NOT be 'bundle exec'd else bundler complains about dev deps not being installed + } finally { + Pop-Location + } + } + } finally { + Pop-Location + } } function Invoke-Install { - # MUST install inspec first because inspec-bin depends on it via gemspec - Push-Location "$HAB_CACHE_SRC_PATH/$pkg_dirname/" - gem install inspec-*.gem --no-document - Pop-Location + 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") - Push-Location "$HAB_CACHE_SRC_PATH/$pkg_dirname/inspec-bin" - gem install inspec-bin*.gem --no-document - Pop-Location -} \ No newline at end of file + try { + Push-Location $pkg_prefix + bundle config --local gemfile $project_root/Gemfile + foreach($gem in ("inspec-bin", "inspec")) { + Write-BuildLine "** generating binstubs for $gem with precise version pins" + Invoke-Expression -Command "appbundler.bat $project_root $pkg_prefix/bin $gem" + } + Remove-StudioPathFrom -File $pkg_prefix/vendor/gems/inspec-$pkg_version*/Gemfile + } finally { + Pop-Location + # forget about the build bundle config + Remove-Item $pkg_prefix/.bundle -Recurse -Force + } +} + +function Invoke-After { + # Trim the fat before packaging + + # We don't need the cache of downloaded .gem files ... + Remove-Item $pkg_prefix/vendor/cache -Recurse -Force + # ... or bundler's cache of git-ref'd gems + Remove-Item $pkg_prefix/vendor/bundler -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 "*inspec*" } ` + | Remove-Item -Recurse -Force +} +function Remove-StudioPathFrom { + Param( + [Parameter(Mandatory=$true)] + [String] + $File + ) + (Get-Content $File) -replace ($env:FS_ROOT -replace "\\","/"),"" | Set-Content $File +}