From 2f0ea6a2bb2b70163f3e0136a356129afa5846c8 Mon Sep 17 00:00:00 2001 From: Jay Faulkner Date: Thu, 19 Dec 2013 09:14:12 -0800 Subject: [PATCH 1/3] fix(extras): Use uname -r output for extras package name by default - Optionally, allow a cookbook user to pick the older method of finding a kernel, in case the new way breaks compatibilty for them --- README.md | 8 ++++++++ attributes/default.rb | 3 +++ recipes/aufs.rb | 19 ++++++++++--------- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 8bbe03edf4..d926865512 100644 --- a/README.md +++ b/README.md @@ -79,6 +79,14 @@ Attribute | Description | Type | Default ref | Repository reference for docker source | String | "master" url | Repository URL for docker source | String | "https://github.com/dotcloud/docker.git" +## AUFS Attributes + +These attributes are under the `node['docker']['aufs'] namespace. + +Attribute | Description | Type | Default +----------|-------------|------|-------- +legacy_package_finder | Use older method for determining kernel package name | Bool | false + ## Recipes * `recipe[docker]` Installs/Configures Docker diff --git a/attributes/default.rb b/attributes/default.rb index 3a42975282..c7b7e35d5e 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -64,3 +64,6 @@ # Source attributes default['docker']['source']['ref'] = 'master' default['docker']['source']['url'] = 'https://github.com/dotcloud/docker.git' + +# linux-image-extras legacy support +default['docker']['aufs']['legacy_package_finder'] = false diff --git a/recipes/aufs.rb b/recipes/aufs.rb index 554998f104..4aff104fe3 100644 --- a/recipes/aufs.rb +++ b/recipes/aufs.rb @@ -1,14 +1,15 @@ case node['platform'] when 'ubuntu' - # - # The below code copied from: https://github.com/thoward/docker-cookbook/blob/master/recipes/default.rb - # It's not pretty, but gets the job done! - # - # If aufs isn't available, do our best to install the correct - # linux-image-extra package. This is somewhat messy because the - # naming of these packages is very inconsistent across kernel - # versions - extra_package = Mixlib::ShellOut.new("apt-cache search linux-image-extra-`uname -r | grep --only-matching -e [0-9]\.[0-9]\.[0-9]-[0-9]*` | cut -d ' ' -f 1").run_command.stdout.strip + # If aufs isn't available, do our best to install the correct linux-image-extra package. + if node['docker']['aufs']['legacy_package_finder'] + # Original method copied from https://github.com/thoward/docker-cookbook/blob/master/recipes/default.rb + extra_package = Mixlib::ShellOut.new("apt-cache search linux-image-extra-`uname -r | grep --only-matching -e [0-9]\.[0-9]\.[0-9]-[0-9]*` | cut -d ' ' -f 1").run_command.stdout.strip + else + # In modern ubuntu versions, uname -r matches the kernel package name + uname = Mixlib::ShellOut.new('uname -r').run_command.stdout.strip + extra_package = 'linux-image-extra-' + uname + end + unless extra_package.empty? package extra_package do not_if 'modprobe -l | grep aufs' From 2721fe15d594e2211ad4913bfdc38238fa244d42 Mon Sep 17 00:00:00 2001 From: Jay Faulkner Date: Thu, 19 Dec 2013 14:38:14 -0800 Subject: [PATCH 2/3] fix(aufs): Check that the package exists before installing - Also for new method, use ohai's provided kernel release rather than shelling out to uname --- recipes/aufs.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/recipes/aufs.rb b/recipes/aufs.rb index 4aff104fe3..f8b5226c60 100644 --- a/recipes/aufs.rb +++ b/recipes/aufs.rb @@ -3,13 +3,13 @@ # If aufs isn't available, do our best to install the correct linux-image-extra package. if node['docker']['aufs']['legacy_package_finder'] # Original method copied from https://github.com/thoward/docker-cookbook/blob/master/recipes/default.rb - extra_package = Mixlib::ShellOut.new("apt-cache search linux-image-extra-`uname -r | grep --only-matching -e [0-9]\.[0-9]\.[0-9]-[0-9]*` | cut -d ' ' -f 1").run_command.stdout.strip + package_name = 'linux-image-extra-' + Mixlib::ShellOut.new("uname -r | grep --only-matching -e [0-9]\.[0-9]\.[0-9]-[0-9]*").run_command.stdout.strip else - # In modern ubuntu versions, uname -r matches the kernel package name - uname = Mixlib::ShellOut.new('uname -r').run_command.stdout.strip - extra_package = 'linux-image-extra-' + uname + # In modern ubuntu versions, kernel release matches the kernel package name + package_name = 'linux-image-extra-' + node['kernel']['release'] end + extra_package = Mixlib::ShellOut.new('apt-cache search ' + package_name).run_command.stdout.split(' ').first.strip unless extra_package.empty? package extra_package do not_if 'modprobe -l | grep aufs' From 3cc505eaf741eb751aa630430102c096ce4b49b2 Mon Sep 17 00:00:00 2001 From: Jay Faulkner Date: Tue, 31 Dec 2013 16:43:47 -0800 Subject: [PATCH 3/3] fix(aufs): Use newer package finder only on saucy or newer --- README.md | 8 -------- attributes/default.rb | 3 --- recipes/aufs.rb | 8 +++++--- 3 files changed, 5 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index d926865512..8bbe03edf4 100644 --- a/README.md +++ b/README.md @@ -79,14 +79,6 @@ Attribute | Description | Type | Default ref | Repository reference for docker source | String | "master" url | Repository URL for docker source | String | "https://github.com/dotcloud/docker.git" -## AUFS Attributes - -These attributes are under the `node['docker']['aufs'] namespace. - -Attribute | Description | Type | Default -----------|-------------|------|-------- -legacy_package_finder | Use older method for determining kernel package name | Bool | false - ## Recipes * `recipe[docker]` Installs/Configures Docker diff --git a/attributes/default.rb b/attributes/default.rb index c7b7e35d5e..3a42975282 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -64,6 +64,3 @@ # Source attributes default['docker']['source']['ref'] = 'master' default['docker']['source']['url'] = 'https://github.com/dotcloud/docker.git' - -# linux-image-extras legacy support -default['docker']['aufs']['legacy_package_finder'] = false diff --git a/recipes/aufs.rb b/recipes/aufs.rb index f8b5226c60..e450264c50 100644 --- a/recipes/aufs.rb +++ b/recipes/aufs.rb @@ -1,7 +1,8 @@ case node['platform'] when 'ubuntu' # If aufs isn't available, do our best to install the correct linux-image-extra package. - if node['docker']['aufs']['legacy_package_finder'] + # Use kernel release for saucy and newer, otherwise use older, more compatible regexp match + if Gem::Version.new(node['platform_version']) < Gem::Version('13.10') # Original method copied from https://github.com/thoward/docker-cookbook/blob/master/recipes/default.rb package_name = 'linux-image-extra-' + Mixlib::ShellOut.new("uname -r | grep --only-matching -e [0-9]\.[0-9]\.[0-9]-[0-9]*").run_command.stdout.strip else @@ -9,9 +10,10 @@ package_name = 'linux-image-extra-' + node['kernel']['release'] end - extra_package = Mixlib::ShellOut.new('apt-cache search ' + package_name).run_command.stdout.split(' ').first.strip + extra_package = Mixlib::ShellOut.new('apt-cache search ' + package_name).run_command.stdout.split(' ').first + # Wait to strip until after checking for empty, to protect against nil errors unless extra_package.empty? - package extra_package do + package extra_package.strip do not_if 'modprobe -l | grep aufs' end end