|
1 | | -pkg_name=chef-cli |
2 | | -pkg_origin=chef |
3 | | -ruby_pkg="core/ruby31" |
4 | | -pkg_deps=(${ruby_pkg} core/coreutils) |
| 1 | +_chef_client_ruby="core/ruby31" |
| 2 | +pkg_name="chef-cli" |
| 3 | +pkg_origin="chef" |
| 4 | +pkg_maintainer="The Chef Maintainers <humans@chef.io>" |
| 5 | +pkg_description="The Chef CLI" |
| 6 | +pkg_license=('Apache-2.0') |
| 7 | +pkg_bin_dirs=( |
| 8 | + bin |
| 9 | + vendor/bin |
| 10 | +) |
5 | 11 | pkg_build_deps=( |
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/lib"' |
14 | | - export GEM_HOME="$pkg_prefix/lib" |
15 | | - |
16 | | - build_line "Setting GEM_PATH=$GEM_HOME" |
17 | | - export GEM_PATH="$GEM_HOME" |
18 | | -} |
| 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 |
19 | 22 |
|
20 | 23 | pkg_version() { |
21 | | - cat "$SRC_PATH/VERSION" |
| 24 | + cat "${SRC_PATH}/VERSION" |
22 | 25 | } |
| 26 | + |
23 | 27 | do_before() { |
| 28 | + do_default_before |
24 | 29 | 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" |
| 32 | +} |
| 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 |
25 | 47 | } |
26 | | -do_unpack() { |
27 | | - mkdir -pv "$HAB_CACHE_SRC_PATH/$pkg_dirname" |
28 | | - cp -RT "$PLAN_CONTEXT"/.. "$HAB_CACHE_SRC_PATH/$pkg_dirname/" |
| 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" |
29 | 55 | } |
| 56 | + |
| 57 | +do_prepare() { |
| 58 | + export GEM_HOME="${pkg_prefix}/vendor" |
| 59 | + export CPPFLAGS="${CPPFLAGS} ${CFLAGS}" |
| 60 | + |
| 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" |
| 65 | + bundle config --local retry 5 |
| 66 | + 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 | + |
30 | 75 | do_build() { |
31 | | - pushd "$HAB_CACHE_SRC_PATH/$pkg_dirname/" |
32 | | - gem build chef-cli.gemspec |
33 | | - popd |
| 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 | + ) |
34 | 84 | } |
| 85 | + |
35 | 86 | do_install() { |
36 | | - pushd "$HAB_CACHE_SRC_PATH/$pkg_dirname/" |
37 | | - gem install chef-cli-*.gem --no-document |
38 | | - popd |
39 | | - wrap_ruby_bin |
| 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 | + ) |
40 | 97 | } |
41 | | -wrap_ruby_bin() { |
42 | | - local bin="$pkg_prefix/bin/$pkg_name" |
43 | | - local real_bin="$GEM_HOME/gems/chef-cli-${pkg_version}/bin/chef-cli" |
44 | | - build_line "Adding wrapper $bin to $real_bin" |
45 | | - cat <<EOF > "$bin" |
46 | | -#!$(pkg_path_for core/bash)/bin/bash |
47 | | -set -e |
48 | 98 |
|
49 | | -# Set binary path that allows InSpec to use non-Hab pkg binaries |
50 | | -export PATH="/sbin:/usr/sbin:/usr/local/sbin:/usr/local/bin:/usr/bin:/bin:\$PATH" |
| 99 | +do_after() { |
| 100 | + build_line "Trimming the fat ..." |
51 | 101 |
|
52 | | -# Set Ruby paths defined from 'do_setup_environment()' |
53 | | -export GEM_HOME="$GEM_HOME" |
54 | | -export GEM_PATH="$GEM_PATH" |
| 102 | + # We don't need the cache of downloaded .gem files ... |
| 103 | + rm -rf "$pkg_prefix/vendor/cache" |
55 | 104 |
|
56 | | -exec $(pkg_path_for core/ruby31)/bin/ruby $real_bin \$@ |
57 | | -EOF |
58 | | - chmod -v 755 "$bin" |
| 105 | + # We don't need the gem docs. |
| 106 | + rm -rf "$pkg_prefix/vendor/doc" |
| 107 | + # We don't need to ship the test suites for every gem dependency, |
| 108 | + # only Chef's for package verification. |
| 109 | + find "$pkg_prefix/vendor/gems" -name spec -type d | grep -v "chef-cli-${pkg_version}" \ |
| 110 | + | while read spec_dir; do rm -rf "$spec_dir"; done |
59 | 111 | } |
60 | 112 |
|
| 113 | +do_end() { |
| 114 | + if [ "$(readlink /usr/bin/env)" = "$(pkg_interpreter_for core/coreutils bin/env)" ]; then |
| 115 | + build_line "Removing the symlink we created for '/usr/bin/env'" |
| 116 | + rm /usr/bin/env |
| 117 | + fi |
| 118 | +} |
61 | 119 |
|
62 | 120 | do_strip() { |
63 | 121 | return 0 |
|
0 commit comments