diff --git a/README.md b/README.md index 8d1568570d..5759a3a7e0 100644 --- a/README.md +++ b/README.md @@ -108,6 +108,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 diff --git a/attributes/default.rb b/attributes/default.rb index 8e8c251cf0..f9aacfbd25 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -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 diff --git a/files/default/tests/minitest/upstart_test.rb b/files/default/tests/minitest/upstart_test.rb index a255d262f8..a4c54c862b 100644 --- a/files/default/tests/minitest/upstart_test.rb +++ b/files/default/tests/minitest/upstart_test.rb @@ -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 diff --git a/libraries/helpers.rb b/libraries/helpers.rb index c73ee611d8..82854d0ccd 100644 --- a/libraries/helpers.rb +++ b/libraries/helpers.rb @@ -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'], diff --git a/recipes/package.rb b/recipes/package.rb index 89be058407..c760fccd4e 100644 --- a/recipes/package.rb +++ b/recipes/package.rb @@ -1,3 +1,4 @@ + case node['platform'] when 'amazon' package 'docker' do @@ -12,21 +13,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 diff --git a/recipes/upstart.rb b/recipes/upstart.rb index 0ddb1a01d6..6f7e09f8f6 100644 --- a/recipes/upstart.rb +++ b/recipes/upstart.rb @@ -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' @@ -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] diff --git a/spec/upstart_spec.rb b/spec/upstart_spec.rb index 0a8bb41add..6a2b93add5 100644 --- a/spec/upstart_spec.rb +++ b/spec/upstart_spec.rb @@ -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 diff --git a/templates/default/docker.conf.erb b/templates/default/docker.conf.erb index 9a3706c175..5690b42a65 100644 --- a/templates/default/docker.conf.erb +++ b/templates/default/docker.conf.erb @@ -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