Skip to content

Commit f7f9406

Browse files
committed
Update the omnibus_updater chef recipe
1 parent 594cb50 commit f7f9406

25 files changed

+274
-341
lines changed
+5-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
.bundle
2-
.cache
3-
.kitchen
1+
.*
2+
!.gitignore
3+
!.kitchen.yml
44
bin
55
Gemfile.lock
6+
Cheffile.lock
7+
tmp*
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
driver_plugin: vagrant
3+
platforms:
4+
- name: ubuntu-12.04
5+
driver_config:
6+
box: opscode-ubuntu-12.04
7+
box_url: https://opscode-vm.s3.amazonaws.com/vagrant/boxes/opscode-ubuntu-12.04.box
8+
- name: ubuntu-10.04
9+
driver_config:
10+
box: opscode-ubuntu-10.04
11+
box_url: https://opscode-vm.s3.amazonaws.com/vagrant/boxes/opscode-ubuntu-10.04.box
12+
- name: centos-6.4
13+
driver_config:
14+
box: opscode-centos-6.4
15+
box_url: https://opscode-vm.s3.amazonaws.com/vagrant/boxes/opscode-centos-6.3.box
16+
- name: centos-5.8
17+
driver_config:
18+
box: opscode-centos-5.8
19+
box_url: https://opscode-vm.s3.amazonaws.com/vagrant/boxes/opscode-centos-5.8.box
20+
suites:
21+
- name: default
22+
run_list:
23+
- recipe[omnibus_updater_test::default]
24+
- recipe[minitest-handler]
25+
- name: upgrade
26+
run_list:
27+
- recipe[omnibus_updater_test::version_upgrade]
28+
- recipe[minitest-handler]

chef/cookbooks/omnibus_updater/CHANGELOG.md

