Commit 78524563b8c7d46aaa727871df989c9c8719d3d5
1 parent
c60e1bf0
bootstrap containers from metadata info / added a sid example box
Showing
12 changed files
with
116 additions
and
26 deletions
@@ -9,7 +9,7 @@ | @@ -9,7 +9,7 @@ | ||
9 | "name": "lxd", | 9 | "name": "lxd", |
10 | "url": "file:///data/ghopp/projects/vagrant/vagrant-lxd/gentoo_001_lxd.box", | 10 | "url": "file:///data/ghopp/projects/vagrant/vagrant-lxd/gentoo_001_lxd.box", |
11 | "checksum_type": "sha1", | 11 | "checksum_type": "sha1", |
12 | - "checksum": "9cf9ffd2c840680672a329a87abcd056b021d130" | 12 | + "checksum": "303573ec033c0eb1939df486f444c5bcc3f82d1e" |
13 | } | 13 | } |
14 | ] | 14 | ] |
15 | } | 15 | } |
No preview for this file type
@@ -5,7 +5,7 @@ | @@ -5,7 +5,7 @@ | ||
5 | "exec": [ | 5 | "exec": [ |
6 | ["sed", "-i", "s/-lxc //", "/etc/init.d/hostname"], | 6 | ["sed", "-i", "s/-lxc //", "/etc/init.d/hostname"], |
7 | ["sed", "-i", "s/LXC_NAME/<%= hostname %>/", "/etc/conf.d/hostname"], | 7 | ["sed", "-i", "s/LXC_NAME/<%= hostname %>/", "/etc/conf.d/hostname"], |
8 | - ["sed", "-i", "s/<%= container %>/<%= hostname %>/", "/etc/hostname"], | 8 | + ["sed", "-i", "s/<%= container %>/<%= hostname %>/", "/etc/hostname"], |
9 | ["sed", "-i", "s/<%= container %>/<%= hostname %>/", "/etc/hosts"] | 9 | ["sed", "-i", "s/<%= container %>/<%= hostname %>/", "/etc/hosts"] |
10 | ] | 10 | ] |
11 | }, | 11 | }, |
@@ -16,7 +16,18 @@ | @@ -16,7 +16,18 @@ | ||
16 | }, | 16 | }, |
17 | "sudo": { | 17 | "sudo": { |
18 | "exec": [ | 18 | "exec": [ |
19 | - ["echo", "vagrant ALL=(ALL) NOPASSWD: ALL", ">>/etc/sudoers"] | 19 | + [ |
20 | + "sed", | ||
21 | + "-i", | ||
22 | + "/vagrant/b;$a\\\nvagrant ALL=(ALL) NOPASSWD: ALL", | ||
23 | + "/etc/sudoers" | ||
24 | + ] | ||
25 | + ] | ||
26 | + }, | ||
27 | + "sshd_service": { | ||
28 | + "exec": [ | ||
29 | + ["rc-update", "add", "sshd", "default"], | ||
30 | + ["/etc/init.d/sshd", "start"] | ||
20 | ] | 31 | ] |
21 | } | 32 | } |
22 | } | 33 | } |
@@ -28,17 +28,18 @@ module Vagrant | @@ -28,17 +28,18 @@ module Vagrant | ||
28 | b2.use EnsureImage | 28 | b2.use EnsureImage |
29 | b2.use Network | 29 | b2.use Network |
30 | b2.use Create | 30 | b2.use Create |
31 | + b2.use action_start | ||
32 | + b2.use Bootstrap | ||
33 | + b2.use EnsureSsh | ||
34 | + else | ||
35 | + b2.use action_start | ||
31 | end | 36 | end |
32 | end | 37 | end |
33 | - b.use action_start | ||
34 | - b.use EnsureSsh | ||
35 | - b.use Bootstrap | ||
36 | end | 38 | end |
37 | end | 39 | end |
38 | 40 | ||
39 | def self.action_start | 41 | def self.action_start |
40 | Vagrant::Action::Builder.new.tap do |b| | 42 | Vagrant::Action::Builder.new.tap do |b| |
41 | - b.use Bootstrap | ||
42 | b.use EnsureStarted | 43 | b.use EnsureStarted |
43 | end | 44 | end |
44 | end | 45 | end |
@@ -24,11 +24,13 @@ module Vagrant | @@ -24,11 +24,13 @@ module Vagrant | ||
24 | hostname = env[:machine].name | 24 | hostname = env[:machine].name |
25 | data.each do |d| | 25 | data.each do |d| |
26 | d.collect! { |element| ERB.new(element).result(binding) } | 26 | d.collect! { |element| ERB.new(element).result(binding) } |
27 | - driver.exec(*d) | ||
28 | - env[:ui].info "--- #{d.inspect} ---", :prefix => false | 27 | + env[:ui].info "--- #{action}: #{d.inspect} ---", |
28 | + :prefix => false | ||
29 | + driver.exec(*d, :retryable => true) | ||
29 | end | 30 | end |
30 | end | 31 | end |
31 | end | 32 | end |
33 | + driver.restart | ||
32 | 34 | ||
33 | @app.call(env) | 35 | @app.call(env) |
34 | end | 36 | end |
@@ -10,8 +10,8 @@ module Vagrant | @@ -10,8 +10,8 @@ module Vagrant | ||
10 | def call(env) | 10 | def call(env) |
11 | driver = env[:machine].provider.driver | 11 | driver = env[:machine].provider.driver |
12 | 12 | ||
13 | - env[:ui].info "--- #{env[:machine].box.directory} ---", | ||
14 | - :prefix => false | 13 | + # Currently I suppose this is the same on all linux distributions |
14 | + # so it is not configured in the metadata of the box. | ||
15 | driver.vagrant_user | 15 | driver.vagrant_user |
16 | driver.enable_ssh | 16 | driver.enable_ssh |
17 | 17 |
@@ -72,12 +72,12 @@ module Vagrant | @@ -72,12 +72,12 @@ module Vagrant | ||
72 | 72 | ||
73 | def initialize(machine) | 73 | def initialize(machine) |
74 | @machine = machine | 74 | @machine = machine |
75 | - @name = "vagrant-#{machine.name}" | 75 | + @name = "vagrant-#{machine.config.vm.hostname}" |
76 | + @name = "vagrant-#{machine.name}" unless @name | ||
76 | @logger = Log4r::Logger.new("vagrant::provider::lxd::driver") | 77 | @logger = Log4r::Logger.new("vagrant::provider::lxd::driver") |
77 | 78 | ||
78 | # This flag is used to keep track of interrupted state (SIGINT) | 79 | # This flag is used to keep track of interrupted state (SIGINT) |
79 | @interrupted = false | 80 | @interrupted = false |
80 | - @image = machine.box.name.split("/")[1] if machine.box | ||
81 | bridge | 81 | bridge |
82 | end | 82 | end |
83 | 83 | ||
@@ -89,8 +89,12 @@ module Vagrant | @@ -89,8 +89,12 @@ module Vagrant | ||
89 | end.flatten(1)] | 89 | end.flatten(1)] |
90 | end | 90 | end |
91 | 91 | ||
92 | + def image | ||
93 | + @machine.box.name.split("/")[1..-1].join("/") if @machine.box | ||
94 | + end | ||
95 | + | ||
92 | def image? | 96 | def image? |
93 | - images.key? @image | 97 | + images.key? image |
94 | end | 98 | end |
95 | 99 | ||
96 | # Get infos about all existing containers | 100 | # Get infos about all existing containers |
@@ -130,7 +134,7 @@ module Vagrant | @@ -130,7 +134,7 @@ module Vagrant | ||
130 | args = [ | 134 | args = [ |
131 | "image", | 135 | "image", |
132 | "copy", | 136 | "copy", |
133 | - "#{remote}:#{@image}", | 137 | + "#{remote}:#{image}", |
134 | "local:", | 138 | "local:", |
135 | "--copy-aliases" | 139 | "--copy-aliases" |
136 | ] | 140 | ] |
@@ -141,7 +145,7 @@ module Vagrant | @@ -141,7 +145,7 @@ module Vagrant | ||
141 | def create | 145 | def create |
142 | # network could be also attached right here if it turns out to be | 146 | # network could be also attached right here if it turns out to be |
143 | # a good idea. | 147 | # a good idea. |
144 | - execute("init", @image, @name, "-n", @bridge["name"]) | 148 | + execute("init", image, @name, "-n", @bridge["name"]) |
145 | end | 149 | end |
146 | 150 | ||
147 | def start | 151 | def start |
@@ -161,15 +165,18 @@ module Vagrant | @@ -161,15 +165,18 @@ module Vagrant | ||
161 | @bridge | 165 | @bridge |
162 | end | 166 | end |
163 | 167 | ||
168 | + def restart | ||
169 | + execute("stop", @name) | ||
170 | + execute("start", @name) | ||
171 | + end | ||
172 | + | ||
164 | def vagrant_user | 173 | def vagrant_user |
165 | pwent = [] | 174 | pwent = [] |
166 | while pwent.empty? do | 175 | while pwent.empty? do |
167 | begin | 176 | begin |
168 | - pwent = execute( | ||
169 | - "exec", @name, "getent", "passwd", "vagrant" | ||
170 | - ).split(":") | 177 | + pwent = exec("getent", "passwd", "vagrant").split(":") |
171 | rescue | 178 | rescue |
172 | - execute("exec", @name, "--", "useradd", "-m", "vagrant") | 179 | + exec("useradd", "-m", "-s", "/bin/bash", "vagrant") |
173 | end | 180 | end |
174 | end | 181 | end |
175 | execute( | 182 | execute( |
@@ -178,17 +185,19 @@ module Vagrant | @@ -178,17 +185,19 @@ module Vagrant | ||
178 | "--uid=#{pwent[2]}", | 185 | "--uid=#{pwent[2]}", |
179 | "--gid=#{pwent[3]}", | 186 | "--gid=#{pwent[3]}", |
180 | "--mode=0400", | 187 | "--mode=0400", |
188 | + "-p", | ||
181 | "#{@machine.box.directory}/vagrant.pub", | 189 | "#{@machine.box.directory}/vagrant.pub", |
182 | - "#{@name}/#{pwent[5]}/.ssh/authorized_keys" | 190 | + "#{@name}#{pwent[5]}/.ssh/authorized_keys" |
183 | ) | 191 | ) |
192 | + exec("chmod", "700", "#{pwent[5]}/.ssh") | ||
184 | end | 193 | end |
185 | 194 | ||
186 | def enable_ssh | 195 | def enable_ssh |
187 | - begin | ||
188 | - execute("exec", @name, "--", "rc-update", "add", "sshd", "default") | ||
189 | - execute("exec", @name, "--", "/etc/init.d/sshd", "start") | ||
190 | - rescue | ||
191 | - end | 196 | + #begin |
197 | + service = @machine.box.metadata["bootstrap"]["sshd_service"] | ||
198 | + service["exec"].each { |command| exec(*command) } | ||
199 | + #rescue | ||
200 | + #end | ||
192 | end | 201 | end |
193 | 202 | ||
194 | def exec(*command) | 203 | def exec(*command) |
sid.json
0 → 100644
1 | +{ | ||
2 | + "name": "lxd/debian/sid", | ||
3 | + "description": "The latest debian/sid LXD image.", | ||
4 | + "versions": [ | ||
5 | + { | ||
6 | + "version": "0.0.1", | ||
7 | + "providers": [ | ||
8 | + { | ||
9 | + "name": "lxd", | ||
10 | + "url": "file:///data/ghopp/projects/vagrant/vagrant-lxd/sid_001_lxd.box", | ||
11 | + "checksum_type": "sha1", | ||
12 | + "checksum": "a533654e7577931659c1cb457b13e6b184d4013d" | ||
13 | + } | ||
14 | + ] | ||
15 | + } | ||
16 | + ] | ||
17 | +} |
sid_001_lxd.box
0 → 100644
No preview for this file type
sid_box/README.md
0 → 100644
1 | +# Vagrant LXD Example Box | ||
2 | + | ||
3 | +Vagrant providers each require a custom provider-specific box format. | ||
4 | +This folder shows the example contents of a box for the `lxd` provider. | ||
5 | +To turn this into a box: | ||
6 | + | ||
7 | +``` | ||
8 | +$ tar cvzf lxd.box ./metadata.json ./vagrant.pub | ||
9 | +``` | ||
10 | + | ||
11 | +The `lxd` provider right now just uses the default lxd images provided | ||
12 | +by the lxd images: remote. Upon start these will be provisioned with an | ||
13 | +vagrant ssh user and and the unsafe common pubkey of vagrant and | ||
14 | +sshd will be enabled. | ||
15 | + | ||
16 | +Well, at least thats the idea for now. |
sid_box/metadata.json
0 → 100644
1 | +{ | ||
2 | + "provider": "lxd", | ||
3 | + "bootstrap": { | ||
4 | + "hostname": { | ||
5 | + "exec": [ | ||
6 | + ["sed", "-i", "s/<%= container %>/<%= hostname %>/", "/etc/hostname"], | ||
7 | + ["sed", "-i", "s/<%= container %>/<%= hostname %>/", "/etc/hosts"] | ||
8 | + ] | ||
9 | + }, | ||
10 | + "packages": { | ||
11 | + "exec": [ | ||
12 | + ["apt-get", "install", "-y", "sudo"], | ||
13 | + ["apt-get", "install", "-y", "openssh-server"] | ||
14 | + ] | ||
15 | + }, | ||
16 | + "sudo": { | ||
17 | + "exec": [ | ||
18 | + [ | ||
19 | + "sed", | ||
20 | + "-i", | ||
21 | + "/vagrant/b;$a\\\nvagrant ALL=(ALL) NOPASSWD: ALL", | ||
22 | + "/etc/sudoers" | ||
23 | + ] | ||
24 | + ] | ||
25 | + }, | ||
26 | + "sshd_service": { | ||
27 | + "exec": [ | ||
28 | + ["systemctl", "enable", "ssh"], | ||
29 | + ["systemctl", "start", "ssh"] | ||
30 | + ] | ||
31 | + } | ||
32 | + } | ||
33 | +} |
sid_box/vagrant.pub
0 → 100644
1 | +ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ== vagrant insecure public key |
Please
register
or
login
to post a comment