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

Docker provision centos8 #11462

Merged
merged 8 commits into from
Apr 13, 2020
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions plugins/guests/centos/cap/flavor.rb
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions plugins/guests/centos/guest.rb
Original file line number Diff line number Diff line change
@@ -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
20 changes: 20 additions & 0 deletions plugins/guests/centos/plugin.rb
Original file line number Diff line number Diff line change
@@ -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
4 changes: 3 additions & 1 deletion plugins/guests/redhat/cap/flavor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ def self.flavor(machine)
end

# Detect various flavors we care about
if output =~ /(CentOS|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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will close #11453 👍

else
return :rhel
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,34 @@
module VagrantPlugins
module DockerProvisioner
module Cap
module Redhat
module Centos
module DockerInstall
def self.docker_install(machine)
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")
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")
when :rhel_7
docker_enable_rhel7(machine)
when :centos
docker_enable_service(machine)
else
docker_enable_default(machine)
docker_enable_systemctl(machine)
end
end

def self.docker_enable_rhel7(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")
Expand Down
24 changes: 24 additions & 0 deletions plugins/provisioners/docker/cap/centos/docker_start_service.rb
Original file line number Diff line number Diff line change
@@ -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
16 changes: 0 additions & 16 deletions plugins/provisioners/docker/cap/redhat/docker_start_service.rb

This file was deleted.

8 changes: 4 additions & 4 deletions plugins/provisioners/docker/plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ class Plugin < Vagrant.plugin("2")
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
Expand Down
37 changes: 37 additions & 0 deletions test/unit/plugins/guests/centos/cap/flavor_test.rb
Original file line number Diff line number Diff line change
@@ -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
7 changes: 5 additions & 2 deletions test/unit/plugins/guests/redhat/cap/flavor_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,15 @@
let(:cap) { caps.get(:flavor) }

{
"CentOS Linux 2.4 release 7" => :rhel_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" => :rhel,
"CloudLinux release 8.1.1911 (Valeri Kubasov)" => :rhel_8,
"Red Hat Enterprise Linux release 8" => :rhel_8,

"Red Hat Enterprise Linux" => :rhel,
"RHEL 6" => :rhel,
"banana" => :rhel,
}.each do |str, expected|
Expand Down