From c4f1570356471c6c220b2c0b7615bd73106f1f0f Mon Sep 17 00:00:00 2001 From: Brian Flad Date: Mon, 23 Jun 2014 23:01:34 -0400 Subject: [PATCH] Refactor package recipe to use package name attribute --- README.md | 1 + attributes/default.rb | 20 +++++++++++++++++++- libraries/helpers.rb | 7 +------ recipes/package.rb | 26 ++++++-------------------- 4 files changed, 27 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index 6d36542fb8..2532d7d846 100644 --- a/README.md +++ b/README.md @@ -112,6 +112,7 @@ Attribute | Description | Type | Default ----------|-------------|------|-------- action | Action for docker packages ("install", "update", etc.) | String | install distribution | Distribution for docker packages | String | auto-detected (see attributes/default.rb) +name | Override Docker package name | String | auto-detected (see attributes/default.rb) repo_url | Repository URL for docker packages | String | auto-detected (see attributes/default.rb) repo_key | Repository GPG key URL for docker packages | String | https://get.docker.io/gpg diff --git a/attributes/default.rb b/attributes/default.rb index eb68a5e0bc..481c3f79cc 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -80,6 +80,25 @@ default['docker']['package']['action'] = 'install' default['docker']['package']['distribution'] = 'docker' +default['docker']['package']['name'] = value_for_platform( + 'amazon' => { + 'default' => 'docker' + }, + %w(centos fedora redhat) => { + 'default' => 'docker-io' + }, + 'debian' => { + 'default' => 'lxc-docker' + }, + 'mac_os_x' => { + 'default' => 'homebrew/binary/docker' + }, + 'ubuntu' => { + %w(12.04 12.10 13.04 13.10) => 'lxc-docker', + 'default' => 'docker.io' + }, + 'default' => nil +) default['docker']['package']['repo_url'] = value_for_platform( 'debian' => { 'default' => 'https://get.docker.io/ubuntu' @@ -91,7 +110,6 @@ 'default' => nil ) default['docker']['package']['repo_key'] = 'https://get.docker.io/gpg' -default['docker']['package']['name'] = nil ## Source installation attributes diff --git a/libraries/helpers.rb b/libraries/helpers.rb index 6d0cb6daa1..ee3f6505b0 100644 --- a/libraries/helpers.rb +++ b/libraries/helpers.rb @@ -94,13 +94,8 @@ def self.executable(node) # Boolean to determine whether or not we are using the docker.io package def self.using_docker_io_package?(node) - node['platform'] == 'ubuntu' && node['docker']['install_type'] == 'package' && - ( - node['docker']['package']['repo_url'].nil? || - node['docker']['package']['repo_url'].empty? - ) && - Chef::VersionConstraint.new('>= 14.04').include?(node['platform_version']) + node['docker']['package']['name'] == 'docker.io' end def self.daemon_cli_args(node) diff --git a/recipes/package.rb b/recipes/package.rb index 71d4621b3c..e39228e926 100644 --- a/recipes/package.rb +++ b/recipes/package.rb @@ -1,27 +1,19 @@ +p = node['docker']['package']['name'] case node['platform'] -when 'amazon' - p = node['docker']['package']['name'] || 'docker' - package p do - version node['docker']['version'] - action node['docker']['package']['action'].intern - end -when 'centos', 'redhat' # ~FC024 - include_recipe 'yum-epel' +when 'amazon', 'centos', 'fedora', 'redhat' + include_recipe 'yum-epel' if %w(centos redhat).include?(node['platform']) - p = node['docker']['package']['name'] || 'docker-io' package p do version node['docker']['version'] action node['docker']['package']['action'].intern end when 'debian', 'ubuntu' if Helpers::Docker.using_docker_io_package? node - p = node['docker']['package']['name'] || 'docker.io' link '/usr/local/bin/docker' do to '/usr/bin/docker.io' end else - p = node['docker']['package']['name'] || 'lxc-docker' apt_repository 'docker' do uri node['docker']['package']['repo_url'] distribution node['docker']['package']['distribution'] @@ -38,17 +30,11 @@ options '--force-yes -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold"' action node['docker']['package']['action'].intern end -when 'fedora' - p = node['docker']['package']['name'] || 'docker-io' - package p do - version node['docker']['version'] - action node['docker']['package']['action'].intern - end -when 'mac_os_x' +when 'mac_os_x', 'mac_os_x_server' homebrew_tap 'homebrew/binary' - package 'homebrew/binary/docker' do + package p do action node['docker']['package']['action'].intern end else - raise RuntimeError, "The package installation method for `#{node['platform']} is not supported.`" + fail "The package installation method for `#{node['platform']} is not supported.`" end