summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc A. Paradise <marcparadise@users.noreply.github.com>2022-09-07 12:46:52 +0000
committerGitHub <noreply@github.com>2022-09-07 12:46:52 +0000
commita58748f05b3aec827a5641123bcce11f193564c6 (patch)
treee373bb6d472ad455a6638bb8ddc2eb321e3efd22
parent93bd0ebbfb702f097285bcbf7dd70dfeb47f6468 (diff)
parentd3c6fae66293a8b24c43389a46c08951dbc6c70f (diff)
downloadchef-a58748f05b3aec827a5641123bcce11f193564c6.tar.gz
Merge pull request #13138 from chef/chef-14-habitat
update habitat plans to package chef 14
-rw-r--r--habitat/config/client.rb1
-rw-r--r--habitat/default.toml8
-rw-r--r--habitat/hooks/run12
-rw-r--r--habitat/plan.ps1137
-rw-r--r--habitat/plan.sh166
5 files changed, 255 insertions, 69 deletions
diff --git a/habitat/config/client.rb b/habitat/config/client.rb
index 2d28d223c5..b8a27f9d95 100644
--- a/habitat/config/client.rb
+++ b/habitat/config/client.rb
@@ -6,6 +6,7 @@ data_collector.token "{{cfg.data_collector.token}}"
data_collector.mode "{{cfg.data_collector.mode}}".to_sym
data_collector.raise_on_failure {{cfg.data_collector.raise_on_failure}}
minimal_ohai {{cfg.minimal_ohai}}
+local_mode "{{cfg.local_mode}}"
{{#if cfg.chef-client.node_name ~}}
node_name "{{cfg.node_name}}"
{{/if ~}}
diff --git a/habitat/default.toml b/habitat/default.toml
index 1422305835..1e5d605e1d 100644
--- a/habitat/default.toml
+++ b/habitat/default.toml
@@ -1,6 +1,14 @@
pid_file = "chef.pid"
run_list = ""
+local_mode = true
+
+# Positive License Acceptance. See https://docs.chef.io/chef_license_accept/
+chef_license = "donotaccept"
+
+# Path to the chef client config on disk. If blank, will default to the one built by habitat.
+config_path = ""
+
# The location in which nodes are stored when the chef-client is run in local mode
log_location = "STDOUT"
diff --git a/habitat/hooks/run b/habitat/hooks/run
index 75dd1958fa..598d609d7f 100644
--- a/habitat/hooks/run
+++ b/habitat/hooks/run
@@ -3,4 +3,14 @@ exec 2>&1
export SSL_CERT_FILE="{{pkgPathFor "core/cacerts"}}/ssl/cert.pem"
-exec chef-solo --fork -c {{pkg.svc_config_path}}/client.rb
+if [[ -z "{{cfg.config_path}}" ]]; then
+ CLIENT_CONFIG="{{pkg.svc_config_path}}"
+else
+ CLIENT_CONFIG="{{cfg.config_path}}"
+fi
+
+if [[ "${CLIENT_CONFIG##*.}" != "rb" ]]; then
+ CLIENT_CONFIG=${CLIENT_CONFIG}/client.rb
+fi
+
+exec chef-client --fork -c ${CLIENT_CONFIG} --chef-license {{cfg.chef_license}}
diff --git a/habitat/plan.ps1 b/habitat/plan.ps1
new file mode 100644
index 0000000000..f32af6797d
--- /dev/null
+++ b/habitat/plan.ps1
@@ -0,0 +1,137 @@
+$pkg_name="chef-infra-client"
+$pkg_origin="chef"
+$pkg_version=(Get-Content $PLAN_CONTEXT/../VERSION)
+$pkg_description="Chef Infra Client is an agent that runs locally on every node that is under management by Chef Infra. This package is binary-only to provide Chef Infra Client executables. It does not define a service to run."
+$pkg_maintainer="The Chef Maintainers <maintainers@chef.io>"
+$pkg_upstream_url="https://github.com/chef/chef"
+$pkg_license=@("Apache-2.0")
+$pkg_filename="${pkg_name}-${pkg_version}.zip"
+$pkg_bin_dirs=@(
+ "bin"
+ "vendor/bin"
+)
+$pkg_deps=@(
+ "core/cacerts"
+ "chef/ruby25-plus-devkit"
+)
+$pkg_build_deps=@("core/git")
+
+function Invoke-Begin {
+ [Version]$hab_version = (hab --version).split(" ")[1].split("/")[0]
+ if ($hab_version -lt [Version]"0.85.0" ) {
+ Write-Warning "(╯°□°)╯︵ ┻━┻ I CAN'T WORK UNDER THESE CONDITIONS!"
+ Write-Warning ":habicat: I'm being built with $hab_version. I need at least Hab 0.85.0, because I use the -IsPath option for setting/pushing paths in SetupEnvironment."
+ throw "unable to build: required minimum version of Habitat not installed"
+ } else {
+ Write-BuildLine ":habicat: I think I have the version I need to build."
+ }
+}
+
+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" # Always use the C-extensions because we use MRI on all the things and C is fast.
+ 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-Download() {
+ Write-BuildLine " ** Locally creating archive of latest repository commit at ${HAB_CACHE_SRC_PATH}/${pkg_filename}"
+ # source is in this repo, so we're going to create an archive from the
+ # appropriate path within the repo and place the generated tarball in the
+ # location expected by do_unpack
+ try {
+ Push-Location (Resolve-Path "$PLAN_CONTEXT/../").Path
+ git archive --format=zip --output="${HAB_CACHE_SRC_PATH}/${pkg_filename}" HEAD
+ } finally {
+ Pop-Location
+ }
+}
+
+function Invoke-Verify() {
+ Write-BuildLine " ** Skipping checksum verification on the archive we just created."
+ return 0
+}
+
+function Invoke-Prepare {
+ $env:GEM_HOME = "$pkg_prefix/vendor"
+ gem install bundler --version 1.16.6 --no-document --force
+
+ try {
+ Push-Location "${HAB_CACHE_SRC_PATH}/${pkg_dirname}"
+
+ Write-BuildLine " ** Configuring bundler for this build environment"
+ bundle config --local without server docgen maintenance pry travis integration ci chefstyle
+ bundle config --local jobs 4
+ bundle config --local retry 5
+ bundle config --local silence_root_warning 1
+ } finally {
+ Pop-Location
+ }
+}
+
+function Invoke-Build {
+ try {
+ Push-Location "${HAB_CACHE_SRC_PATH}/${pkg_dirname}"
+
+ $env:_BUNDER_WINDOWS_DLLS_COPIED = "1"
+
+ Write-BuildLine " ** Using bundler to retrieve the Ruby dependencies"
+ bundle install --jobs=3 --retry=3
+ if (-not $?) { throw "unable to install gem dependencies" }
+ Write-BuildLine " ** Running the chef 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
+ if (-not $?) {
+ Write-Warning " -- That didn't work. Let's try again."
+ bundle exec rake install # this needs to be 'bundle exec'd because a Rakefile makes reference to Bundler
+ if (-not $?) { throw "unable to install the gems that live in directories within this repo" }
+ }
+ } finally {
+ Pop-Location
+ }
+}
+
+function Invoke-Install {
+ try {
+ Push-Location $pkg_prefix
+ $env:BUNDLE_GEMFILE="${HAB_CACHE_SRC_PATH}/${pkg_dirname}/Gemfile"
+
+ foreach($gem in ("chef", "ohai")) {
+ Write-BuildLine "** generating binstubs for $gem with precise version pins"
+ appbundler.bat "${HAB_CACHE_SRC_PATH}/${pkg_dirname}" $pkg_prefix/bin $gem
+ if (-not $?) { throw "Failed to create appbundled binstubs for $gem"}
+ }
+ Remove-StudioPathFrom -File $pkg_prefix/vendor/gems/chef-$pkg_version*/Gemfile
+ } finally {
+ Pop-Location
+ }
+}
+
+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
+
+ # 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 Chef's for package verification.
+ Get-ChildItem $pkg_prefix/vendor/gems -Filter "spec" -Directory -Recurse -Depth 1 `
+ | Where-Object -FilterScript { $_.FullName -notlike "*chef-$pkg_version*" } `
+ | 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
+}
+
+function Remove-StudioPathFrom {
+ Param(
+ [Parameter(Mandatory=$true)]
+ [String]
+ $File
+ )
+ (Get-Content $File) -replace ($env:FS_ROOT -replace "\\","/"),"" | Set-Content $File
+} \ No newline at end of file
diff --git a/habitat/plan.sh b/habitat/plan.sh
index 26fcd5dad6..f893c13ebf 100644
--- a/habitat/plan.sh
+++ b/habitat/plan.sh
@@ -1,27 +1,53 @@
-pkg_name=chef-client
-pkg_origin=chef
+_chef_client_ruby="core/ruby25"
+pkg_name="chef-infra-client"
+pkg_origin="chef"
pkg_maintainer="The Chef Maintainers <humans@chef.io>"
-pkg_description="The Chef Client"
-pkg_version=$(cat ../VERSION)
+pkg_description="The Chef Infra Client"
pkg_license=('Apache-2.0')
-pkg_filename=${pkg_dirname}.tar.gz
-pkg_bin_dirs=(bin)
-pkg_build_deps=(core/make core/gcc core/git)
-pkg_deps=(core/glibc core/ruby core/libxml2 core/libxslt core/libiconv core/xz core/zlib core/bundler core/openssl core/cacerts core/libffi core/coreutils core/libarchive)
+pkg_bin_dirs=(
+ bin
+ vendor/bin
+)
+pkg_build_deps=(
+ core/make
+ core/gcc
+ core/git
+)
+pkg_deps=(
+ core/glibc
+ $_chef_client_ruby
+ core/libxml2
+ core/libxslt
+ core/libiconv
+ core/xz
+ core/zlib
+ core/openssl
+ core/cacerts
+ core/libffi
+ core/coreutils
+ core/libarchive
+)
pkg_svc_user=root
+pkg_version() {
+ cat "${SRC_PATH}/VERSION"
+}
+
do_before() {
do_default_before
update_pkg_version
+ # We must wait until we update the pkg_version to use the pkg_version
+ pkg_filename="${pkg_name}-${pkg_version}.tar.gz"
}
do_download() {
- build_line "Fake download! Creating archive of latest repository commit."
+ build_line "Locally creating archive of latest repository commit at ${HAB_CACHE_SRC_PATH}/${pkg_filename}"
# source is in this repo, so we're going to create an archive from the
# appropriate path within the repo and place the generated tarball in the
# location expected by do_unpack
- cd $PLAN_CONTEXT/../
- git archive --prefix=${pkg_name}-${pkg_version}/ --output=$HAB_CACHE_SRC_PATH/${pkg_filename} HEAD
+ ( cd "${SRC_PATH}" || exit_with "unable to enter hab-src directory" 1
+ git archive --prefix="${pkg_name}-${pkg_version}/" --output="${HAB_CACHE_SRC_PATH}/${pkg_filename}" HEAD
+ )
}
do_verify() {
@@ -29,62 +55,82 @@ do_verify() {
return 0
}
-do_prepare() {
- export OPENSSL_LIB_DIR=$(pkg_path_for openssl)/lib
- export OPENSSL_INCLUDE_DIR=$(pkg_path_for openssl)/include
- export SSL_CERT_FILE=$(pkg_path_for cacerts)/ssl/cert.pem
-
- build_line "Setting link for /usr/bin/env to 'coreutils'"
- [[ ! -f /usr/bin/env ]] && ln -s $(pkg_path_for coreutils)/bin/env /usr/bin/env
+do_setup_environment() {
+ push_runtime_env GEM_PATH "${pkg_prefix}/vendor"
- return 0
+ set_runtime_env APPBUNDLER_ALLOW_RVM "true" # prevent appbundler from clearing out the carefully constructed runtime GEM_PATH
+ set_runtime_env SSL_CERT_FILE "$(pkg_path_for cacerts)/ssl/cert.pem"
+ set_runtime_env LANG "en_US.UTF-8"
+ set_runtime_env LC_CTYPE "en_US.UTF-8"
}
-do_build() {
+do_prepare() {
+ export GEM_HOME="${pkg_prefix}/vendor"
+ export OPENSSL_LIB_DIR="$(pkg_path_for openssl)/lib"
+ export OPENSSL_INCLUDE_DIR="$(pkg_path_for openssl)/include"
+ export SSL_CERT_FILE="$(pkg_path_for cacerts)/ssl/cert.pem"
export CPPFLAGS="${CPPFLAGS} ${CFLAGS}"
- local _bundler_dir=$(pkg_path_for bundler)
- local _libxml2_dir=$(pkg_path_for libxml2)
- local _libxslt_dir=$(pkg_path_for libxslt)
- local _zlib_dir=$(pkg_path_for zlib)
-
- export GEM_HOME=${pkg_prefix}/bundle
- export GEM_PATH=${_bundler_dir}:${GEM_HOME}
-
- export NOKOGIRI_CONFIG="--use-system-libraries --with-zlib-dir=${_zlib_dir} --with-xslt-dir=${_libxslt_dir} --with-xml2-include=${_libxml2_dir}/include/libxml2 --with-xml2-lib=${_libxml2_dir}/lib"
- bundle config --local build.nokogiri '${NOKOGIRI_CONFIG}'
+ ( cd "$CACHE_PATH"
+ bundle config --local build.nokogiri "--use-system-libraries \
+ --with-zlib-dir=$(pkg_path_for zlib) \
+ --with-xslt-dir=$(pkg_path_for libxslt) \
+ --with-xml2-include=$(pkg_path_for libxml2)/include/libxml2 \
+ --with-xml2-lib=$(pkg_path_for libxml2)/lib"
+ bundle config --local jobs "$(nproc)"
+ bundle config --local without server docgen maintenance pry travis integration ci chefstyle
+ bundle config --local shebang "$(pkg_path_for "$_chef_client_ruby")/bin/ruby"
+ bundle config --local retry 5
+ bundle config --local silence_root_warning 1
+ )
- bundle config --local silence_root_warning 1
-
- pushd chef-config > /dev/null
- _bundle_install "${pkg_prefix}/bundle"
- popd > /dev/null
+ build_line "Setting link for /usr/bin/env to 'coreutils'"
+ if [ ! -f /usr/bin/env ]; then
+ ln -s "$(pkg_interpreter_for core/coreutils bin/env)" /usr/bin/env
+ fi
+}
- _bundle_install "${pkg_prefix}/bundle"
+do_build() {
+ ( cd "$CACHE_PATH" || exit_with "unable to enter hab-cache directory" 1
+ build_line "Installing gem dependencies ..."
+ bundle install --jobs=3 --retry=3
+ build_line "Installing this project's gems ..."
+ bundle exec rake install
+ )
}
do_install() {
- mkdir -p "${pkg_prefix}/chef"
- for dir in bin chef-config lib chef.gemspec Gemfile Gemfile.lock; do
- cp -rv "${PLAN_CONTEXT}/../${dir}" "${pkg_prefix}/chef/"
- done
+ ( cd "$pkg_prefix" || exit_with "unable to enter pkg prefix directory" 1
+ export BUNDLE_GEMFILE="${CACHE_PATH}/Gemfile"
+ build_line "** fixing binstub shebangs"
+ fix_interpreter "${pkg_prefix}/vendor/bin/*" "$_chef_client_ruby" bin/ruby
+ export BUNDLE_GEMFILE="${CACHE_PATH}/Gemfile"
+ for gem in chef ohai; do
+ build_line "** generating binstubs for $gem with precise version pins"
+ appbundler $CACHE_PATH $pkg_prefix/bin $gem
+ done
+ )
+}
- # This is just generating binstubs with the correct path.
- # If we generated them on install, bundler thinks our source is in $HAB_CACHE_SOURCE_PATH
- pushd "$pkg_prefix/chef" > /dev/null
- _bundle_install \
- "${pkg_prefix}/bundle" \
- --local \
- --quiet \
- --binstubs "${pkg_prefix}/bin"
- popd > /dev/null
+do_after() {
+ build_line "Trimming the fat ..."
- fix_interpreter "${pkg_prefix}/bin/*" core/coreutils bin/env
- fix_interpreter "${pkg_prefix}/bin/*" core/ruby bin/ruby
+ # We don't need the cache of downloaded .gem files ...
+ rm -r "$pkg_prefix/vendor/cache"
+ # ... or bundler's cache of git-ref'd gems
+ if [ -f "$pkg_prefix/vendor/bundler" ]; then
+ rm -r "$pkg_prefix/vendor/bundler"
+ fi
+ # We don't need the gem docs.
+ rm -r "$pkg_prefix/vendor/doc"
+ # We don't need to ship the test suites for every gem dependency,
+ # only Chef's for package verification.
+ find "$pkg_prefix/vendor/gems" -name spec -type d | grep -v "chef-${pkg_version}" \
+ | while read spec_dir; do rm -r "$spec_dir"; done
}
do_end() {
- if [[ `readlink /usr/bin/env` = "$(pkg_path_for coreutils)/bin/env" ]]; then
+ if [ "$(readlink /usr/bin/env)" = "$(pkg_interpreter_for core/coreutils bin/env)" ]; then
build_line "Removing the symlink we created for '/usr/bin/env'"
rm /usr/bin/env
fi
@@ -93,19 +139,3 @@ do_end() {
do_strip() {
return 0
}
-
-# Helper function to wrap up some repetitive bundle install flags
-_bundle_install() {
- local path
- path="$1"
- shift
-
- bundle install ${*:-} \
- --jobs "$(nproc)" \
- --without development:test \
- --path "$path" \
- --shebang="$(pkg_path_for "core/ruby")/bin/ruby" \
- --no-clean \
- --retry 5 \
- --standalone
-}