2019-07-11 04:53:55 +00:00
|
|
|
$pkg_name="inspec"
|
2019-10-17 03:25:54 +00:00
|
|
|
$pkg_origin="chef"
|
|
|
|
$pkg_version=$(Get-Content "$PLAN_CONTEXT/../VERSION")
|
2019-09-17 00:46:35 +00:00
|
|
|
$pkg_revision="1"
|
2019-07-11 04:53:55 +00:00
|
|
|
$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/"
|
2019-10-17 03:25:54 +00:00
|
|
|
$pkg_maintainer="The Chef Maintainers <humans@chef.io>"
|
2019-07-11 04:53:55 +00:00
|
|
|
$pkg_license=('Apache-2.0')
|
2019-09-17 00:46:35 +00:00
|
|
|
|
2019-07-11 04:53:55 +00:00
|
|
|
$pkg_deps=@(
|
2019-09-17 00:46:35 +00:00
|
|
|
"core/cacerts"
|
2019-10-17 03:25:54 +00:00
|
|
|
"robbkidd/ruby-plus-devkit"
|
2019-07-11 04:53:55 +00:00
|
|
|
)
|
2019-09-17 23:52:31 +00:00
|
|
|
$pkg_bin_dirs=@("bin"
|
|
|
|
"vendor/bin")
|
2019-09-17 00:46:35 +00:00
|
|
|
$project_root= (Resolve-Path "$PLAN_CONTEXT/../").Path
|
|
|
|
|
|
|
|
function Invoke-SetupEnvironment {
|
|
|
|
Push-RuntimeEnv -IsPath GEM_PATH "$pkg_prefix/vendor"
|
2019-07-11 04:53:55 +00:00
|
|
|
|
2019-09-17 00:46:35 +00:00
|
|
|
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"
|
2019-07-11 04:53:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function Invoke-Build {
|
2019-09-17 00:46:35 +00:00
|
|
|
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
|
|
|
|
} finally {
|
|
|
|
Pop-Location
|
|
|
|
}
|
2019-07-11 04:53:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function Invoke-Install {
|
2019-09-17 00:46:35 +00:00
|
|
|
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")
|
|
|
|
|
|
|
|
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 {
|
|
|
|
# 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 "*inspec*" } `
|
|
|
|
| Remove-Item -Recurse -Force
|
|
|
|
}
|
2019-10-17 03:25:54 +00:00
|
|
|
|
2019-09-17 00:46:35 +00:00
|
|
|
function Remove-StudioPathFrom {
|
|
|
|
Param(
|
|
|
|
[Parameter(Mandatory=$true)]
|
|
|
|
[String]
|
|
|
|
$File
|
|
|
|
)
|
|
|
|
(Get-Content $File) -replace ($env:FS_ROOT -replace "\\","/"),"" | Set-Content $File
|
|
|
|
}
|