Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

address bflad/chef-docker #137 and support that trusty tahr. #138

Merged
merged 5 commits into from
May 7, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ Attribute | Description | Type | Default
----------|-------------|------|--------
distribution | Distribution for docker packages | String | auto-detected (see attributes/default.rb)
repo_url | Repository URL for docker packages | String | auto-detected (see attributes/default.rb)
use_docker_io_ppa | Use the docker.io package repository (can be set to false on Ubuntu 14.04+) | TrueClass, FalseClass | true

#### Source Installation Attributes

Expand Down
4 changes: 4 additions & 0 deletions attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@
default['docker']['package']['distribution'] = 'docker'
default['docker']['package']['repo_url'] = 'https://get.docker.io/ubuntu'
default['docker']['package']['repo_key'] = 'https://get.docker.io/gpg'
# this currently only has meaning on ubuntu >= 14.04
# if you want to use the ubuntu provided package / repository
# override this attribute to false
default['docker']['package']['use_docker_io_ppa'] = true
end

## Source installation attributes
Expand Down
6 changes: 5 additions & 1 deletion files/default/tests/minitest/upstart_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
include Helpers::Docker

it 'starts docker' do
service('docker').must_be_running
if Helpers::Docker.use_docker_ppa? node
service('docker').must_be_running
else
service('docker.io').must_be_running
end
end
end
10 changes: 10 additions & 0 deletions libraries/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ def initialize(timeout)
# Exception to signify that the docker command timed out.
class CommandTimeout < RuntimeError; end

# Boolean to determine whether or not we are using the docker ppa
def self.use_docker_ppa?(node)
! (
node['platform'] == 'ubuntu' &&
node['docker']['install_type'] == 'package' &&
node['docker']['package']['use_docker_io_ppa'] == false &&
Chef::VersionConstraint.new('>= 14.04').include?(node['platform_version'])
)
end

def self.daemon_cli_args(node)
daemon_options = Helpers::Docker.cli_args(
'api-enable-cors' => node['docker']['api_enable_cors'],
Expand Down
22 changes: 16 additions & 6 deletions recipes/package.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

case node['platform']
when 'centos', 'redhat'
include_recipe 'yum-epel'
Expand All @@ -7,21 +8,30 @@
action node['docker']['package']['action'].intern
end
when 'debian', 'ubuntu'
apt_repository 'docker' do
uri node['docker']['package']['repo_url']
distribution node['docker']['package']['distribution']
components ['main']
key node['docker']['package']['repo_key']
if Helpers::Docker.use_docker_ppa? node
p = 'lxc-docker'
apt_repository 'docker' do
uri node['docker']['package']['repo_url']
distribution node['docker']['package']['distribution']
components ['main']
key node['docker']['package']['repo_key']
end
else
p = 'docker.io'
link '/usr/local/bin/docker' do
action :nothing
to '/usr/bin/docker.io'
end
end

# reprepro doesn't support version tagging
# See: https://github.com/dotcloud/docker/issues/979
p = 'lxc-docker'
p += "-#{node['docker']['version']}" if node['docker']['version']

package p do
options '--force-yes -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold"'
action node['docker']['package']['action'].intern
notifies :create, 'link[/usr/local/bin/docker]', :immediately unless Helpers::Docker.use_docker_ppa? node
end
when 'fedora'
package 'docker-io' do
Expand Down
40 changes: 32 additions & 8 deletions recipes/upstart.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,41 @@
settings_file =
def docker_settings_file
case node['platform']
when 'debian', 'ubuntu' then '/etc/default/docker'
else '/etc/sysconfig/docker'
when 'debian'
'/etc/default/docker'
when 'ubuntu'
if Helpers::Docker.use_docker_ppa? node
'/etc/default/docker'
else
'/etc/default/docker.io'
end
else
'/etc/sysconfig/docker'
end
end

def docker_upstart_conf_file
case node['platform']
when 'ubuntu'
if Helpers::Docker.use_docker_ppa? node
'/etc/init/docker.conf'
else
'/etc/init/docker.io.conf'
end
else
'/etc/init/docker.conf'
end
end

docker_service_name = ::File.basename(docker_upstart_conf_file, '.conf')

template '/etc/init/docker.conf' do
template docker_upstart_conf_file do
source 'docker.conf.erb'
mode '0600'
owner 'root'
group 'root'
end

template settings_file do
template docker_settings_file do
source 'docker.sysconfig.erb'
mode '0644'
owner 'root'
Expand All @@ -21,11 +45,11 @@
)
# DEPRECATED: stop and start only necessary for 0.x cookbook upgrades
# Default docker Upstart job now sources default file for DOCKER_OPTS
notifies :stop, 'service[docker]', :immediately
notifies :start, 'service[docker]', :immediately
notifies :stop, "service[#{docker_service_name}]", :immediately
notifies :start, "service[#{docker_service_name}]", :immediately
end

service 'docker' do
service docker_service_name do
provider Chef::Provider::Service::Upstart
supports :status => true, :restart => true, :reload => true
action [:start]
Expand Down
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# TODO: Figure out a better way to do this - couldn't get stubbing to work (see below)
# Kernel module
module Kernel
def system(cmd)
def system(*)
true
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/upstart_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
it 'creates the docker Upstart template' do
expect(chef_run).to create_template('/etc/init/docker.conf')
expect(chef_run).to render_file('/etc/init/docker.conf').with_content(
/"\$DOCKER" -d \$DOCKER_OPTS/)
/"\$UPSTART_JOB" -d \$DOCKER_OPTS/)
end

it 'creates the docker sysconfig template' do
Expand Down
2 changes: 1 addition & 1 deletion templates/default/docker.conf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@ script
if [ -f /etc/default/$UPSTART_JOB ]; then
. /etc/default/$UPSTART_JOB
fi
"$DOCKER" -d $DOCKER_OPTS
"$UPSTART_JOB" -d $DOCKER_OPTS
end script