Skip to content

Commit

Permalink
Merge pull request #458 from Wing924/fix-hard-coded-version
Browse files Browse the repository at this point in the history
Make it possible to override base package URL location; switch default to GitHub
  • Loading branch information
michaelklishin authored Sep 26, 2017
2 parents a986869 + 99679b7 commit 30ef49f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 23 deletions.
18 changes: 4 additions & 14 deletions attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,11 @@
default['rabbitmq']['pin_distro_version'] = false

# provide options to override download urls and package names
default['rabbitmq']['deb_package'] = "rabbitmq-server_#{node['rabbitmq']['version']}-1_all.deb"
default['rabbitmq']['deb_package_url'] = "https://www.rabbitmq.com/releases/rabbitmq-server/v#{node['rabbitmq']['version']}/"
default['rabbitmq']['deb_package'] = nil
default['rabbitmq']['deb_package_url'] = nil

case node['platform_family']
when 'rhel', 'fedora'
default['rabbitmq']['rpm_package'] = if node['platform_version'].to_i > 6
"rabbitmq-server-#{node['rabbitmq']['version']}-1.el7.noarch.rpm"
else
"rabbitmq-server-#{node['rabbitmq']['version']}-1.el6.noarch.rpm"
end
when 'suse'
default['rabbitmq']['rpm_package'] = "rabbitmq-server-#{node['rabbitmq']['version']}-1.suse.noarch.rpm"
end

default['rabbitmq']['rpm_package_url'] = "https://www.rabbitmq.com/releases/rabbitmq-server/v#{node['rabbitmq']['version']}/"
default['rabbitmq']['rpm_package'] = nil
default['rabbitmq']['rpm_package_url'] = nil

# RabbitMQ 3.6.8+ non-distro versions requires a modern Erlang which is neither available in
# older distros via packages nor EPEL. rhel < 7, debian < 8
Expand Down
38 changes: 29 additions & 9 deletions recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,29 @@ class Chef::Resource

include_recipe 'erlang'

version = node['rabbitmq']['version']
url_version = version.tr('.', '_')

default_package_url = "https://github.com/rabbitmq/rabbitmq-server/releases/download/rabbitmq_v#{url_version}/"

default_deb_package_name = "rabbitmq-server_#{version}-1_all.deb"

case node['platform_family']
when 'rhel', 'fedora'
default_rpm_package_name = if node['platform_version'].to_i > 6
"rabbitmq-server-#{version}-1.el7.noarch.rpm"
else
"rabbitmq-server-#{version}-1.el6.noarch.rpm"
end
when 'suse'
default_rpm_package_name = "rabbitmq-server-#{version}-1.suse.noarch.rpm"
end

deb_package_name = node['rabbitmq']['deb_package'] || default_deb_package_name
deb_package_url = node['rabbitmq']['deb_package_url'] || default_package_url
rpm_package_name = node['rabbitmq']['rpm_package'] || default_rpm_package_name
rpm_package_url = node['rabbitmq']['rpm_package_url'] || default_package_url

## Install the package
case node['platform_family']
when 'debian'
Expand Down Expand Up @@ -61,14 +84,13 @@ class Chef::Resource
end
else
# we need to download the package
deb_package = "#{node['rabbitmq']['deb_package_url']}#{node['rabbitmq']['deb_package']}"
remote_file "#{Chef::Config[:file_cache_path]}/#{node['rabbitmq']['deb_package']}" do
source deb_package
remote_file "#{Chef::Config[:file_cache_path]}/#{deb_package_name}" do
source "#{deb_package_url}#{deb_package_name}"
action :create_if_missing
end
package 'rabbitmq-server' do
provider Chef::Provider::Package::Dpkg
source ::File.join(Chef::Config[:file_cache_path], node['rabbitmq']['deb_package'])
source ::File.join(Chef::Config[:file_cache_path], deb_package_name)
action :upgrade
end
end
Expand Down Expand Up @@ -133,13 +155,11 @@ class Chef::Resource
end
else
# We need to download the rpm
rpm_package = "#{node['rabbitmq']['rpm_package_url']}#{node['rabbitmq']['rpm_package']}"

remote_file "#{Chef::Config[:file_cache_path]}/#{node['rabbitmq']['rpm_package']}" do
source rpm_package
remote_file "#{Chef::Config[:file_cache_path]}/#{rpm_package_name}" do
source "#{rpm_package_url}#{rpm_package_name}"
action :create_if_missing
end
rpm_package "#{Chef::Config[:file_cache_path]}/#{node['rabbitmq']['rpm_package']}"
rpm_package "#{Chef::Config[:file_cache_path]}/#{rpm_package_name}"
end

when 'suse'
Expand Down

0 comments on commit 30ef49f

Please sign in to comment.