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.
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.create_platform_image(platform_image_name, platform_image_options, lxc_config_path='/var/lib/lxc')
10
- platform_image = DevLXC::Container.new(platform_image_name, lxc_config_path)
11
- if platform_image.defined?
12
- puts "Using existing platform image '#{platform_image.name}'"
13
- return platform_image
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 platform image '#{platform_image.name}'"
15
+ puts "Creating base container '#{base_container.name}'"
16
16
  template = "download"
17
- case platform_image.name
18
- when "p-ubuntu-1004"
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 "p-ubuntu-1404"
20
+ when "b-ubuntu-1404"
23
21
  options = ["-d", "ubuntu", "-r", "trusty", "-a", "amd64"]
24
- when "p-ubuntu-1604"
22
+ when "b-ubuntu-1604"
25
23
  options = ["-d", "ubuntu", "-r", "xenial", "-a", "amd64"]
26
- when "p-centos-5"
24
+ when "b-centos-5"
27
25
  template = "centos"
28
26
  options = ["-R", "5"]
29
- when "p-centos-6"
27
+ when "b-centos-6"
30
28
  options = ["-d", "centos", "-r", "6", "-a", "amd64"]
31
- when "p-centos-7"
29
+ when "b-centos-7"
32
30
  options = ["-d", "centos", "-r", "7", "-a", "amd64"]
33
31
  end
34
- options.concat(platform_image_options.split) unless platform_image_options.nil?
35
- platform_image.create(template, "btrfs", {}, 0, options)
36
- if platform_image.name == "p-centos-7"
37
- # Centos 7 needs setpcap capabilities
38
- # ref: https://bugzilla.redhat.com/show_bug.cgi?id=1176816
39
- # ref: https://bugs.launchpad.net/ubuntu/+source/lxc/+bug/1339781
40
- # ref: http://vfamilyserver.org/blog/2015/05/centos-7-lxc-container-slow-boot/
41
- DevLXC.search_file_replace(platform_image.config_file_name, /centos.common.conf/, 'fedora.common.conf')
42
- platform_image.clear_config
43
- platform_image.load_config
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
- unless platform_image.config_item("lxc.mount.auto").nil?
46
- platform_image.set_config_item("lxc.mount.auto", "proc:rw sys:rw")
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 platform_image.config_item("lxc.network.0.hwaddr").nil?
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 '#{platform_image.name}' platform image's lxc.network.hwaddr to #{hwaddr}"
51
- platform_image.set_config_item("lxc.network.hwaddr", hwaddr)
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
- platform_image.save_config
54
- platform_image.start
55
- puts "Installing packages in platform image '#{platform_image.name}'"
56
- case platform_image.name
57
- when "p-ubuntu-1004"
58
- # Disable certain sysctl.d files in Ubuntu 10.04, they cause `start procps` to fail
59
- if File.exist?("#{platform_image.config_item('lxc.rootfs')}/etc/sysctl.d/10-console-messages.conf")
60
- FileUtils.mv("#{platform_image.config_item('lxc.rootfs')}/etc/sysctl.d/10-console-messages.conf",
61
- "#{platform_image.config_item('lxc.rootfs')}/etc/sysctl.d/10-console-messages.conf.orig")
62
- end
63
- platform_image.run_command("apt-get update")
64
- platform_image.run_command("apt-get install -y standard^ server^ vim-nox emacs23-nox curl tree openssh-server")
65
- IO.write("#{platform_image.config_item('lxc.rootfs')}/etc/rc.local", "#!/usr/bin/env bash\n\n/usr/sbin/dpkg-reconfigure openssh-server\n")
66
- FileUtils.chmod(0755, "#{platform_image.config_item('lxc.rootfs')}/etc/rc.local")
67
- when "p-ubuntu-1204", "p-ubuntu-1404"
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
- platform_image.run_command("yum downgrade -y openssl")
81
- platform_image.run_command("yum install -y @base @core vim-enhanced emacs-nox tree openssh-server")
82
- FileUtils.mkdir_p("#{platform_image.config_item('lxc.rootfs')}/etc/sudoers.d")
83
- FileUtils.chmod(0750, "#{platform_image.config_item('lxc.rootfs')}/etc/sudoers.d")
84
- append_line_to_file("#{platform_image.config_item('lxc.rootfs')}/etc/sudoers", "\n#includedir /etc/sudoers.d\n")
85
- when "p-centos-6"
86
- platform_image.run_command("yum install -y @base @core vim-enhanced emacs-nox tree openssh-server")
87
- when "p-centos-7"
88
- platform_image.run_command("yum install -y @base @core vim-enhanced emacs-nox tree openssh-server")
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
- platform_image.run_command("useradd --create-home --shell /bin/bash --password $6$q3FDMpMZ$zfahCxEWHbzuEV98QPzhGZ7fLtGcLNZrbKK7OAYGXmJXZc07WbcxVnDwrMyX/cL6vSp4/IjlrVUZFBp7Orhyu1 dev-lxc")
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("#{platform_image.config_item('lxc.rootfs')}/home/dev-lxc/.ssh")
93
- FileUtils.chmod(0700, "#{platform_image.config_item('lxc.rootfs')}/home/dev-lxc/.ssh")
94
- FileUtils.touch("#{platform_image.config_item('lxc.rootfs')}/home/dev-lxc/.ssh/authorized_keys")
95
- FileUtils.chmod(0600, "#{platform_image.config_item('lxc.rootfs')}/home/dev-lxc/.ssh/authorized_keys")
96
- platform_image.run_command("chown -R dev-lxc:dev-lxc /home/dev-lxc/.ssh")
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("#{platform_image.config_item('lxc.rootfs')}/etc/sudoers.d/dev-lxc", "dev-lxc ALL=NOPASSWD:ALL\n")
99
- FileUtils.chmod(0440, "#{platform_image.config_item('lxc.rootfs')}/etc/sudoers.d/dev-lxc")
100
- platform_image.stop
101
- return platform_image
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(api_fqdn, container_name, ipaddress)
112
- dns_record = "#{ipaddress} #{container_name} #{api_fqdn}\n"
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: 1.7.0
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-05-04 00:00:00.000000000 Z
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 creating Chef server clusters using LXC containers
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 creating Chef server clusters using LXC containers
128
+ summary: A tool for building Chef server clusters using LXC containers
115
129
  test_files: []
116
130
  has_rdoc: