Skip to content

Commit

Permalink
sous-chefs#215 consul_ui resource and readme
Browse files Browse the repository at this point in the history
  • Loading branch information
tomzo committed Sep 15, 2015
1 parent adf1f06 commit 4927a08
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 0 deletions.
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,34 @@ into the resource. This could potentially be a *very dangerous*
operation. You should absolutely understand what you are doing. By the
nature of this command it is _impossible_ for it to be idempotent.

### UI

`consul_ui` resource can be used to download and extract the
[consul web UI](https://www.consul.io/intro/getting-started/ui.html).
It can be done with a block like this:

```ruby
consul_ui 'consul-ui' do
owner node['consul']['service_user']
group node['consul']['service_group']
version node['consul']['version']
end
```

Assuming consul version `0.5.2` above block would create `/srv/consul-ui/0.5.2`
and symlink `/srv/consul-ui/current`.

It does not change agent's configuration by itself.
`consul_config` resource should be modified explicitly in order to host the web page.

```ruby
consul_config 'consul' do
...
ui_dir '/opt/consul-ui/current/dist'
end
```


[0]: http://blog.vialstudios.com/the-environment-cookbook-pattern/#theapplicationcookbook
[1]: http://consul.io
[2]: http://blog.vialstudios.com/the-environment-cookbook-pattern#thewrappercookbook
Expand Down
82 changes: 82 additions & 0 deletions libraries/consul_ui.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
require 'poise'

module ConsulCookbook
module Resource
# Resource for managing the Consul web UI installation.
class ConsulUI < Chef::Resource
include Poise
provides(:consul_ui)
default_action(:install)

# @!attribute version
# @return [String]
attribute(:version, kind_of: String, required: true)

# @!attribute install_path
# @return [String]
attribute(:install_path, kind_of: String, default: '/srv')

# @!attribute owner
# @return [String]
attribute(:owner, kind_of: String, default: 'consul')

# @!attribute group
# @return [String]
attribute(:group, kind_of: String, default: 'consul')

# @!attribute binary_url
# @return [String]
attribute(:binary_url, kind_of: String, default: "https://dl.bintray.com/mitchellh/consul/%{filename}.zip")

# @!attribute source_url
# @return [String]
attribute(:source_url, kind_of: String)

def default_environment
{ GOMAXPROCS: [node['cpu']['total'], 2].max.to_s, PATH: '/usr/local/bin:/usr/bin:/bin' }
end

def binary_checksum
node['consul']['checksums'].fetch(binary_filename)
end

def binary_filename
[version, 'web_ui'].join('_')
end

end
end

module Provider
# Provider for managing the Consul web UI installation.
class ConsulUI < Chef::Provider
include Poise
provides(:consul_ui)

def action_install
notifying_block do
artifact = libartifact_file "consul-ui-#{new_resource.version}" do
artifact_name new_resource.name
artifact_version new_resource.version
owner new_resource.owner
group new_resource.group
install_path new_resource.install_path
remote_url new_resource.binary_url % { filename: new_resource.binary_filename }
remote_checksum new_resource.binary_checksum
end
end
end

def action_uninstall
notifying_block do
artifact = libartifact_file "consul-ui-#{new_resource.version}" do
action :delete
artifact_name new_resource.name
artifact_version new_resource.version
install_path new_resource.install_path
end
end
end
end
end
end

0 comments on commit 4927a08

Please sign in to comment.