Skip to content

Commit ee87596

Browse files
author
Sophia Castellarin
authored
Merge pull request #11462 from soapy1/docker-provision-centos8
Docker provision centos8
2 parents 2a18eff + e61725a commit ee87596

File tree

10 files changed

+136
-30
lines changed

10 files changed

+136
-30
lines changed

plugins/guests/centos/cap/flavor.rb

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
module VagrantPlugins
2+
module GuestCentos
3+
module Cap
4+
class Flavor
5+
def self.flavor(machine)
6+
# Read the version file
7+
output = ""
8+
machine.communicate.sudo("cat /etc/centos-release") do |_, data|
9+
output = data
10+
end
11+
12+
# Detect various flavors we care about
13+
if output =~ /(CentOS)( .+)? 7/i
14+
return :centos_7
15+
elsif output =~ /(CentOS)( .+)? 8/i
16+
return :centos_8
17+
else
18+
return :centos
19+
end
20+
end
21+
end
22+
end
23+
end
24+
end

plugins/guests/centos/guest.rb

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module VagrantPlugins
2+
module GuestCentos
3+
class Guest < Vagrant.plugin("2", :guest)
4+
def detect?(machine)
5+
machine.communicate.test("cat /etc/centos-release")
6+
end
7+
end
8+
end
9+
end

plugins/guests/centos/plugin.rb

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
require "vagrant"
2+
3+
module VagrantPlugins
4+
module GuestCentos
5+
class Plugin < Vagrant.plugin("2")
6+
name "CentOS guest"
7+
description "CentOS guest support."
8+
9+
guest(:centos, :redhat) do
10+
require_relative "guest"
11+
Guest
12+
end
13+
14+
guest_capability(:centos, :flavor) do
15+
require_relative "cap/flavor"
16+
Cap::Flavor
17+
end
18+
end
19+
end
20+
end

plugins/guests/redhat/cap/flavor.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ def self.flavor(machine)
1010
end
1111

1212
# Detect various flavors we care about
13-
if output =~ /(CentOS|Red Hat Enterprise|Scientific|Cloud|Virtuozzo)\s*Linux( .+)? release 7/i
13+
if output =~ /(Red Hat Enterprise|Scientific|Cloud|Virtuozzo)\s*Linux( .+)? release 7/i
1414
return :rhel_7
15+
elsif output =~ /(Red Hat Enterprise|Scientific|Cloud|Virtuozzo)\s*Linux( .+)? release 8/i
16+
return :rhel_8
1517
else
1618
return :rhel
1719
end

plugins/provisioners/docker/cap/redhat/docker_install.rb renamed to plugins/provisioners/docker/cap/centos/docker_install.rb

+10-7
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,34 @@
11
module VagrantPlugins
22
module DockerProvisioner
33
module Cap
4-
module Redhat
4+
module Centos
55
module DockerInstall
66
def self.docker_install(machine)
77
machine.communicate.tap do |comm|
88
comm.sudo("yum -q -y update")
99
comm.sudo("yum -q -y remove docker-io* || true")
10-
comm.sudo("curl -sSL https://get.docker.com/ | sh")
10+
comm.sudo("yum install -y -q yum-utils")
11+
comm.sudo("yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo")
12+
comm.sudo("yum makecache")
13+
comm.sudo("yum install -y -q docker-ce")
1114
end
1215

1316
case machine.guest.capability("flavor")
14-
when :rhel_7
15-
docker_enable_rhel7(machine)
17+
when :centos
18+
docker_enable_service(machine)
1619
else
17-
docker_enable_default(machine)
20+
docker_enable_systemctl(machine)
1821
end
1922
end
2023

21-
def self.docker_enable_rhel7(machine)
24+
def self.docker_enable_systemctl(machine)
2225
machine.communicate.tap do |comm|
2326
comm.sudo("systemctl start docker.service")
2427
comm.sudo("systemctl enable docker.service")
2528
end
2629
end
2730

