From 9d53e8ccab77c319ec9e9276ea52948f6ccbae09 Mon Sep 17 00:00:00 2001 From: sophia Date: Wed, 25 Mar 2020 10:36:02 -0400 Subject: [PATCH 1/8] Recognize rhel8 flavor --- plugins/guests/redhat/cap/flavor.rb | 2 ++ test/unit/plugins/guests/redhat/cap/flavor_test.rb | 3 +++ 2 files changed, 5 insertions(+) diff --git a/plugins/guests/redhat/cap/flavor.rb b/plugins/guests/redhat/cap/flavor.rb index 32dc1a7c2..544af5412 100644 --- a/plugins/guests/redhat/cap/flavor.rb +++ b/plugins/guests/redhat/cap/flavor.rb @@ -12,6 +12,8 @@ module VagrantPlugins # Detect various flavors we care about if output =~ /(CentOS|Red Hat Enterprise|Scientific|Cloud|Virtuozzo)\s*Linux( .+)? release 7/i return :rhel_7 + elsif output =~ /(CentOS|Red Hat Enterprise|Scientific|Cloud|Virtuozzo)\s*Linux( .+)? release 8/i + return :rhel_8 else return :rhel end diff --git a/test/unit/plugins/guests/redhat/cap/flavor_test.rb b/test/unit/plugins/guests/redhat/cap/flavor_test.rb index c711495fa..df890783f 100644 --- a/test/unit/plugins/guests/redhat/cap/flavor_test.rb +++ b/test/unit/plugins/guests/redhat/cap/flavor_test.rb @@ -27,6 +27,9 @@ describe "VagrantPlugins::GuestRedHat::Cap::Flavor" do "Scientific Linux release 7" => :rhel_7, "CloudLinux release 7.2 (Valeri Kubasov)" => :rhel_7, + "CentOS Linux release 8.1.1911 (Core)" => :rhel_8, + "Red Hat Enterprise Linux release 8" => :rhel_8, + "CentOS" => :rhel, "RHEL 6" => :rhel, "banana" => :rhel, From 60b05426e18c095aa428fe1866011950a668133d Mon Sep 17 00:00:00 2001 From: sophia Date: Wed, 25 Mar 2020 10:40:31 -0400 Subject: [PATCH 2/8] Install containerd.io from docker on rhel_8 containerd.io is required for docker howerver it is not avilable in official yum repos. It needs to be installed directly from docker. ref: https://docs.docker.com/install/linux/docker-ce/centos/ https://linuxconfig.org/how-to-install-docker-in-rhel-8 --- plugins/provisioners/docker/cap/redhat/docker_install.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/plugins/provisioners/docker/cap/redhat/docker_install.rb b/plugins/provisioners/docker/cap/redhat/docker_install.rb index 0a6868b8b..c3d7f410b 100644 --- a/plugins/provisioners/docker/cap/redhat/docker_install.rb +++ b/plugins/provisioners/docker/cap/redhat/docker_install.rb @@ -7,7 +7,12 @@ module VagrantPlugins machine.communicate.tap do |comm| comm.sudo("yum -q -y update") comm.sudo("yum -q -y remove docker-io* || true") - comm.sudo("curl -sSL https://get.docker.com/ | sh") + if machine.guest.capability("flavor") == :rhel_8 + # containerd.io is not available on official yum repos + # install it directly from docker + comm.sudo("yum -y install https://download.docker.com/linux/centos/7/x86_64/stable/Packages/containerd.io-1.2.6-3.3.el7.x86_64.rpm") + end + comm.sudo("curl -fsSL https://get.docker.com/ | sh") end case machine.guest.capability("flavor") From f7d6070b0d67cd0537546552364fab5c8f6a462f Mon Sep 17 00:00:00 2001 From: sophia Date: Fri, 27 Mar 2020 09:42:13 -0400 Subject: [PATCH 3/8] Raise error when trying to install docker on centos8 --- .../provisioners/docker/cap/redhat/docker_install.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/plugins/provisioners/docker/cap/redhat/docker_install.rb b/plugins/provisioners/docker/cap/redhat/docker_install.rb index c3d7f410b..76555749b 100644 --- a/plugins/provisioners/docker/cap/redhat/docker_install.rb +++ b/plugins/provisioners/docker/cap/redhat/docker_install.rb @@ -4,14 +4,14 @@ module VagrantPlugins module Redhat module DockerInstall def self.docker_install(machine) + if machine.guest.capability("flavor") == :rhel_8 + machine.ui.warn("Docker is not supported on RHEL 8 machines.") + raise DockerError, :install_failed + end + machine.communicate.tap do |comm| comm.sudo("yum -q -y update") comm.sudo("yum -q -y remove docker-io* || true") - if machine.guest.capability("flavor") == :rhel_8 - # containerd.io is not available on official yum repos - # install it directly from docker - comm.sudo("yum -y install https://download.docker.com/linux/centos/7/x86_64/stable/Packages/containerd.io-1.2.6-3.3.el7.x86_64.rpm") - end comm.sudo("curl -fsSL https://get.docker.com/ | sh") end From d87d421586bbf06268f2e1acc9d106046d398be6 Mon Sep 17 00:00:00 2001 From: sophia Date: Fri, 27 Mar 2020 10:12:43 -0400 Subject: [PATCH 4/8] Install docker using docker repo instead of convenience script This approach will be more stable than depending on a convenience script provided by docker ref: https://docs.docker.com/install/linux/docker-ce/ubuntu/#install-using-the-convenience-script --- .../provisioners/docker/cap/redhat/docker_install.rb | 10 +++++++--- templates/locales/en.yml | 3 +++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/plugins/provisioners/docker/cap/redhat/docker_install.rb b/plugins/provisioners/docker/cap/redhat/docker_install.rb index 76555749b..027864304 100644 --- a/plugins/provisioners/docker/cap/redhat/docker_install.rb +++ b/plugins/provisioners/docker/cap/redhat/docker_install.rb @@ -4,15 +4,19 @@ module VagrantPlugins module Redhat module DockerInstall def self.docker_install(machine) + machine.ui.warn(I18n.t("vagrant.provisioners.docker.rhel_not_supported")) + if machine.guest.capability("flavor") == :rhel_8 - machine.ui.warn("Docker is not supported on RHEL 8 machines.") raise DockerError, :install_failed end - + machine.communicate.tap do |comm| comm.sudo("yum -q -y update") comm.sudo("yum -q -y remove docker-io* || true") - comm.sudo("curl -fsSL https://get.docker.com/ | sh") + comm.sudo("yum install -y -q yum-utils") + comm.sudo("yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo") + comm.sudo("yum makecache") + comm.sudo("yum install -y -q docker-ce") end case machine.guest.capability("flavor") diff --git a/templates/locales/en.yml b/templates/locales/en.yml index 743be4761..a9481fd12 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -2821,6 +2821,9 @@ en: provisioner not_running: "Docker is not running on the guest VM." install_failed: "Docker installation failed." + rhel_not_supported: |- + RHEL is now only supported by Docker EE. Please install Docker EE or + switch to the Podman provisioner to run containers on RHEL. salt: minion_config_nonexist: |- From d500daea030ceebd5d7e33b8daf4fac8390e486d Mon Sep 17 00:00:00 2001 From: sophia Date: Fri, 3 Apr 2020 14:27:44 -0400 Subject: [PATCH 5/8] Support centos flavors of redhat --- plugins/guests/redhat/cap/flavor.rb | 10 ++++++++-- test/unit/plugins/guests/redhat/cap/flavor_test.rb | 6 +++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/plugins/guests/redhat/cap/flavor.rb b/plugins/guests/redhat/cap/flavor.rb index 544af5412..b1187bd09 100644 --- a/plugins/guests/redhat/cap/flavor.rb +++ b/plugins/guests/redhat/cap/flavor.rb @@ -10,9 +10,15 @@ module VagrantPlugins end # Detect various flavors we care about - if output =~ /(CentOS|Red Hat Enterprise|Scientific|Cloud|Virtuozzo)\s*Linux( .+)? release 7/i + if output =~ /(CentOS)( .+)? 7/i + return :centos_7 + elsif output =~ /(CentOS)( .+)? 8/i + return :centos_8 + elsif output =~ /(CentOS)( .+)?/i + return :centos + elsif output =~ /(Red Hat Enterprise|Scientific|Cloud|Virtuozzo)\s*Linux( .+)? release 7/i return :rhel_7 - elsif output =~ /(CentOS|Red Hat Enterprise|Scientific|Cloud|Virtuozzo)\s*Linux( .+)? release 8/i + elsif output =~ /(Red Hat Enterprise|Scientific|Cloud|Virtuozzo)\s*Linux( .+)? release 8/i return :rhel_8 else return :rhel diff --git a/test/unit/plugins/guests/redhat/cap/flavor_test.rb b/test/unit/plugins/guests/redhat/cap/flavor_test.rb index df890783f..0aa26943e 100644 --- a/test/unit/plugins/guests/redhat/cap/flavor_test.rb +++ b/test/unit/plugins/guests/redhat/cap/flavor_test.rb @@ -22,15 +22,15 @@ describe "VagrantPlugins::GuestRedHat::Cap::Flavor" do let(:cap) { caps.get(:flavor) } { - "CentOS Linux 2.4 release 7" => :rhel_7, + "CentOS Linux 2.4 release 7" => :centos_7, "Red Hat Enterprise Linux release 7" => :rhel_7, "Scientific Linux release 7" => :rhel_7, "CloudLinux release 7.2 (Valeri Kubasov)" => :rhel_7, - "CentOS Linux release 8.1.1911 (Core)" => :rhel_8, + "CentOS Linux release 8.1.1911 (Core)" => :centos_8, "Red Hat Enterprise Linux release 8" => :rhel_8, - "CentOS" => :rhel, + "CentOS" => :centos, "RHEL 6" => :rhel, "banana" => :rhel, }.each do |str, expected| From 311fb035e6836b39efa23aa691b6189fabb7f8a0 Mon Sep 17 00:00:00 2001 From: sophia Date: Fri, 3 Apr 2020 15:14:03 -0400 Subject: [PATCH 6/8] Don't install docker on RHEL Docker CE is not supported on RHEL. It is supported on CentOS --- .../docker/cap/redhat/docker_install.rb | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/plugins/provisioners/docker/cap/redhat/docker_install.rb b/plugins/provisioners/docker/cap/redhat/docker_install.rb index 027864304..64ba934b4 100644 --- a/plugins/provisioners/docker/cap/redhat/docker_install.rb +++ b/plugins/provisioners/docker/cap/redhat/docker_install.rb @@ -4,9 +4,11 @@ module VagrantPlugins module Redhat module DockerInstall def self.docker_install(machine) - machine.ui.warn(I18n.t("vagrant.provisioners.docker.rhel_not_supported")) - - if machine.guest.capability("flavor") == :rhel_8 + flavor = machine.guest.capability("flavor") + if flavor.to_s.include? "rhel" + # rhel is not supported by docker ce + # https://docs.docker.com/ee/docker-ee/rhel/ + machine.ui.warn(I18n.t("vagrant.provisioners.docker.rhel_not_supported")) raise DockerError, :install_failed end @@ -19,15 +21,15 @@ module VagrantPlugins comm.sudo("yum install -y -q docker-ce") end - case machine.guest.capability("flavor") - when :rhel_7 - docker_enable_rhel7(machine) + case flavor + when :centos_7 + docker_enable_centos7(machine) else docker_enable_default(machine) end end - def self.docker_enable_rhel7(machine) + def self.docker_enable_centos7(machine) machine.communicate.tap do |comm| comm.sudo("systemctl start docker.service") comm.sudo("systemctl enable docker.service") From 5104d075bdeb8670db7aff6c8247506e6ca28a63 Mon Sep 17 00:00:00 2001 From: sophia Date: Mon, 6 Apr 2020 10:53:22 -0400 Subject: [PATCH 7/8] Add CentOS guest plugin --- plugins/guests/centos/cap/flavor.rb | 24 ++++++++++++ plugins/guests/centos/guest.rb | 9 +++++ plugins/guests/centos/plugin.rb | 20 ++++++++++ plugins/guests/redhat/cap/flavor.rb | 8 +--- .../plugins/guests/centos/cap/flavor_test.rb | 37 +++++++++++++++++++ .../plugins/guests/redhat/cap/flavor_test.rb | 6 +-- 6 files changed, 94 insertions(+), 10 deletions(-) create mode 100644 plugins/guests/centos/cap/flavor.rb create mode 100644 plugins/guests/centos/guest.rb create mode 100644 plugins/guests/centos/plugin.rb create mode 100644 test/unit/plugins/guests/centos/cap/flavor_test.rb diff --git a/plugins/guests/centos/cap/flavor.rb b/plugins/guests/centos/cap/flavor.rb new file mode 100644 index 000000000..dfaeb3263 --- /dev/null +++ b/plugins/guests/centos/cap/flavor.rb @@ -0,0 +1,24 @@ +module VagrantPlugins + module GuestCentos + module Cap + class Flavor + def self.flavor(machine) + # Read the version file + output = "" + machine.communicate.sudo("cat /etc/centos-release") do |_, data| + output = data + end + + # Detect various flavors we care about + if output =~ /(CentOS)( .+)? 7/i + return :centos_7 + elsif output =~ /(CentOS)( .+)? 8/i + return :centos_8 + else + return :centos + end + end + end + end + end +end diff --git a/plugins/guests/centos/guest.rb b/plugins/guests/centos/guest.rb new file mode 100644 index 000000000..f62a6bd59 --- /dev/null +++ b/plugins/guests/centos/guest.rb @@ -0,0 +1,9 @@ +module VagrantPlugins + module GuestCentos + class Guest < Vagrant.plugin("2", :guest) + def detect?(machine) + machine.communicate.test("cat /etc/centos-release") + end + end + end +end diff --git a/plugins/guests/centos/plugin.rb b/plugins/guests/centos/plugin.rb new file mode 100644 index 000000000..fc07dafd6 --- /dev/null +++ b/plugins/guests/centos/plugin.rb @@ -0,0 +1,20 @@ +require "vagrant" + +module VagrantPlugins + module GuestCentos + class Plugin < Vagrant.plugin("2") + name "CentOS guest" + description "CentOS guest support." + + guest(:centos, :redhat) do + require_relative "guest" + Guest + end + + guest_capability(:centos, :flavor) do + require_relative "cap/flavor" + Cap::Flavor + end + end + end +end diff --git a/plugins/guests/redhat/cap/flavor.rb b/plugins/guests/redhat/cap/flavor.rb index b1187bd09..bfe13d377 100644 --- a/plugins/guests/redhat/cap/flavor.rb +++ b/plugins/guests/redhat/cap/flavor.rb @@ -10,13 +10,7 @@ module VagrantPlugins end # Detect various flavors we care about - if output =~ /(CentOS)( .+)? 7/i - return :centos_7 - elsif output =~ /(CentOS)( .+)? 8/i - return :centos_8 - elsif output =~ /(CentOS)( .+)?/i - return :centos - elsif output =~ /(Red Hat Enterprise|Scientific|Cloud|Virtuozzo)\s*Linux( .+)? release 7/i + if output =~ /(Red Hat Enterprise|Scientific|Cloud|Virtuozzo)\s*Linux( .+)? release 7/i return :rhel_7 elsif output =~ /(Red Hat Enterprise|Scientific|Cloud|Virtuozzo)\s*Linux( .+)? release 8/i return :rhel_8 diff --git a/test/unit/plugins/guests/centos/cap/flavor_test.rb b/test/unit/plugins/guests/centos/cap/flavor_test.rb new file mode 100644 index 000000000..b3bc89cb6 --- /dev/null +++ b/test/unit/plugins/guests/centos/cap/flavor_test.rb @@ -0,0 +1,37 @@ +require_relative "../../../../base" + +describe "VagrantPlugins::GuestCentos::Cap::Flavor" do + let(:caps) do + VagrantPlugins::GuestCentos::Plugin + .components + .guest_capabilities[:centos] + end + + let(:machine) { double("machine") } + let(:comm) { VagrantTests::DummyCommunicator::Communicator.new(machine) } + + before do + allow(machine).to receive(:communicate).and_return(comm) + end + + after do + comm.verify_expectations! + end + + describe ".flavor" do + let(:cap) { caps.get(:flavor) } + + { + "CentOS Linux 2.4 release 7" => :centos_7, + "CentOS Linux release 8.1.1911 (Core)" => :centos_8, + + "CentOS" => :centos, + "banana" => :centos, + }.each do |str, expected| + it "returns #{expected} for #{str}" do + comm.stub_command("cat /etc/centos-release", stdout: str) + expect(cap.flavor(machine)).to be(expected) + end + end + end +end diff --git a/test/unit/plugins/guests/redhat/cap/flavor_test.rb b/test/unit/plugins/guests/redhat/cap/flavor_test.rb index 0aa26943e..1676d54f2 100644 --- a/test/unit/plugins/guests/redhat/cap/flavor_test.rb +++ b/test/unit/plugins/guests/redhat/cap/flavor_test.rb @@ -22,15 +22,15 @@ describe "VagrantPlugins::GuestRedHat::Cap::Flavor" do let(:cap) { caps.get(:flavor) } { - "CentOS Linux 2.4 release 7" => :centos_7, + "Red Hat Enterprise Linux 2.4 release 7" => :rhel_7, "Red Hat Enterprise Linux release 7" => :rhel_7, "Scientific Linux release 7" => :rhel_7, "CloudLinux release 7.2 (Valeri Kubasov)" => :rhel_7, - "CentOS Linux release 8.1.1911 (Core)" => :centos_8, + "CloudLinux release 8.1.1911 (Valeri Kubasov)" => :rhel_8, "Red Hat Enterprise Linux release 8" => :rhel_8, - "CentOS" => :centos, + "Red Hat Enterprise Linux" => :rhel, "RHEL 6" => :rhel, "banana" => :rhel, }.each do |str, expected| From e61725a1308a6f4f930050b723eb1d9bdcfe3a0a Mon Sep 17 00:00:00 2001 From: sophia Date: Mon, 6 Apr 2020 11:05:43 -0400 Subject: [PATCH 8/8] Docker provision to support centos guest, not RHEL guest --- .../cap/{redhat => centos}/docker_install.rb | 22 ++++++----------- .../docker/cap/centos/docker_start_service.rb | 24 +++++++++++++++++++ .../docker/cap/redhat/docker_start_service.rb | 16 ------------- plugins/provisioners/docker/plugin.rb | 8 +++---- templates/locales/en.yml | 3 --- 5 files changed, 35 insertions(+), 38 deletions(-) rename plugins/provisioners/docker/cap/{redhat => centos}/docker_install.rb (62%) create mode 100644 plugins/provisioners/docker/cap/centos/docker_start_service.rb delete mode 100644 plugins/provisioners/docker/cap/redhat/docker_start_service.rb diff --git a/plugins/provisioners/docker/cap/redhat/docker_install.rb b/plugins/provisioners/docker/cap/centos/docker_install.rb similarity index 62% rename from plugins/provisioners/docker/cap/redhat/docker_install.rb rename to plugins/provisioners/docker/cap/centos/docker_install.rb index 64ba934b4..a755320f3 100644 --- a/plugins/provisioners/docker/cap/redhat/docker_install.rb +++ b/plugins/provisioners/docker/cap/centos/docker_install.rb @@ -1,17 +1,9 @@ module VagrantPlugins module DockerProvisioner module Cap - module Redhat + module Centos module DockerInstall def self.docker_install(machine) - flavor = machine.guest.capability("flavor") - if flavor.to_s.include? "rhel" - # rhel is not supported by docker ce - # https://docs.docker.com/ee/docker-ee/rhel/ - machine.ui.warn(I18n.t("vagrant.provisioners.docker.rhel_not_supported")) - raise DockerError, :install_failed - end - machine.communicate.tap do |comm| comm.sudo("yum -q -y update") comm.sudo("yum -q -y remove docker-io* || true") @@ -21,22 +13,22 @@ module VagrantPlugins comm.sudo("yum install -y -q docker-ce") end - case flavor - when :centos_7 - docker_enable_centos7(machine) + case machine.guest.capability("flavor") + when :centos + docker_enable_service(machine) else - docker_enable_default(machine) + docker_enable_systemctl(machine) end end - def self.docker_enable_centos7(machine) + def self.docker_enable_systemctl(machine) machine.communicate.tap do |comm| comm.sudo("systemctl start docker.service") comm.sudo("systemctl enable docker.service") end end - def self.docker_enable_default(machine) + def self.docker_enable_service(machine) machine.communicate.tap do |comm| comm.sudo("service docker start") comm.sudo("chkconfig docker on") diff --git a/plugins/provisioners/docker/cap/centos/docker_start_service.rb b/plugins/provisioners/docker/cap/centos/docker_start_service.rb new file mode 100644 index 000000000..116d86fca --- /dev/null +++ b/plugins/provisioners/docker/cap/centos/docker_start_service.rb @@ -0,0 +1,24 @@ +module VagrantPlugins + module DockerProvisioner + module Cap + module Centos + module DockerStartService + def self.docker_start_service(machine) + case machine.guest.capability("flavor") + when :centos + machine.communicate.tap do |comm| + comm.sudo("service docker start") + comm.sudo("chkconfig docker on") + end + else + machine.communicate.tap do |comm| + comm.sudo("systemctl start docker.service") + comm.sudo("systemctl enable docker.service") + end + end + end + end + end + end + end +end diff --git a/plugins/provisioners/docker/cap/redhat/docker_start_service.rb b/plugins/provisioners/docker/cap/redhat/docker_start_service.rb deleted file mode 100644 index 2e7662f00..000000000 --- a/plugins/provisioners/docker/cap/redhat/docker_start_service.rb +++ /dev/null @@ -1,16 +0,0 @@ -module VagrantPlugins - module DockerProvisioner - module Cap - module Redhat - module DockerStartService - def self.docker_start_service(machine) - machine.communicate.sudo("service docker start") - # TODO :: waiting to start - sleep 5 - machine.communicate.sudo("chkconfig docker on") - end - end - end - end - end -end diff --git a/plugins/provisioners/docker/plugin.rb b/plugins/provisioners/docker/plugin.rb index 6de03e727..e761ae400 100644 --- a/plugins/provisioners/docker/plugin.rb +++ b/plugins/provisioners/docker/plugin.rb @@ -29,14 +29,14 @@ module VagrantPlugins Cap::Fedora::DockerInstall end - guest_capability("redhat", "docker_install") do + guest_capability("centos", "docker_install") do require_relative "cap/redhat/docker_install" - Cap::Redhat::DockerInstall + Cap::Centos::DockerInstall end - guest_capability("redhat", "docker_start_service") do + guest_capability("centos", "docker_start_service") do require_relative "cap/redhat/docker_start_service" - Cap::Redhat::DockerStartService + Cap::Centos::DockerStartService end guest_capability("linux", "docker_installed") do diff --git a/templates/locales/en.yml b/templates/locales/en.yml index a9481fd12..743be4761 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -2821,9 +2821,6 @@ en: provisioner not_running: "Docker is not running on the guest VM." install_failed: "Docker installation failed." - rhel_not_supported: |- - RHEL is now only supported by Docker EE. Please install Docker EE or - switch to the Podman provisioner to run containers on RHEL. salt: minion_config_nonexist: |-