Merge pull request #11462 from soapy1/docker-provision-centos8
Docker provision centos8
This commit is contained in:
commit
ee87596a77
24
plugins/guests/centos/cap/flavor.rb
Normal file
24
plugins/guests/centos/cap/flavor.rb
Normal file
@ -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
plugins/guests/centos/guest.rb
Normal file
9
plugins/guests/centos/guest.rb
Normal file
@ -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
plugins/guests/centos/plugin.rb
Normal file
20
plugins/guests/centos/plugin.rb
Normal file
@ -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
|
||||
@ -10,8 +10,10 @@ 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 =~ /(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
|
||||
else
|
||||
return :rhel
|
||||
end
|
||||
|
||||
@ -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")
|
||||
@ -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
|
||||
@ -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
|
||||
@ -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
|
||||
|
||||
37
test/unit/plugins/guests/centos/cap/flavor_test.rb
Normal file
37
test/unit/plugins/guests/centos/cap/flavor_test.rb
Normal file
@ -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
|
||||
@ -22,12 +22,15 @@ describe "VagrantPlugins::GuestRedHat::Cap::Flavor" do
|
||||
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|
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user