+14
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
v0.2.4
2+
======
3+
* Only download omnibus package if version difference detected (#20 #22 #23)
4+
* Provide attribute for always downloading package even if version matches
5+
6+
v0.2.3
7+
======
8+
* Use chef internals for interactions with omnitruck to provide proper proxy support (#19)
9+
10+
v0.2.0
11+
======
12+
* Use omnitruck client for url generation for package fetching
13+
* Use `prerelease` in favor of `allow_release_clients`
14+
115
v0.1.2
216
======
317
* Fix regression on debian package path construction (thanks [ashmere](https://github.com/ashmere))
+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
site 'http://community.opscode.com/api/v1'
2+
3+
cookbook 'omnibus_updater', path: './'
4+
cookbook 'omnibus_updater_test', path: './test/kitchen/cookbooks/omnibus_updater_test'
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
source :rubygems
22

3-
gem 'test-kitchen'
3+
gem 'vagabond'

chef/cookbooks/omnibus_updater/README.md

+19-26
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ be installed on the node:
1414

1515
`knife node run_list add recipe[omnibus_updater]`
1616

17-
In your role you'll likely want to set the version (it defaults
18-
to the 0.10.10 version of Chef):
17+
In your role you'll likely want to set the version. It defaults
18+
to nothing, and will install the latest..
1919

2020
```
2121
override_attributes(
2222
:omnibus_updater => {
23-
:version => '10.16.2'
23+
:version => '11.4.0'
2424
}
2525
)
2626
```
@@ -35,37 +35,30 @@ override_attributes(
3535
}
3636
)
3737
```
38-
---
39-
40-
If you are using a Chef version earlier than 10.12.0 you may want
41-
to take a look at the chef_gem cookbook to ensure gems are going
42-
where expected.
43-
44-
---
45-
46-
The default recipe will install the omnibus package based
47-
on system information but you can override that by using
48-
the `install_via` attribute which accepts: deb, rpm or script.
4938

5039
Features
5140
========
5241

53-
Auto version expansion
54-
----------------------
42+
Latest Version
43+
--------------
5544

56-
Versions for the omnibus installer are defined as: x.y.z-n If the `:version` attribute only provides
57-
x.y.z the `n` value will be automatically filled in with the latest available version.
45+
Force installation of the latest version regardless of value stored in version
46+
attribute by setting the `force_latest` attribute.
5847

59-
Auto version searching
60-
----------------------
48+
Chef Killing
49+
------------
6150

62-
Using the `:version_search` attribute, the latest stable version of the omnibus installer will
63-
be installed automatically as they become available.
51+
By default the omnibus updater will kill the chef instance by raising and exception.
52+
You can turn this off using the `kill_chef_on_upgrade` attribute. It is not
53+
recommended to turn this off. Internal chef libraries may change, move, or no
54+
longer exist. The currently running instance can encounter unexpected states because
55+
of this. To prevent this, the updater will attempt to kill the Chef instance so
56+
that it can be restarted in a normal state.
6457

65-
Release clients
66-
---------------
58+
Prerelease
59+
--------
6760

68-
Release clients can be installed via the auto-installation using `:allow_release_clients` attribute.
61+
Prereleases can be installed via the auto-installation using `prerelease` attribute.
6962

7063
Disable
7164
-------
@@ -79,4 +72,4 @@ Infos
7972

8073
* Repo: https://github.com/hw-cookbooks/omnibus_updater
8174
* IRC: Freenode @ #heavywater
82-
75+
* Cookbook: http://ckbk.it/omnibus_updater
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
default[:omnibus_updater][:version] = '10.18.2'
2-
default[:omnibus_updater][:version_search] = false
3-
default[:omnibus_updater][:base_uri] = 'http://opscode-omnibus-packages.s3.amazonaws.com'
1+
default[:omnibus_updater][:version] = nil
2+
default[:omnibus_updater][:force_latest] = false
43
default[:omnibus_updater][:cache_dir] = '/opt'
54
default[:omnibus_updater][:cache_omnibus_installer] = false
65
default[:omnibus_updater][:remove_chef_system_gem] = false
7-
default[:omnibus_updater][:allow_release_clients] = false
6+
default[:omnibus_updater][:prerelease] = false
87
default[:omnibus_updater][:disabled] = false
8+
default[:omnibus_updater][:kill_chef_on_upgrade] = true
9+
default[:omnibus_updater][:always_download] = false
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
module OmnibusTrucker
2+
class << self
3+
URL_MAP = {
4+
:p => :platform, :pv => :platform_version, :m => :machine,
5+
:v => :version, :prerelease => :prerelease,
6+
:nightlies => :nightlies
7+
}
8+
9+
def build_url(*opts)
10+
args = node = nil
11+
opts.each do |o|
12+
if(o.kind_of?(Hash))
13+
args = o
14+
elsif(o.kind_of?(Chef::Node))
15+
node = o
16+
else
17+
raise ArgumentError.new "Provided argument is not allowed: #{o.class}"
18+
end
19+
end
20+
args ||= {}
21+
if(node)
22+
args = collect_attributes(node).merge(args)
23+
end
24+
url = args[:url] || "http://www.opscode.com/chef/download#{'-server' if args[:server]}"
25+
u_args = URL_MAP.map do |u_k, a_k|
26+
"#{u_k}=#{args[a_k]}" unless args[a_k].nil?
27+
end.compact
28+
"#{url}?#{u_args.join('&')}"
29+
end
30+
31+
def collect_attributes(node, args={})
32+
set = Hash[*(
33+
[:platform_family, :platform, :platform_version].map do |k|
34+
[k, args[k] || node[k]]
35+
end.flatten.compact
36+
)]
37+
unless(@attrs)
38+
if(set[:platform_family] == 'rhel')
39+
@attrs = {:platform => 'el', :platform_version => set[:platform_version].to_i}
40+
else
41+
@attrs = {:platform => set[:platform], :platform_version => set[:platform_version]}
42+
end
43+
@attrs[:machine] = args[:machine] || node[:kernel][:machine]
44+
end
45+
@attrs
46+
end
47+
48+
def url(url_or_node, node = nil)
49+
if(url_or_node.is_a?(Chef::Node))
50+
url = build_url(url_or_node)
51+
node = url_or_node
52+
else
53+
url = url_or_node
54+
raise "Node instance is required for Omnitruck.url!" unless node
55+
end
56+
request = Chef::REST::RESTRequest.new(:head, URI.parse(url), nil)
57+
result = request.call
58+
if(result.kind_of?(Net::HTTPRedirection))
59+
result['location']
60+
end
61+
end
62+
63+
end
64+
end

chef/cookbooks/omnibus_updater/metadata.json

-29
This file was deleted.
+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
name "omnibus_updater"
12
maintainer "Chris Roberts"
23
maintainer_email "[email protected]"
34
license "Apache 2.0"
45
description "Chef omnibus package updater and installer"
56
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
6-
version "0.1.2"
7+
version "0.2.4"
78

chef/cookbooks/omnibus_updater/recipes/deb_downloader.rb

-18
This file was deleted.

chef/cookbooks/omnibus_updater/recipes/deb_package.rb

-30
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,10 @@
1-
if node[:omnibus_updater][:disabled]
1+
if(node[:omnibus_updater][:disabled])
22
Chef::Log.warn 'Omnibus updater disabled via `disabled` attribute'
3-
elsif node[:omnibus_updater][:install_via]
4-
case node[:omnibus_updater][:install_via]
5-
when 'deb'
6-
include_recipe 'omnibus_updater::deb_package'
7-
when 'rpm'
8-
include_recipe 'omnibus_updater::rpm_package'
9-
when 'script'
10-
include_recipe 'omnibus_updater::script'
11-
else
12-
raise "Unknown omnibus update method requested: #{node[:omnibus_updater][:install_via]}"
13-
end
143
else
15-
case node.platform_family
16-
when 'debian'
17-
include_recipe 'omnibus_updater::deb_package'
18-
when 'fedora', 'rhel'
19-
include_recipe 'omnibus_updater::rpm_package'
20-
else
21-
include_recipe 'omnibus_updater::script'
22-
end
4+
include_recipe 'omnibus_updater::downloader'
5+
include_recipe 'omnibus_updater::installer'
236
end
247

25-
include_recipe 'omnibus_updater::remove_chef_system_gem' if node[:omnibus_updater][:remove_chef_system_gem]
8+
if(node[:omnibus_updater][:remove_chef_system_gem])
9+
include_recipe 'omnibus_updater::remove_chef_system_gem'
10+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# NOTE: This recipe is here for others that just want the
2+
# package, not the actual installation (lxc for example)
3+
4+
if(node[:omnibus_updater][:direct_url])
5+
remote_path = node[:omnibus_updater][:direct_url]
6+
else
7+
version = node[:omnibus_updater][:version] || ''
8+
remote_path = OmnibusTrucker.url(
9+
OmnibusTrucker.build_url(node,
10+
:version => node[:omnibus_updater][:force_latest] ? nil : version.sub(/\-.+$/, ''),
11+
:prerelease => node[:omnibus_updater][:preview]
12+
), node
13+
)
14+
end
15+
16+
if(remote_path)
17+
node.set[:omnibus_updater][:full_url] = remote_path
18+
Chef::Log.info "Omnibus Updater remote path: #{remote_path}"
19+
20+
remote_file "omnibus_remote[#{File.basename(remote_path)}]" do
21+
path File.join(node[:omnibus_updater][:cache_dir], File.basename(remote_path))
22+
source remote_path
23+
backup false
24+
action :create_if_missing
25+
only_if do
26+
unless(version = node[:omnibus_updater][:version])
27+
version = node[:omnibus_updater][:full_url].scan(%r{chef_(\d+\.\d+.\d+)}).flatten.first
28+
end
29+
node[:omnibus_updater][:always_download] || Chef::VERSION != version.to_s.sub(/\-.+$/, '')
30+
end
31+
end
32+
else
33+
Chef::Log.warn 'Failed to retrieve omnibus download URL'
34+
end
35+
36+
include_recipe 'omnibus_updater::old_package_cleaner'

0 commit comments

Comments
 (0)