chef-boneyard / habitat

Chef Cookbook for Habitat
https://supermarket.chef.io/cookbooks/habitat
Apache License 2.0
22 stars 42 forks source link
chef containers cookbook habitat hacktoberfest

Habitat Cookbook

Cookbook Version CI State License

Deprecation

Great news: The habitat resources from this cookbook are now included directly in Chef Infra Client 17.3 or later. Due to this we will no longer be making enhancements to this cookbook. If you have any feature requests or would like to open a PR with improvements please direct them to https://github.com/chef/chef

Description

This cookbook provides resources for working with Habitat. It is intended that these resources will be included in core Chef at some point in the future, so it is important to note:

License Note

Habitat requires acceptance of a license before any habitat commands can be run. To accept the Habitat license using this cookbook, the license parameter can be set to accept for either the hab_install or hab_sup resources as shown in the below examples:

hab_install 'install habitat' do
  license 'accept'
end
hab_sup 'default' do
  license 'accept'
end

PLEASE NOTE: Without performing one of the above license acceptance steps, all other resources in the habitat cookbook will fail with an error prompting that the license must be accepted.

Requirements

Platforms

Habitat

This cookbook used to base version number off of the latest stable Habitat release and install a specific version of Habitat based upon the cookbook version. Current behavior is now that the cookbook will install the latest stable release of Habitat on the source Habitat Builder which is contacted by default, but allows for explicit version pinning to be set via cookbook resources.

Chef

Cookbooks

Resources

hab_install

Installs Habitat on the system using the install script.

Actions

Properties

Examples


# Nameless Installation
hab_install

# Instalaltion specifying a bldr URL
hab_install 'install habitat' do
  bldr_url 'http://localhost'
end

# Installtation specifying version and bldr URL
hab_install 'install habitat' do
  bldr_url 'http://localhost'
  hab_version '1.5.50'
end

hab_package

Install the specified Habitat package from builder. Requires that Habitat is installed

actions

Properties

While it is valid to pass the version and release with a Habitat package as a fully qualified package identifier when using the hab CLI, they must be specified using the version property when using this resource. See the examples below.

Examples

hab_package 'core/redis'

hab_package 'core/redis' do
  version '3.2.3'
  channel 'unstable'
end

hab_package 'core/redis' do
  version '3.2.3/20160920131015'
end

hab_package 'core/nginx' do
  binlink :force
end

hab_package 'core/nginx' do
  options '--binlink'
end

# Remove all
hab_package 'core/nginx'
  action :remove
end

# Remove specified
hab_package 'core/nginx/3.2.3'
  action :remove
end

# Remove but retain some versions (only available as of Habitat 1.5.86)
hab_package 'core/nginx'
  keep_latest '2'
  action :remove
end

# Renove but keep dependencies
hab_package 'core/nginx'
  no_deps false
  action :remove
end

hab_service

Manages a Habitat application service using hab sup/hab service. This requires that core/hab-sup be running as a service. See the hab_sup resource documentation below for more information about how to set that up with this cookbook.

Note: Applications may run as a specific user. Often with Habitat, the default is hab, or root. If the application requires another user, then it should be created with Chef's user resource.

Actions

Properties

The remote_sup property is valid for all actions.

The follow properties are valid for the load action.

Examples

# install and load nginx
hab_package 'core/nginx'
hab_service 'core/nginx'

hab_service 'core/nginx unload' do
  service_name 'core/nginx'
  action :unload
end

# pass the strategy and topology options to hab service commands (load by default)
hab_service 'core/redis' do
  strategy 'rolling'
  topology 'standalone'
end

# Using update_condition
hab_service 'core/redis' do
  strategy 'rolling'
  update_condition 'track-channel'
  topology 'standalone'
end

If the service has it's own user specified that is not the hab user, don't create the hab user on install, and instead create the application user with Chef's user resource

hab_install 'install habitat' do
  create_user false
end

user 'acme-apps' do
  system true
end

hab_service 'acme/apps'

hab_sup

Runs a Habitat Supervisor for one or more Habitat Services. It is used in conjunction with hab_service which will manage the services loaded and started within the supervisor.

The run action handles installing Habitat using the hab_install resource, ensures that the appropriate versions of the core/hab-sup and core/hab-launcher packages are installed using hab_package, and then drops off the appropriate init system definitions and manages the service.

All event_stream_* properties are optional, and allow the Habitat Supervisor to display details about it's status and running services via the Chef Automate Applications Dashboard. Note: Automate has TLS on by default. You will need to follow these instructions to make sure habitat has the proper certificates for `eventstram` Share the TLS Certificate with Chef Habitat*

Actions

Properties

Examples

# set up with just the defaults
hab_sup 'default'

# Update listen ports and use Supervisor toml config
hab_sup 'test-options' do
  listen_http '0.0.0.0:9999'
  listen_gossip '0.0.0.0:9998'
  toml_config true
end

# Use with an on-prem Builder
# Access to public builder may not be available
hab_sup 'default' do
  bldr_url 'https://bldr.private.net'
end

# Using update_condition
hab_sup 'default' do
  bldr_url 'https://bldr.private.net'
  hab_channel 'dev'
  update_condition 'track-channel'
end

# Provide event_stream_* information
hab_sup 'default' do
  license 'accept'
  event_stream_application 'myapp'
  event_stream_environment 'production'
  event_stream_site 'MySite'
  event_stream_url 'automate.private.net:4222'
  event_stream_token 'myawesomea2clitoken='
  event_stream_cert '/hab/cache/ssl/mycert.crt'
end

# Provide specific versions
hab_sup 'default' do
  bldr_url 'https://bldr.private.net'
  sup_version '1.5.50'
  launcher_version '13458'
  service_version '0.6.0' # WINDOWS ONLY
end

# Set latest version of packages to retain
hab_sup 'default' do
  bldr_url 'https://bldr.private.net'
  sup_version '1.5.86'
  launcher_version '13458'
  service_version '0.6.0' # WINDOWS ONLY
  keep_latest '2'
end

hab_config

Applies a given configuration to a habitat service using hab config apply.

Actions

Properties

Notes

The version number of the configuration is automatically generated and will be the current timestamp in seconds since 1970-01-01 00:00:00 UTC.

Examples

hab_config 'nginx.default' do
  config({
    worker_count: 2,
    http: {
      keepalive_timeout: 120
    }
  })
end

hab_user_toml

Templates a user.toml for the specified service. This is written to /hab/user/<service_name>/config/user.toml. User.toml can be used to set configuration overriding the default.toml for a given package as an alternative to applying service group level configuration.

Actions

Properties

Examples

hab_user_toml 'nginx' do
  config({
    worker_count: 2,
    http: {
      keepalive_timeout: 120
    }
  })
end

Maintainers

This cookbook is maintained by the following maintainers:

The goal of the Community Cookbook Engineering team is to improve cookbook quality and to aid the community in contributing to cookbooks. To learn more about our team, process, and design goals see our team documentation. To learn more about contributing to cookbooks like this see our contributing documentation, or if you have general questions about this cookbook come chat with us in #cookbok-engineering on the Chef Community Slack

License

Copyright: 2016-2018, Chef Software, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.