summaryrefslogtreecommitdiff
path: root/habitat
diff options
context:
space:
mode:
authorElliott Davis <edavis@chef.io>2017-05-01 16:48:42 -0500
committerThom May <thom@chef.io>2018-05-02 14:57:37 +0100
commitf60781bbfe16a23078c22dced4ed968fe4e26ec3 (patch)
tree596e7ab16e5c2eb2c017786c8a585c88976dff42 /habitat
parent21dcbdd200d69725845f75b6b8bebe1ec950e826 (diff)
downloadchef-f60781bbfe16a23078c22dced4ed968fe4e26ec3.tar.gz
Update Habitat plan to correctly build
* Add a few config new settings Signed-off-by: Elliott Davis <edavis@chef.io>
Diffstat (limited to 'habitat')
-rw-r--r--habitat/config/client.rb21
-rw-r--r--habitat/config/data_collector_metadata.json1
-rw-r--r--habitat/default.toml45
-rw-r--r--habitat/hooks/init11
-rw-r--r--habitat/hooks/run8
-rw-r--r--habitat/plan.sh75
6 files changed, 113 insertions, 48 deletions
diff --git a/habitat/config/client.rb b/habitat/config/client.rb
new file mode 100644
index 0000000000..1b1f512184
--- /dev/null
+++ b/habitat/config/client.rb
@@ -0,0 +1,21 @@
+cookbook_path "{{pkg.svc_data_path}}/{{cfg.cookbook_path}}"
+data_bag_path "{{pkg.svc_data_path}}/{{cfg.data_bag_path}}"
+environment_path "{{pkg.svc_data_path}}/{{cfg.environment_path}}"
+file_backup_path "{{pkg.svc_data_path}}/{{cfg.file_backup_path}}"
+node_path "{{pkg.svc_data_path}}/{{cfg.node_path}}"
+role_path "{{pkg.svc_data_path}}/{{cfg.role_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}}
+chef_repo_path "{{pkg.svc_data_path}}/chef"
+environment "{{cfg.environment}}"
+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
diff --git a/habitat/config/data_collector_metadata.json b/habitat/config/data_collector_metadata.json
new file mode 100644
index 0000000000..10a5f027d3
--- /dev/null
+++ b/habitat/config/data_collector_metadata.json
@@ -0,0 +1 @@
+{"node_uuid": "{{svc.me.member_id}}"}
diff --git a/habitat/default.toml b/habitat/default.toml
index 04385fc371..38b33210f9 100644
--- a/habitat/default.toml
+++ b/habitat/default.toml
@@ -1,11 +1,42 @@
-# The Chef run interval in seconds
-interval = 10
+cookbook_path = "chef/cookbooks"
+data_bag_bath = "chef/data_bags"
+environment_path = "chef/environments"
+file_backup_path = "chef/backup"
+file_cache_path = "chef/cache"
+node_path = "chef/node"
+role_path = "chef/roles"
-# The splay
-splay = 10
+pid_file = "chef.pid"
+run_list = ""
+
+# The location in which nodes are stored when the chef-client is run in local mode
-# The default log level
+log_location = "STDOUT"
+
+# 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..f615b11d85
--- /dev/null
+++ b/habitat/hooks/init
@@ -0,0 +1,11 @@
+#!/bin/sh
+
+exec 2>&1
+for path in {{cfg.cookbook_path}} {{cfg.data_bag_path}} {{cfg.environment_path}} {{cfg.file_backup_path}} {{cfg.file_cache_path}} {{cfg.node_path}} {{cfg.role_path}}; do
+ mkdir -p "{{pkg.svc_data_path}}/$path"
+done
+
+{{#if cfg.use_member_id_as_uuid ~}}
+mkdir -p "{{pkg.svc_config_path}}/local-mode-cache/cache/"
+cp -v "{{pkg.svc_config_path}}/data_collector_metadata.json" "{{pkg.svc_config_path}}/local-mode-cache/cache/"
+{{/if ~}}
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..9c9b5b19c8 100644
--- a/habitat/plan.sh
+++ b/habitat/plan.sh
@@ -7,8 +7,8 @@ pkg_source=nosuchfile.tar.gz
pkg_filename=${pkg_dirname}.tar.gz
pkg_license=('Apache-2.0')
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)
pkg_svc_user=root
do_download() {
@@ -44,7 +44,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 +52,52 @@ 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
}