Skip to content

Commit

Permalink
Refactor package recipe to use package name attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
bflad committed Jun 24, 2014
1 parent 5fba8c6 commit c4f1570
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 27 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
20 changes: 19 additions & 1 deletion attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -91,7 +110,6 @@
'default' => nil
)
default['docker']['package']['repo_key'] = 'https://get.docker.io/gpg'
default['docker']['package']['name'] = nil

## Source installation attributes

Expand Down
7 changes: 1 addition & 6 deletions libraries/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
26 changes: 6 additions & 20 deletions recipes/package.rb
Original file line number Diff line number Diff line change
@@ -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']
Expand All @@ -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

0 comments on commit c4f1570

Please sign in to comment.