Skip to content

Commit fe50afb

Browse files
committed
Change chef-cli hab pkg origin
Signed-off-by: nitin sanghi <[email protected]>
1 parent 61d0572 commit fe50afb

File tree

3 files changed

+146
-103
lines changed

3 files changed

+146
-103
lines changed

habitat/plan.ps1

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

habitat/plan.sh

Lines changed: 53 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -1,123 +1,74 @@
1-
_chef_client_ruby="core/ruby31"
2-
pkg_name="chef-cli"
3-
pkg_origin="ngupta26"
4-
pkg_maintainer="The Chef Maintainers <[email protected]>"
5-
pkg_description="The Chef CLI"
6-
pkg_license=('Apache-2.0')
7-
pkg_bin_dirs=(
8-
bin
9-
vendor/bin
10-
)
1+
pkg_name=chef-cli
2+
pkg_origin=chef
3+
ruby_pkg="core/ruby3_1"
4+
pkg_deps=(${ruby_pkg} core/coreutils)
115
pkg_build_deps=(
12-
core/make
13-
core/gcc
14-
core/git
15-
core/libarchive
16-
)
17-
pkg_deps=(
18-
$_chef_client_ruby
19-
core/coreutils
20-
)
21-
pkg_svc_user=root
6+
core/make
7+
core/sed
8+
core/gcc
9+
core/libarchive
10+
)
11+
pkg_bin_dirs=(bin)
12+
do_setup_environment() {
13+
build_line 'Setting GEM_HOME="$pkg_prefix/vendor"'
14+
export GEM_HOME="$pkg_prefix/vendor"
2215

23-
pkg_version() {
24-
cat "${SRC_PATH}/VERSION"
16+
build_line "Setting GEM_PATH=$GEM_HOME"
17+
export GEM_PATH="$GEM_HOME"
2518
}
2619

20+
pkg_version() {
21+
cat "$SRC_PATH/VERSION"
22+
}
2723
do_before() {
28-
do_default_before
2924
update_pkg_version
30-
# We must wait until we update the pkg_version to use the pkg_version
31-
pkg_filename="${pkg_name}-${pkg_version}.tar.gz"
3225
}
33-
34-
do_download() {
35-
build_line "Locally creating archive of latest repository commit at ${HAB_CACHE_SRC_PATH}/${pkg_filename}"
36-
# source is in this repo, so we're going to create an archive from the
37-
# appropriate path within the repo and place the generated tarball in the
38-
# location expected by do_unpack
39-
( cd "${SRC_PATH}" || exit_with "unable to enter hab-src directory" 1
40-
git archive --prefix="${pkg_name}-${pkg_version}/" --output="${HAB_CACHE_SRC_PATH}/${pkg_filename}" HEAD
41-
)
42-
}
43-
44-
do_verify() {
45-
build_line "Skipping checksum verification on the archive we just created."
46-
return 0
47-
}
48-
49-
do_setup_environment() {
50-
push_runtime_env GEM_PATH "${pkg_prefix}/vendor"
51-
52-
set_runtime_env APPBUNDLER_ALLOW_RVM "true" # prevent appbundler from clearing out the carefully constructed runtime GEM_PATH
53-
set_runtime_env LANG "en_US.UTF-8"
54-
set_runtime_env LC_CTYPE "en_US.UTF-8"
26+
do_unpack() {
27+
mkdir -pv "$HAB_CACHE_SRC_PATH/$pkg_dirname"
28+
cp -RT "$PLAN_CONTEXT"/.. "$HAB_CACHE_SRC_PATH/$pkg_dirname/"
5529
}
30+
do_build() {
5631

57-
do_prepare() {
58-
export GEM_HOME="${pkg_prefix}/vendor"
59-
export CPPFLAGS="${CPPFLAGS} ${CFLAGS}"
32+
export GEM_HOME="$pkg_prefix/vendor"
6033

61-
( cd "$CACHE_PATH"
62-
bundle config --local jobs "$(nproc)"
63-
bundle config --local without server docgen maintenance pry travis integration ci chefstyle
64-
bundle config --local shebang "$(pkg_path_for "$_chef_client_ruby")/bin/ruby"
34+
build_line "Setting GEM_PATH=$GEM_HOME"
35+
export GEM_PATH="$GEM_HOME"
36+
bundle config --local without integration deploy maintenance
37+
bundle config --local jobs 4
6538
bundle config --local retry 5
6639
bundle config --local silence_root_warning 1
67-
)
68-
69-
build_line "Setting link for /usr/bin/env to 'coreutils'"
70-
if [ ! -f /usr/bin/env ]; then
71-
ln -s "$(pkg_interpreter_for core/coreutils bin/env)" /usr/bin/env
72-
fi
73-
}
74-
75-
do_build() {
76-
( cd "$CACHE_PATH" || exit_with "unable to enter hab-cache directory" 1
77-
build_line "Installing gem dependencies ..."
78-
bundle install --jobs=3 --retry=3
79-
build_line "Installing gems from git repos properly ..."
80-
build_line "Installing this project's gems ..."
81-
bundle exec rake install:local
82-
gem install chef-utils chef-config appbundler
83-
)
40+
bundle install
41+
gem build chef-cli.gemspec
8442
}
85-
8643
do_install() {
87-
( cd "$pkg_prefix" || exit_with "unable to enter pkg prefix directory" 1
88-
export BUNDLE_GEMFILE="${CACHE_PATH}/Gemfile"
89-
build_line "** fixing binstub shebangs"
90-
fix_interpreter "${pkg_prefix}/vendor/bin/*" "$_chef_client_ruby" bin/ruby
91-
export BUNDLE_GEMFILE="${CACHE_PATH}/Gemfile"
92-
for gem in chef-cli; do
93-
build_line "** generating binstubs for $gem with precise version pins"
94-
appbundler $CACHE_PATH $pkg_prefix/bin $gem
95-
done
96-
)
97-
sed -i '1s|^.*|#!'$(pkg_path_for $_chef_client_ruby)/bin/ruby'|' ${pkg_prefix}/vendor/bin/rspec
44+
export GEM_HOME="$pkg_prefix/vendor"
9845

46+
build_line "Setting GEM_PATH=$GEM_HOME"
47+
export GEM_PATH="$GEM_HOME"
48+
gem install chef-cli-*.gem --no-document
49+
set_runtime_env "GEM_PATH" "${pkg_prefix}/vendor"
50+
wrap_ruby_bin
9951
}
100-
101-
do_after() {
102-
build_line "Trimming the fat ..."
103-
104-
# We don't need the cache of downloaded .gem files ...
105-
rm -rf "$pkg_prefix/vendor/cache"
106-
107-
# We don't need the gem docs.
108-
rm -rf "$pkg_prefix/vendor/doc"
109-
# We don't need to ship the test suites for every gem dependency,
110-
# only Chef's for package verification.
111-
find "$pkg_prefix/vendor/gems" -name spec -type d | grep -v "chef-cli-${pkg_version}" \
112-
| while read spec_dir; do rm -rf "$spec_dir"; done
52+
wrap_ruby_bin() {
53+
local bin="$pkg_prefix/bin/$pkg_name"
54+
local real_bin="$GEM_HOME/gems/chef-cli-${pkg_version}/bin/chef-cli"
55+
build_line "Adding wrapper $bin to $real_bin"
56+
cat <<EOF > "$bin"
57+
#!$(pkg_path_for core/bash)/bin/bash
58+
set -e
59+
60+
# Set binary path that allows InSpec to use non-Hab pkg binaries
61+
export PATH="/sbin:/usr/sbin:/usr/local/sbin:/usr/local/bin:/usr/bin:/bin:\$PATH"
62+
63+
# Set Ruby paths defined from 'do_setup_environment()'
64+
export GEM_HOME="$pkg_prefix/vendor"
65+
export GEM_PATH="$GEM_PATH"
66+
67+
exec $(pkg_path_for core/ruby31)/bin/ruby $real_bin \$@
68+
EOF
69+
chmod -v 755 "$bin"
11370
}
11471

115-
do_end() {
116-
if [ "$(readlink /usr/bin/env)" = "$(pkg_interpreter_for core/coreutils bin/env)" ]; then
117-
build_line "Removing the symlink we created for '/usr/bin/env'"
118-
rm /usr/bin/env
119-
fi
120-
}
12172

12273
do_strip() {
12374
return 0

lib/chef-cli/helpers.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ def habitat_env
135135
end
136136

137137
def get_pkg_prefix
138-
pkg_origin = "ngupta26"
138+
pkg_origin = "chef"
139139
pkg_name = "#{pkg_origin}/chef-cli" # Your origin and package name
140140
path = `hab pkg path #{pkg_name}`.strip
141141

0 commit comments

Comments
 (0)