From d2983d4fe4774efabd489575a2e7dfa190b6bd99 Mon Sep 17 00:00:00 2001 From: Jason Casden Date: Fri, 7 Aug 2015 13:44:08 -0400 Subject: [PATCH 1/5] Use official Docker installer and upgrade for :latest installs --- .../docker/cap/debian/docker_install.rb | 18 +++------------ .../docker/cap/redhat/docker_install.rb | 22 +++++++++++-------- plugins/provisioners/docker/installer.rb | 6 ++--- 3 files changed, 19 insertions(+), 27 deletions(-) diff --git a/plugins/provisioners/docker/cap/debian/docker_install.rb b/plugins/provisioners/docker/cap/debian/docker_install.rb index b9fbed673..d1dd0222a 100644 --- a/plugins/provisioners/docker/cap/debian/docker_install.rb +++ b/plugins/provisioners/docker/cap/debian/docker_install.rb @@ -4,26 +4,14 @@ module VagrantPlugins module Debian module DockerInstall def self.docker_install(machine, version) - package = 'lxc-docker' + package = 'docker-engine' package << "-#{version}" if version != :latest machine.communicate.tap do |comm| comm.sudo("apt-get update -y") - # TODO: Perform check on the host machine if aufs is installed and using LXC - if machine.provider_name != :lxc - # Attempt to install linux-image-extra for this kernel, if it exists - package_name = "linux-image-extra-`uname -r`" - comm.sudo("lsmod | grep aufs || modprobe aufs || apt-cache show #{package_name} && apt-get install -y #{package_name} || true") - end comm.sudo("apt-get install -y --force-yes -q curl") - comm.sudo("curl -sSL https://get.docker.com/gpg | apt-key add -") - comm.sudo("echo deb https://get.docker.com/ubuntu docker main > /etc/apt/sources.list.d/docker.list") - comm.sudo("apt-get update") - comm.sudo("echo lxc lxc/directory string /var/lib/lxc | debconf-set-selections") - comm.sudo("apt-get install -y --force-yes -q xz-utils #{package} -o Dpkg::Options::='--force-confdef' -o Dpkg::Options::='--force-confold'") - - # chmod the directory if it exists - comm.sudo("chmod 0755 /var/lib/docker") + comm.sudo("apt-get purge -y lxc-docker*") + comm.sudo("curl -sSL https://get.docker.com/ | sh") end end end diff --git a/plugins/provisioners/docker/cap/redhat/docker_install.rb b/plugins/provisioners/docker/cap/redhat/docker_install.rb index 2d6bd1e51..7afd30587 100644 --- a/plugins/provisioners/docker/cap/redhat/docker_install.rb +++ b/plugins/provisioners/docker/cap/redhat/docker_install.rb @@ -8,28 +8,32 @@ module VagrantPlugins machine.ui.warn(I18n.t("vagrant.docker_install_with_version_not_supported")) end + machine.communicate.tap do |comm| + comm.sudo("yum -y update") + comm.sudo("yum -y remove docker-io*") + comm.sudo("curl -sSL https://get.docker.com/ | sh") + end + case machine.guest.capability("flavor") + when :rhel_7 - docker_install_rhel7(machine) + docker_enable_rhel7(machine) else - docker_install_default(machine) + docker_enable_default(machine) end end - def self.docker_install_rhel7(machine) + def self.docker_enable_rhel7(machine) machine.communicate.tap do |comm| - comm.sudo("yum -y install docker") comm.sudo("systemctl start docker.service") comm.sudo("systemctl enable docker.service") end end - def self.docker_install_default(machine) + def self.docker_enable_default(machine) machine.communicate.tap do |comm| - if ! comm.test("rpm -qa | grep epel-release") - comm.sudo("rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm") - end - comm.sudo("yum -y install docker-io") + comm.sudo("service docker start") + comm.sudo("chkconfig docker on") end end end diff --git a/plugins/provisioners/docker/installer.rb b/plugins/provisioners/docker/installer.rb index cfcebdd43..b144ec1e6 100644 --- a/plugins/provisioners/docker/installer.rb +++ b/plugins/provisioners/docker/installer.rb @@ -15,10 +15,10 @@ module VagrantPlugins return end - if !@machine.guest.capability(:docker_installed) - @machine.ui.detail(I18n.t("vagrant.docker_installing", version: @version.to_s)) - @machine.guest.capability(:docker_install, @version) + @machine.ui.detail(I18n.t("vagrant.docker_installing", version: @version.to_s)) + @machine.guest.capability(:docker_install, @version) + if !@machine.guest.capability(:docker_installed) if !@machine.guest.capability(:docker_installed) raise DockerError, :install_failed end From 7076d192c9d00d6efa81916a2418a8fb6f0cc1a2 Mon Sep 17 00:00:00 2001 From: Jason Casden Date: Fri, 7 Aug 2015 14:12:38 -0400 Subject: [PATCH 2/5] Quiet package commands --- plugins/provisioners/docker/cap/debian/docker_install.rb | 9 +++------ plugins/provisioners/docker/cap/redhat/docker_install.rb | 4 ++-- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/plugins/provisioners/docker/cap/debian/docker_install.rb b/plugins/provisioners/docker/cap/debian/docker_install.rb index d1dd0222a..11f748632 100644 --- a/plugins/provisioners/docker/cap/debian/docker_install.rb +++ b/plugins/provisioners/docker/cap/debian/docker_install.rb @@ -4,13 +4,10 @@ module VagrantPlugins module Debian module DockerInstall def self.docker_install(machine, version) - package = 'docker-engine' - package << "-#{version}" if version != :latest - machine.communicate.tap do |comm| - comm.sudo("apt-get update -y") - comm.sudo("apt-get install -y --force-yes -q curl") - comm.sudo("apt-get purge -y lxc-docker*") + comm.sudo("apt-get update -qq -y") + comm.sudo("apt-get install -qq -y --force-yes curl") + comm.sudo("apt-get purge -qq -y lxc-docker*") comm.sudo("curl -sSL https://get.docker.com/ | sh") end end diff --git a/plugins/provisioners/docker/cap/redhat/docker_install.rb b/plugins/provisioners/docker/cap/redhat/docker_install.rb index 7afd30587..4f1756df9 100644 --- a/plugins/provisioners/docker/cap/redhat/docker_install.rb +++ b/plugins/provisioners/docker/cap/redhat/docker_install.rb @@ -9,8 +9,8 @@ module VagrantPlugins end machine.communicate.tap do |comm| - comm.sudo("yum -y update") - comm.sudo("yum -y remove docker-io*") + comm.sudo("yum -q -y update") + comm.sudo("yum -q -y remove docker-io*") comm.sudo("curl -sSL https://get.docker.com/ | sh") end From f5a0c3ed5bd201a084bb4c4410813c99a48d73bf Mon Sep 17 00:00:00 2001 From: Seth Vargo Date: Thu, 19 Nov 2015 17:45:16 -0800 Subject: [PATCH 3/5] Deprecate docker.version --- .../docker/cap/debian/docker_install.rb | 2 +- .../docker/cap/fedora/docker_install.rb | 6 +----- .../docker/cap/redhat/docker_install.rb | 7 +------ plugins/provisioners/docker/config.rb | 16 ++++++++++------ plugins/provisioners/docker/installer.rb | 7 +++---- plugins/provisioners/docker/provisioner.rb | 2 +- templates/locales/en.yml | 8 +------- .../plugins/provisioners/docker/config_test.rb | 13 ++++--------- .../docs/source/v2/provisioning/docker.html.md | 3 --- 9 files changed, 22 insertions(+), 42 deletions(-) diff --git a/plugins/provisioners/docker/cap/debian/docker_install.rb b/plugins/provisioners/docker/cap/debian/docker_install.rb index 11f748632..7b81df0f9 100644 --- a/plugins/provisioners/docker/cap/debian/docker_install.rb +++ b/plugins/provisioners/docker/cap/debian/docker_install.rb @@ -3,7 +3,7 @@ module VagrantPlugins module Cap module Debian module DockerInstall - def self.docker_install(machine, version) + def self.docker_install(machine) machine.communicate.tap do |comm| comm.sudo("apt-get update -qq -y") comm.sudo("apt-get install -qq -y --force-yes curl") diff --git a/plugins/provisioners/docker/cap/fedora/docker_install.rb b/plugins/provisioners/docker/cap/fedora/docker_install.rb index 16377f410..8feb5b0e2 100644 --- a/plugins/provisioners/docker/cap/fedora/docker_install.rb +++ b/plugins/provisioners/docker/cap/fedora/docker_install.rb @@ -3,11 +3,7 @@ module VagrantPlugins module Cap module Fedora module DockerInstall - def self.docker_install(machine, version) - if version != :latest - machine.ui.warn(I18n.t("vagrant.docker_install_with_version_not_supported")) - end - + def self.docker_install(machine) machine.communicate.tap do |comm| if dnf?(machine) comm.sudo("dnf -y install docker") diff --git a/plugins/provisioners/docker/cap/redhat/docker_install.rb b/plugins/provisioners/docker/cap/redhat/docker_install.rb index 4f1756df9..9324c8f5b 100644 --- a/plugins/provisioners/docker/cap/redhat/docker_install.rb +++ b/plugins/provisioners/docker/cap/redhat/docker_install.rb @@ -3,11 +3,7 @@ module VagrantPlugins module Cap module Redhat module DockerInstall - def self.docker_install(machine, version) - if version != :latest - machine.ui.warn(I18n.t("vagrant.docker_install_with_version_not_supported")) - end - + def self.docker_install(machine) machine.communicate.tap do |comm| comm.sudo("yum -q -y update") comm.sudo("yum -q -y remove docker-io*") @@ -15,7 +11,6 @@ module VagrantPlugins end case machine.guest.capability("flavor") - when :rhel_7 docker_enable_rhel7(machine) else diff --git a/plugins/provisioners/docker/config.rb b/plugins/provisioners/docker/config.rb index bcf4cf672..8e9de55da 100644 --- a/plugins/provisioners/docker/config.rb +++ b/plugins/provisioners/docker/config.rb @@ -4,11 +4,18 @@ module VagrantPlugins module DockerProvisioner class Config < Vagrant.plugin("2", :config) attr_reader :images - attr_accessor :version + + def version=(value) + STDOUT.puts <<-EOH +[DEPRECATED] The configuration `docker.version' has been deprecated. Docker no +longer allows you to specify the version of Docker you want installed and will +automatically choose the best version for your guest. Please remove this option +from your Vagrantfile. +EOH + end def initialize - @images = Set.new - @version = UNSET_VALUE + @images = Set.new @__build_images = [] @__containers = Hash.new { |h, k| h[k] = {} } @@ -65,9 +72,6 @@ module VagrantPlugins end def finalize! - @version = "latest" if @version == UNSET_VALUE - @version = @version.to_sym - @__containers.each do |name, params| params[:image] ||= name params[:auto_assign_name] = true if !params.key?(:auto_assign_name) diff --git a/plugins/provisioners/docker/installer.rb b/plugins/provisioners/docker/installer.rb index b144ec1e6..da71ed1a5 100644 --- a/plugins/provisioners/docker/installer.rb +++ b/plugins/provisioners/docker/installer.rb @@ -1,9 +1,8 @@ module VagrantPlugins module DockerProvisioner class Installer - def initialize(machine, version) + def initialize(machine) @machine = machine - @version = version end # This handles verifying the Docker installation, installing it if it was @@ -15,8 +14,8 @@ module VagrantPlugins return end - @machine.ui.detail(I18n.t("vagrant.docker_installing", version: @version.to_s)) - @machine.guest.capability(:docker_install, @version) + @machine.ui.detail(I18n.t("vagrant.docker_installing")) + @machine.guest.capability(:docker_install) if !@machine.guest.capability(:docker_installed) if !@machine.guest.capability(:docker_installed) diff --git a/plugins/provisioners/docker/provisioner.rb b/plugins/provisioners/docker/provisioner.rb index 8b9d609a3..aa4aca27e 100644 --- a/plugins/provisioners/docker/provisioner.rb +++ b/plugins/provisioners/docker/provisioner.rb @@ -11,7 +11,7 @@ module VagrantPlugins def initialize(machine, config, installer = nil, client = nil) super(machine, config) - @installer = installer || Installer.new(@machine, config.version) + @installer = installer || Installer.new(@machine) @client = client || Client.new(@machine) end diff --git a/templates/locales/en.yml b/templates/locales/en.yml index 10fee4f09..3367c500a 100755 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -123,14 +123,8 @@ en: installed and attempt to continue. docker_configure_autostart: |- Configuring Docker to autostart containers... - docker_install_with_version_not_supported: |- - Vagrant is not capable of installing a specific version of Docker - onto the guest machine and the latest version will be installed. - This is a limitation of Vagrant knowing how to interact with this - operating system. This isn't a bug, but if you know how to fix this - please report it to Vagrant. docker_installing: |- - Installing Docker (%{version}) onto machine... + Installing Docker onto machine... docker_pulling_images: Pulling Docker images... docker_pulling_single: |- diff --git a/test/unit/plugins/provisioners/docker/config_test.rb b/test/unit/plugins/provisioners/docker/config_test.rb index e12f883c4..ba2b6836d 100644 --- a/test/unit/plugins/provisioners/docker/config_test.rb +++ b/test/unit/plugins/provisioners/docker/config_test.rb @@ -139,15 +139,10 @@ describe VagrantPlugins::DockerProvisioner::Config do end describe "#version" do - it "defaults to latest" do - subject.finalize! - expect(subject.version).to eql(:latest) - end - - it "converts to a symbol" do - subject.version = "v27" - subject.finalize! - expect(subject.version).to eql(:v27) + it "is removed in Vagrant 1.9" do + if Vagrant::VERSION >= "1.9" + raise "Remove deprecated option" + end end end end diff --git a/website/docs/source/v2/provisioning/docker.html.md b/website/docs/source/v2/provisioning/docker.html.md index 0e03ec660..cb0d526fd 100644 --- a/website/docs/source/v2/provisioning/docker.html.md +++ b/website/docs/source/v2/provisioning/docker.html.md @@ -42,9 +42,6 @@ for you (if it isn't already installed). can also use the `pull_images` function. See the example below this section for more information. -* `version` (string) - The version of Docker to install. This defaults to - "latest" and will install the latest version of Docker. - In addition to the options that can be set, various functions are available and can be called to configure other aspects of the Docker provisioner. Most of these functions have examples in more detailed sections below. From bad4c2103d4cd56bb3ef57c76fc58e1360762389 Mon Sep 17 00:00:00 2001 From: Seth Vargo Date: Thu, 19 Nov 2015 18:25:28 -0800 Subject: [PATCH 4/5] Only install Docker if it is not already installed --- plugins/provisioners/docker/installer.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/plugins/provisioners/docker/installer.rb b/plugins/provisioners/docker/installer.rb index da71ed1a5..3f2ae95ad 100644 --- a/plugins/provisioners/docker/installer.rb +++ b/plugins/provisioners/docker/installer.rb @@ -14,13 +14,13 @@ module VagrantPlugins return end - @machine.ui.detail(I18n.t("vagrant.docker_installing")) - @machine.guest.capability(:docker_install) + if !@machine.guest.capability(:docker_installed) + @machine.ui.detail(I18n.t("vagrant.docker_installing")) + @machine.guest.capability(:docker_install) + end if !@machine.guest.capability(:docker_installed) - if !@machine.guest.capability(:docker_installed) - raise DockerError, :install_failed - end + raise DockerError, :install_failed end if @machine.guest.capability?(:docker_configure_vagrant_user) From 1b08cfcd0945d1f7c2273d9c56d90a1e456d26aa Mon Sep 17 00:00:00 2001 From: Seth Vargo Date: Thu, 19 Nov 2015 18:34:31 -0800 Subject: [PATCH 5/5] Do not fail if uninstalling lxc/docker-io fails --- plugins/provisioners/docker/cap/debian/docker_install.rb | 2 +- plugins/provisioners/docker/cap/redhat/docker_install.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/provisioners/docker/cap/debian/docker_install.rb b/plugins/provisioners/docker/cap/debian/docker_install.rb index 7b81df0f9..33724f673 100644 --- a/plugins/provisioners/docker/cap/debian/docker_install.rb +++ b/plugins/provisioners/docker/cap/debian/docker_install.rb @@ -7,7 +7,7 @@ module VagrantPlugins machine.communicate.tap do |comm| comm.sudo("apt-get update -qq -y") comm.sudo("apt-get install -qq -y --force-yes curl") - comm.sudo("apt-get purge -qq -y lxc-docker*") + comm.sudo("apt-get purge -qq -y lxc-docker* || true") comm.sudo("curl -sSL https://get.docker.com/ | sh") end end diff --git a/plugins/provisioners/docker/cap/redhat/docker_install.rb b/plugins/provisioners/docker/cap/redhat/docker_install.rb index 9324c8f5b..0a6868b8b 100644 --- a/plugins/provisioners/docker/cap/redhat/docker_install.rb +++ b/plugins/provisioners/docker/cap/redhat/docker_install.rb @@ -6,7 +6,7 @@ module VagrantPlugins def self.docker_install(machine) machine.communicate.tap do |comm| comm.sudo("yum -q -y update") - comm.sudo("yum -q -y remove docker-io*") + comm.sudo("yum -q -y remove docker-io* || true") comm.sudo("curl -sSL https://get.docker.com/ | sh") end