diff options
author | Thom May <thom@may.lt> | 2018-05-14 18:46:41 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-05-14 18:46:41 +0100 |
commit | 938ec675bd3d97624b5b41c3476a07218e313219 (patch) | |
tree | c6f6d1115462f0c653dd5f7890279f7db75f2a75 | |
parent | 60c506446dc130b94a387853c04235b6fd3ad1d0 (diff) | |
parent | cf9fa5c5d903c8b81728d53281b3eef70913fd45 (diff) | |
download | chef-938ec675bd3d97624b5b41c3476a07218e313219.tar.gz |
Merge pull request #6111 from chef/elliott/update_hab_plan
Update Habitat plan to correctly build
-rw-r--r-- | .rubocop.yml | 1 | ||||
-rw-r--r-- | habitat/config/client.rb | 18 | ||||
-rw-r--r-- | habitat/default.toml | 37 | ||||
-rw-r--r-- | habitat/hooks/init | 5 | ||||
-rw-r--r-- | habitat/hooks/run | 8 | ||||
-rw-r--r-- | habitat/plan.sh | 83 |
6 files changed, 104 insertions, 48 deletions
diff --git a/.rubocop.yml b/.rubocop.yml index ec28184845..9730861155 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -4,6 +4,7 @@ AllCops: - "vendor/**/*" - "pkg/**/*" - "chef-config/pkg/**/*" + - "habitat/**/*" Security/Eval: Enabled: false Lint/UselessAssignment: diff --git a/habitat/config/client.rb b/habitat/config/client.rb new file mode 100644 index 0000000000..2d28d223c5 --- /dev/null +++ b/habitat/config/client.rb @@ -0,0 +1,18 @@ +chef_repo_path "{{pkg.svc_data_path}}/chef" +file_backup_path "{{pkg.svc_data_path}}/{{cfg.file_backup_path}}" +pid_file "{{pkg.svc_data_path}}/{{cfg.pid_file}}" +data_collector.server_url "{{cfg.data_collector.url}}" +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}} +{{#if cfg.chef-client.node_name ~}} +node_name "{{cfg.node_name}}" +{{/if ~}} +splay {{cfg.splay}} +interval {{cfg.interval}} +log_location {{cfg.log_location}} +log_level "{{cfg.log_level}}".to_sym +{{#if cfg.use_member_id_as_uuid ~}} +chef_guid "{{svc.me.member_id}}" +{{/if ~}} diff --git a/habitat/default.toml b/habitat/default.toml index 04385fc371..1422305835 100644 --- a/habitat/default.toml +++ b/habitat/default.toml @@ -1,11 +1,34 @@ -# The Chef run interval in seconds -interval = 10 +pid_file = "chef.pid" +run_list = "" -# The splay -splay = 10 +# The location in which nodes are stored when the chef-client is run in local mode + +log_location = "STDOUT" -# The default log level +# The level of logging to be stored in a log file log_level = "info" -# The default run list -run_list = "" +# A random number between zero and splay that is added to interval +splay = 10 + +# The frequency (in seconds) at which the chef-client runs +interval = 10 + +minimal_ohai = false + +# The name of the node. Determines which configuration should be applied and sets the client_name, +# which is the name used when authenticating to a Chef server. The default value is the FQDN of the chef-client, +#as detected by Ohai. In general, Chef recommends that you leave this setting blank and let Ohai +# assign the FQDN of the node as the node_name during each chef-clientrun. +node_name = "" + +#The name of the environment +environment = "_default" + +use_member_id_as_uuid = false + +[data_collector] +url="http://localhost/data-collector/v0/" +token="93a49a4f2482c64126f7b6015e6b0f30284287ee4054ff8807fb63d9cbd1c506" +raise_on_failure=false +mode="both" diff --git a/habitat/hooks/init b/habitat/hooks/init new file mode 100644 index 0000000000..a23344b2a9 --- /dev/null +++ b/habitat/hooks/init @@ -0,0 +1,5 @@ +#!/bin/sh + +exec 2>&1 + +mkdir -p "{{pkg.svc_data_path}}/chef" diff --git a/habitat/hooks/run b/habitat/hooks/run index 0f3844dd5f..75dd1958fa 100644 --- a/habitat/hooks/run +++ b/habitat/hooks/run @@ -1,8 +1,6 @@ #!/bin/sh -export GEM_HOME="{{pkg.path}}/ruby/2.3.0" -export GEM_PATH="$(hab pkg path core/ruby)/lib/ruby/gems/2.3.0:$(hab pkg path core/bundler):$GEM_HOME" -export APPBUNDLER_ALLOW_RVM=true - exec 2>&1 -exec chef-solo --fork -i {{cfg.interval}} -s {{cfg.splay}} -l {{cfg.log_level}} -o {{cfg.run_list}} +export SSL_CERT_FILE="{{pkgPathFor "core/cacerts"}}/ssl/cert.pem" + +exec chef-solo --fork -c {{pkg.svc_config_path}}/client.rb diff --git a/habitat/plan.sh b/habitat/plan.sh index 7a797842e2..26fcd5dad6 100644 --- a/habitat/plan.sh +++ b/habitat/plan.sh @@ -3,14 +3,18 @@ pkg_origin=chef pkg_maintainer="The Chef Maintainers <humans@chef.io>" pkg_description="The Chef Client" pkg_version=$(cat ../VERSION) -pkg_source=nosuchfile.tar.gz -pkg_filename=${pkg_dirname}.tar.gz pkg_license=('Apache-2.0') +pkg_filename=${pkg_dirname}.tar.gz pkg_bin_dirs=(bin) -pkg_build_deps=(core/make core/gcc core/coreutils 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) +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_svc_user=root +do_before() { + do_default_before + update_pkg_version +} + do_download() { build_line "Fake download! Creating archive of latest repository commit." # source is in this repo, so we're going to create an archive from the @@ -44,7 +48,7 @@ do_build() { local _libxslt_dir=$(pkg_path_for libxslt) local _zlib_dir=$(pkg_path_for zlib) - export GEM_HOME=${pkg_prefix} + 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" @@ -52,49 +56,56 @@ do_build() { bundle config --local silence_root_warning 1 - # We need to add tzinfo-data to the Gemfile since we're not in an - # environment that has this from the OS - if [[ -z "`grep 'gem .*tzinfo-data.*' Gemfile`" ]]; then - echo 'gem "tzinfo-data"' >> Gemfile - fi - - bundle install --no-deployment --jobs 2 --retry 5 --path $pkg_prefix - - bundle exec 'cd ./chef-config && rake package' - bundle exec 'rake package' - mkdir -p gems-suck/gems - cp pkg/chef-$pkg_version.gem gems-suck/gems - cp chef-config/pkg/chef-config-$pkg_version.gem gems-suck/gems - bundle exec gem generate_index -d gems-suck - - sed -e "s#gem \"chef\".*#gem \"chef\", source: \"file://$HAB_CACHE_SRC_PATH/$pkg_dirname/gems-suck\"#" -i Gemfile - sed -e "s#gem \"chef-config\".*#gem \"chef-config\", source: \"file://$HAB_CACHE_SRC_PATH/$pkg_dirname/gems-suck\"#" -i Gemfile - #bundle config --local local.chef $HAB_CACHE_SRC_PATH/$pkg_dirname/gems-suck - #bundle config --local local.chef-config $HAB_CACHE_SRC_PATH/$pkg_dirname/gems-suck - - bundle install --no-deployment --jobs 2 --retry 5 --path $pkg_prefix + pushd chef-config > /dev/null + _bundle_install "${pkg_prefix}/bundle" + popd > /dev/null + _bundle_install "${pkg_prefix}/bundle" } do_install() { - - mkdir -p $pkg_prefix/bin - - bundle exec appbundler $HAB_CACHE_SRC_PATH/$pkg_dirname $pkg_prefix/bin chef - bundle exec appbundler $HAB_CACHE_SRC_PATH/$pkg_dirname $pkg_prefix/bin ohai - - for binstub in ${pkg_prefix}/bin/*; do - build_line "Setting shebang for ${binstub} to 'ruby'" - [[ -f $binstub ]] && sed -e "s#/usr/bin/env ruby#$(pkg_path_for ruby)/bin/ruby#" -i $binstub + 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 + # 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 + + fix_interpreter "${pkg_prefix}/bin/*" core/coreutils bin/env + fix_interpreter "${pkg_prefix}/bin/*" core/ruby bin/ruby +} + +do_end() { if [[ `readlink /usr/bin/env` = "$(pkg_path_for coreutils)/bin/env" ]]; then build_line "Removing the symlink we created for '/usr/bin/env'" rm /usr/bin/env fi } -# Stubs 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 +} |