28-
def self.docker_enable_default(machine)
31+
def self.docker_enable_service(machine)
2932
machine.communicate.tap do |comm|
3033
comm.sudo("service docker start")
3134
comm.sudo("chkconfig docker on")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
module VagrantPlugins
2+
module DockerProvisioner
3+
module Cap
4+
module Centos
5+
module DockerStartService
6+
def self.docker_start_service(machine)
7+
case machine.guest.capability("flavor")
8+
when :centos
9+
machine.communicate.tap do |comm|
10+
comm.sudo("service docker start")
11+
comm.sudo("chkconfig docker on")
12+
end
13+
else
14+
machine.communicate.tap do |comm|
15+
comm.sudo("systemctl start docker.service")
16+
comm.sudo("systemctl enable docker.service")
17+
end
18+
end
19+
end
20+
end
21+
end
22+
end
23+
end
24+
end

plugins/provisioners/docker/cap/redhat/docker_start_service.rb

-16
This file was deleted.

plugins/provisioners/docker/plugin.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ class Plugin < Vagrant.plugin("2")
2929
Cap::Fedora::DockerInstall
3030
end
3131

32-
guest_capability("redhat", "docker_install") do
32+
guest_capability("centos", "docker_install") do
3333
require_relative "cap/redhat/docker_install"
34-
Cap::Redhat::DockerInstall
34+
Cap::Centos::DockerInstall
3535
end
3636

37-
guest_capability("redhat", "docker_start_service") do
37+
guest_capability("centos", "docker_start_service") do
3838
require_relative "cap/redhat/docker_start_service"
39-
Cap::Redhat::DockerStartService
39+
Cap::Centos::DockerStartService
4040
end
4141

4242
guest_capability("linux", "docker_installed") do
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
require_relative "../../../../base"
2+
3+
describe "VagrantPlugins::GuestCentos::Cap::Flavor" do
4+
let(:caps) do
5+
VagrantPlugins::GuestCentos::Plugin
6+
.components
7+
.guest_capabilities[:centos]
8+
end
9+
10+
let(:machine) { double("machine") }
11+
let(:comm) { VagrantTests::DummyCommunicator::Communicator.new(machine) }
12+
13+
before do
14+
allow(machine).to receive(:communicate).and_return(comm)
15+
end
16+
17+
after do
18+
comm.verify_expectations!
19+
end
20+
21+
describe ".flavor" do
22+
let(:cap) { caps.get(:flavor) }
23+
24+
{
25+
"CentOS Linux 2.4 release 7" => :centos_7,
26+
"CentOS Linux release 8.1.1911 (Core)" => :centos_8,
27+
28+
"CentOS" => :centos,
29+
"banana" => :centos,
30+
}.each do |str, expected|
31+
it "returns #{expected} for #{str}" do
32+
comm.stub_command("cat /etc/centos-release", stdout: str)
33+
expect(cap.flavor(machine)).to be(expected)
34+
end
35+
end
36+
end
37+
end

test/unit/plugins/guests/redhat/cap/flavor_test.rb

+5-2
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,15 @@
2222
let(:cap) { caps.get(:flavor) }
2323

2424
{
25-
"CentOS Linux 2.4 release 7" => :rhel_7,
25+
"Red Hat Enterprise Linux 2.4 release 7" => :rhel_7,
2626
"Red Hat Enterprise Linux release 7" => :rhel_7,
2727
"Scientific Linux release 7" => :rhel_7,
2828
"CloudLinux release 7.2 (Valeri Kubasov)" => :rhel_7,
2929

30-
"CentOS" => :rhel,
30+
"CloudLinux release 8.1.1911 (Valeri Kubasov)" => :rhel_8,
31+
"Red Hat Enterprise Linux release 8" => :rhel_8,
32+
33+
"Red Hat Enterprise Linux" => :rhel,
3134
"RHEL 6" => :rhel,
3235
"banana" => :rhel,
3336
}.each do |str, expected|

0 commit comments

Comments
 (0)