dev-lxc 1.7.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +230 -452
- data/dev-lxc.gemspec +2 -1
- data/lib/dev-lxc/cli.rb +174 -309
- data/lib/dev-lxc/cluster.rb +772 -113
- data/lib/dev-lxc/container.rb +1 -107
- data/lib/dev-lxc/server.rb +107 -420
- data/lib/dev-lxc/version.rb +1 -1
- data/lib/dev-lxc.rb +72 -76
- metadata +18 -4
data/lib/dev-lxc.rb
CHANGED
@@ -6,99 +6,95 @@ require "dev-lxc/server"
|
|
6
6
|
require "dev-lxc/cluster"
|
7
7
|
|
8
8
|
module DevLXC
|
9
|
-
def self.
|
10
|
-
|
11
|
-
if
|
12
|
-
puts "Using existing
|
13
|
-
return
|
9
|
+
def self.create_base_container(base_container_name, base_container_options)
|
10
|
+
base_container = DevLXC::Container.new(base_container_name)
|
11
|
+
if base_container.defined?
|
12
|
+
puts "Using existing base container '#{base_container.name}'"
|
13
|
+
return base_container
|
14
14
|
end
|
15
|
-
puts "Creating
|
15
|
+
puts "Creating base container '#{base_container.name}'"
|
16
16
|
template = "download"
|
17
|
-
case
|
18
|
-
when "
|
19
|
-
options = ["-d", "ubuntu", "-r", "lucid", "-a", "amd64"]
|
20
|
-
when "p-ubuntu-1204"
|
17
|
+
case base_container.name
|
18
|
+
when "b-ubuntu-1204"
|
21
19
|
options = ["-d", "ubuntu", "-r", "precise", "-a", "amd64"]
|
22
|
-
when "
|
20
|
+
when "b-ubuntu-1404"
|
23
21
|
options = ["-d", "ubuntu", "-r", "trusty", "-a", "amd64"]
|
24
|
-
when "
|
22
|
+
when "b-ubuntu-1604"
|
25
23
|
options = ["-d", "ubuntu", "-r", "xenial", "-a", "amd64"]
|
26
|
-
when "
|
24
|
+
when "b-centos-5"
|
27
25
|
template = "centos"
|
28
26
|
options = ["-R", "5"]
|
29
|
-
when "
|
27
|
+
when "b-centos-6"
|
30
28
|
options = ["-d", "centos", "-r", "6", "-a", "amd64"]
|
31
|
-
when "
|
29
|
+
when "b-centos-7"
|
32
30
|
options = ["-d", "centos", "-r", "7", "-a", "amd64"]
|
33
31
|
end
|
34
|
-
options.concat(
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
#
|
41
|
-
|
42
|
-
|
43
|
-
|
32
|
+
options.concat(base_container_options.split) unless base_container_options.nil?
|
33
|
+
base_container.create(template, "btrfs", {}, 0, options)
|
34
|
+
|
35
|
+
# if base container is centos then `/etc/hosts` file needs to be modified so `hostname -f`
|
36
|
+
# provides the FQDN instead of `localhost`
|
37
|
+
if base_container.name.start_with?('b-centos-')
|
38
|
+
IO.write("#{base_container.config_item('lxc.rootfs')}/etc/hosts", "127.0.0.1 localhost\n127.0.1.1 #{base_container.name}\n")
|
39
|
+
end
|
40
|
+
|
41
|
+
# Centos 7 needs setpcap capabilities
|
42
|
+
# ref: https://bugzilla.redhat.com/show_bug.cgi?id=1176816
|
43
|
+
# ref: https://bugs.launchpad.net/ubuntu/+source/lxc/+bug/1339781
|
44
|
+
# ref: http://vfamilyserver.org/blog/2015/05/centos-7-lxc-container-slow-boot/
|
45
|
+
if base_container.name == "b-centos-7"
|
46
|
+
DevLXC.search_file_replace(base_container.config_file_name, /centos.common.conf/, 'fedora.common.conf')
|
47
|
+
base_container.clear_config
|
48
|
+
base_container.load_config
|
44
49
|
end
|
45
|
-
|
46
|
-
|
50
|
+
|
51
|
+
unless base_container.config_item("lxc.mount.auto").nil?
|
52
|
+
base_container.set_config_item("lxc.mount.auto", "proc:rw sys:rw")
|
47
53
|
end
|
48
|
-
if
|
54
|
+
if base_container.config_item("lxc.network.0.hwaddr").nil?
|
49
55
|
hwaddr = '00:16:3e:' + Digest::SHA1.hexdigest(Time.now.to_s).slice(0..5).unpack('a2a2a2').join(':')
|
50
|
-
puts "Setting '#{
|
51
|
-
|
56
|
+
puts "Setting '#{base_container.name}' base container's lxc.network.hwaddr to #{hwaddr}"
|
57
|
+
base_container.set_config_item("lxc.network.hwaddr", hwaddr)
|
52
58
|
end
|
53
|
-
|
54
|
-
|
55
|
-
puts "Installing packages in
|
56
|
-
case
|
57
|
-
when "
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
IO.write("#{
|
66
|
-
FileUtils.chmod(0755, "#{
|
67
|
-
when "
|
68
|
-
platform_image.run_command("apt-get update")
|
69
|
-
platform_image.run_command("apt-get install -y standard^ server^ vim-nox emacs23-nox tree openssh-server")
|
70
|
-
IO.write("#{platform_image.config_item('lxc.rootfs')}/etc/rc.local", "#!/usr/bin/env bash\n\n/usr/sbin/dpkg-reconfigure openssh-server\n")
|
71
|
-
FileUtils.chmod(0755, "#{platform_image.config_item('lxc.rootfs')}/etc/rc.local")
|
72
|
-
when "p-ubuntu-1604"
|
73
|
-
platform_image.run_command("apt-get update")
|
74
|
-
platform_image.run_command("apt-get install -y standard^ server^ vim-nox emacs24-nox tree openssh-server")
|
75
|
-
IO.write("#{platform_image.config_item('lxc.rootfs')}/etc/rc.local", "#!/usr/bin/env bash\n\n/usr/sbin/dpkg-reconfigure openssh-server\n")
|
76
|
-
FileUtils.chmod(0755, "#{platform_image.config_item('lxc.rootfs')}/etc/rc.local")
|
77
|
-
when "p-centos-5"
|
59
|
+
base_container.save_config
|
60
|
+
base_container.start
|
61
|
+
puts "Installing packages in base container '#{base_container.name}'"
|
62
|
+
case base_container.name
|
63
|
+
when "b-ubuntu-1204", "b-ubuntu-1404"
|
64
|
+
base_container.run_command("apt-get update")
|
65
|
+
base_container.run_command("apt-get install -y standard^ server^ vim-nox emacs23-nox tree openssh-server")
|
66
|
+
IO.write("#{base_container.config_item('lxc.rootfs')}/etc/rc.local", "#!/usr/bin/env bash\n\n/usr/sbin/dpkg-reconfigure openssh-server\n")
|
67
|
+
FileUtils.chmod(0755, "#{base_container.config_item('lxc.rootfs')}/etc/rc.local")
|
68
|
+
when "b-ubuntu-1604"
|
69
|
+
base_container.run_command("apt-get update")
|
70
|
+
base_container.run_command("apt-get install -y standard^ server^ vim-nox emacs24-nox tree openssh-server")
|
71
|
+
IO.write("#{base_container.config_item('lxc.rootfs')}/etc/rc.local", "#!/usr/bin/env bash\n\n/usr/sbin/dpkg-reconfigure openssh-server\n")
|
72
|
+
FileUtils.chmod(0755, "#{base_container.config_item('lxc.rootfs')}/etc/rc.local")
|
73
|
+
when "b-centos-5"
|
78
74
|
# downgrade openssl temporarily to overcome an install bug
|
79
75
|
# reference: http://www.hack.net.br/blog/2014/02/12/openssl-conflicts-with-file-from-package-openssl/
|
80
|
-
|
81
|
-
|
82
|
-
FileUtils.mkdir_p("#{
|
83
|
-
FileUtils.chmod(0750, "#{
|
84
|
-
append_line_to_file("#{
|
85
|
-
when "
|
86
|
-
|
87
|
-
when "
|
88
|
-
|
76
|
+
base_container.run_command("yum downgrade -y openssl")
|
77
|
+
base_container.run_command("yum install -y @base @core vim-enhanced emacs-nox tree openssh-server")
|
78
|
+
FileUtils.mkdir_p("#{base_container.config_item('lxc.rootfs')}/etc/sudoers.d")
|
79
|
+
FileUtils.chmod(0750, "#{base_container.config_item('lxc.rootfs')}/etc/sudoers.d")
|
80
|
+
append_line_to_file("#{base_container.config_item('lxc.rootfs')}/etc/sudoers", "\n#includedir /etc/sudoers.d\n")
|
81
|
+
when "b-centos-6"
|
82
|
+
base_container.run_command("yum install -y @base @core vim-enhanced emacs-nox tree openssh-server")
|
83
|
+
when "b-centos-7"
|
84
|
+
base_container.run_command("yum install -y @base @core vim-enhanced emacs-nox tree openssh-server")
|
89
85
|
end
|
90
|
-
|
86
|
+
base_container.run_command("useradd --create-home --shell /bin/bash --password $6$q3FDMpMZ$zfahCxEWHbzuEV98QPzhGZ7fLtGcLNZrbKK7OAYGXmJXZc07WbcxVnDwrMyX/cL6vSp4/IjlrVUZFBp7Orhyu1 dev-lxc")
|
91
87
|
|
92
|
-
FileUtils.mkdir_p("#{
|
93
|
-
FileUtils.chmod(0700, "#{
|
94
|
-
FileUtils.touch("#{
|
95
|
-
FileUtils.chmod(0600, "#{
|
96
|
-
|
88
|
+
FileUtils.mkdir_p("#{base_container.config_item('lxc.rootfs')}/home/dev-lxc/.ssh")
|
89
|
+
FileUtils.chmod(0700, "#{base_container.config_item('lxc.rootfs')}/home/dev-lxc/.ssh")
|
90
|
+
FileUtils.touch("#{base_container.config_item('lxc.rootfs')}/home/dev-lxc/.ssh/authorized_keys")
|
91
|
+
FileUtils.chmod(0600, "#{base_container.config_item('lxc.rootfs')}/home/dev-lxc/.ssh/authorized_keys")
|
92
|
+
base_container.run_command("chown -R dev-lxc:dev-lxc /home/dev-lxc/.ssh")
|
97
93
|
|
98
|
-
IO.write("#{
|
99
|
-
FileUtils.chmod(0440, "#{
|
100
|
-
|
101
|
-
return
|
94
|
+
IO.write("#{base_container.config_item('lxc.rootfs')}/etc/sudoers.d/dev-lxc", "dev-lxc ALL=NOPASSWD:ALL\n")
|
95
|
+
FileUtils.chmod(0440, "#{base_container.config_item('lxc.rootfs')}/etc/sudoers.d/dev-lxc")
|
96
|
+
base_container.stop
|
97
|
+
return base_container
|
102
98
|
end
|
103
99
|
|
104
100
|
def self.assign_ip_address(ipaddress, container_name, hwaddr)
|
@@ -108,8 +104,8 @@ module DevLXC
|
|
108
104
|
reload_dnsmasq
|
109
105
|
end
|
110
106
|
|
111
|
-
def self.create_dns_record(
|
112
|
-
dns_record = "#{ipaddress} #{container_name} #{
|
107
|
+
def self.create_dns_record(fqdn, container_name, ipaddress)
|
108
|
+
dns_record = "#{ipaddress} #{container_name} #{fqdn}\n"
|
113
109
|
puts "Creating DNS record: #{dns_record}"
|
114
110
|
search_file_delete_line("/etc/lxc/addn-hosts.conf", /^#{ipaddress}\s/)
|
115
111
|
append_line_to_file("/etc/lxc/addn-hosts.conf", dns_record)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dev-lxc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremiah Snapp
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-06-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: mixlib-install
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: thor
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,7 +80,7 @@ dependencies:
|
|
66
80
|
- - "~>"
|
67
81
|
- !ruby/object:Gem::Version
|
68
82
|
version: 1.2.0
|
69
|
-
description: A tool for
|
83
|
+
description: A tool for building Chef server clusters using LXC containers
|
70
84
|
email:
|
71
85
|
- jeremiah@getchef.com
|
72
86
|
executables:
|
@@ -111,6 +125,6 @@ rubyforge_project:
|
|
111
125
|
rubygems_version: 2.6.3
|
112
126
|
signing_key:
|
113
127
|
specification_version: 4
|
114
|
-
summary: A tool for
|
128
|
+
summary: A tool for building Chef server clusters using LXC containers
|
115
129
|
test_files: []
|
116
130
|
has_rdoc:
|