Skip to content

Commit

Permalink
migrate ui recipe to use libarchive pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
reset committed Feb 6, 2015
1 parent 3980762 commit 1627ff5
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 19 deletions.
6 changes: 0 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -322,12 +322,6 @@ Following attributes, if exist in the [encrypted databag][7], override the node
</td>
<td><tt>nil</tt></td>
</tr>
<tr>
<td><tt>['consul']['ui_dir']</tt></td>
<td>String</td>
<td>Location to download the UI to</td>
<td><tt>/var/lib/consul/ui</tt></td>
</tr>
<tr>
<td><tt>['consul']['serve_ui']</tt></td>
<td>Boolean</td>
Expand Down
5 changes: 2 additions & 3 deletions attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@
default['consul']['client_interface'] = nil

# UI attributes
default['consul']['client_addr'] = '0.0.0.0'
default['consul']['ui_dir'] = '/var/lib/consul/ui'
default['consul']['serve_ui'] = false
default['consul']['client_addr'] = '0.0.0.0'
default['consul']['serve_ui'] = false
default['consul']['extra_params'] = {}
46 changes: 46 additions & 0 deletions libraries/consul_ui.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#
# Copyright 2014-2015 John Bellone <jbellone@bloomberg.net>
# Copyright 2014-2015 Bloomberg Finance L.P.
#
# 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.
#

class Chef
module ConsulUI
class << self
def active_path(node)
File.join(node['consul']['data_dir'], 'ui')
end

def cached_archive(node)
File.join(Chef::Config[:file_cache_path], File.basename(remote_url(node)))
end

def install_path(node)
File.join(['/opt', 'consul_ui', node['consul']['version']])
end

def remote_filename(node)
[node['consul']['version'], 'web_ui'].join('_')
end

def remote_checksum(node)
node['consul']['checksums'].fetch(remote_filename(node))
end

def remote_url(node)
node['consul']['base_url'] % { version: remote_filename(node) }
end
end
end
end
2 changes: 1 addition & 1 deletion recipes/_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
end

if node['consul']['serve_ui']
service_config['ui_dir'] = node['consul']['ui_dir']
service_config['ui_dir'] = Chef::ConsulUI.active_path(node)
service_config['client_addr'] = node['consul']['client_addr']
end

Expand Down
24 changes: 15 additions & 9 deletions recipes/ui.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,21 @@
# limitations under the License.
#

include_recipe 'ark::default'
include_recipe 'libarchive::default'

install_version = [node['consul']['version'], 'web_ui'].join('_')
install_checksum = node['consul']['checksums'].fetch(install_version)
archive = remote_file Chef::ConsulUI.cached_archive(node) do
source Chef::ConsulUI.remote_url(node)
checksum Chef::ConsulUI.remote_checksum(node)
end

libarchive_file 'consul_ui.zip' do
path archive.path
extract_to Chef::ConsulUI.install_path(node)
extract_options :no_overwrite

action :extract
end

ark 'consul_ui' do
path node['consul']['data_dir']
home_dir node['consul']['ui_dir']
version node['consul']['version']
checksum install_checksum
url node['consul']['base_url'] % { version: install_version }
link Chef::Consul.active(node) do
to Chef::Consul.install_path(node)
end

0 comments on commit 1627ff5

Please sign in to comment.