vagrant-lxc 0.6.0 → 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/BOXES.md +55 -0
- data/CHANGELOG.md +14 -0
- data/CONTRIBUTING.md +20 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +4 -3
- data/README.md +16 -19
- data/boxes/build-debian-box.sh +167 -0
- data/boxes/build-ubuntu-box.sh +151 -0
- data/boxes/common/install-babushka +4 -3
- data/boxes/common/install-chef +3 -2
- data/boxes/common/install-puppet +3 -2
- data/boxes/common/install-salt +3 -2
- data/boxes/common/lxc-template +10 -13
- data/boxes/common/metadata.json +2 -1
- data/development/Vagrantfile +4 -4
- data/development/site.pp +31 -6
- data/lib/vagrant-lxc/action.rb +44 -40
- data/lib/vagrant-lxc/action/clear_forwarded_ports.rb +4 -0
- data/lib/vagrant-lxc/action/fetch_ip_from_dnsmasq_leases.rb +1 -1
- data/lib/vagrant-lxc/action/fetch_ip_with_lxc_attach.rb +4 -7
- data/lib/vagrant-lxc/action/message.rb +1 -0
- data/lib/vagrant-lxc/action/setup_package_files.rb +1 -0
- data/lib/vagrant-lxc/action/wait_for_communicator.rb +9 -14
- data/lib/vagrant-lxc/driver.rb +10 -7
- data/lib/vagrant-lxc/driver/cli.rb +7 -1
- data/lib/vagrant-lxc/errors.rb +5 -0
- data/lib/vagrant-lxc/version.rb +1 -1
- data/locales/en.yml +8 -2
- data/spec/Vagrantfile +7 -2
- data/spec/unit/driver/cli_spec.rb +8 -0
- metadata +8 -18
- data/boxes/debian/download +0 -156
- data/boxes/debian/finalize +0 -195
- data/boxes/debian/lxc-template +0 -367
- data/boxes/debian/metadata.json.template +0 -9
- data/boxes/ubuntu/download +0 -113
- data/boxes/ubuntu/finalize +0 -374
- data/boxes/ubuntu/lxc-template +0 -559
- data/boxes/ubuntu/metadata.json.template +0 -9
- data/development/shell-provisioning/upgrade-kernel +0 -14
- data/example/Vagrantfile +0 -46
- data/example/cookbooks/hello-world/recipes/default.rb +0 -4
- data/example/puppet/manifests/site.pp +0 -5
- data/example/puppet/modules/hello_world/manifests/init.pp +0 -3
- data/tasks/boxes.rake +0 -115
- data/tasks/boxes.v2.rake +0 -188
@@ -1,12 +1,13 @@
|
|
1
1
|
#!/bin/bash
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
set -e
|
4
|
+
|
5
|
+
rootfs=$1
|
5
6
|
|
6
7
|
echo "installing babushka"
|
7
8
|
cat > $rootfs/tmp/install-babushka.sh << EOF
|
8
9
|
#!/bin/sh
|
9
|
-
curl
|
10
|
+
curl https://babushka.me/up | sudo bash
|
10
11
|
|
11
12
|
EOF
|
12
13
|
chmod +x $rootfs/tmp/install-babushka.sh
|
data/boxes/common/install-chef
CHANGED
data/boxes/common/install-puppet
CHANGED
data/boxes/common/install-salt
CHANGED
data/boxes/common/lxc-template
CHANGED
@@ -112,17 +112,13 @@ post_process()
|
|
112
112
|
usage()
|
113
113
|
{
|
114
114
|
cat <<EOF
|
115
|
-
$1 -h|--help [-a|--arch] [--trim] [-d|--debug]
|
116
|
-
[-F | --flush-cache] [-r|--release <release>] [ -S | --auth-key <keyfile>]
|
117
|
-
release: the ubuntu release (e.g. precise): defaults to host release on ubuntu, otherwise uses latest LTS
|
118
|
-
trim: make a minimal (faster, but not upgrade-safe) container
|
115
|
+
$1 -h|--help [-a|--arch] [--trim] [-d|--debug] [--rootfs <rootfs>] [-T|--tarball <rootfs-tarball>
|
119
116
|
arch: the container architecture (e.g. amd64): defaults to host arch
|
120
|
-
auth-key: SSH Public key file to inject into container
|
121
117
|
EOF
|
122
118
|
return 0
|
123
119
|
}
|
124
120
|
|
125
|
-
options=$(getopt -o a:b:hp:r:xn:FS:d:C -l arch:,help,path:,release:,trim,name:,flush-cache,auth-key:,debug:,tarball: -- "$@")
|
121
|
+
options=$(getopt -o a:b:hp:r:xn:FS:d:C -l arch:,help,path:,release:,trim,name:,flush-cache,auth-key:,debug:,tarball:,rootfs: -- "$@")
|
126
122
|
if [ $? -ne 0 ]; then
|
127
123
|
usage $(basename $0)
|
128
124
|
exit 1
|
@@ -162,12 +158,11 @@ while true
|
|
162
158
|
do
|
163
159
|
case "$1" in
|
164
160
|
-h|--help) usage $0 && exit 0;;
|
161
|
+
--rootfs) rootfs=$2; shift 2;;
|
165
162
|
-p|--path) path=$2; shift 2;;
|
166
163
|
-n|--name) name=$2; shift 2;;
|
167
164
|
-T|--tarball) tarball=$2; shift 2;;
|
168
|
-
-r|--release) release=$2; shift 2;;
|
169
165
|
-a|--arch) arch=$2; shift 2;;
|
170
|
-
-x|--trim) trim_container=1; shift 1;;
|
171
166
|
-S|--auth-key) auth_key=$2; shift 2;;
|
172
167
|
-d|--debug) debug=1; shift 1;;
|
173
168
|
--) shift 1; break ;;
|
@@ -179,7 +174,6 @@ if [ $debug -eq 1 ]; then
|
|
179
174
|
set -x
|
180
175
|
fi
|
181
176
|
|
182
|
-
|
183
177
|
if [ "$arch" == "i686" ]; then
|
184
178
|
arch=i386
|
185
179
|
fi
|
@@ -201,10 +195,13 @@ fi
|
|
201
195
|
|
202
196
|
# detect rootfs
|
203
197
|
config="$path/config"
|
204
|
-
if
|
205
|
-
|
206
|
-
|
207
|
-
|
198
|
+
# if $rootfs exists here, it was passed in with --rootfs
|
199
|
+
if [ -z "$rootfs" ]; then
|
200
|
+
if grep -q '^lxc.rootfs' $config 2>/dev/null ; then
|
201
|
+
rootfs=`grep 'lxc.rootfs =' $config | awk -F= '{ print $2 }'`
|
202
|
+
else
|
203
|
+
rootfs=$path/rootfs
|
204
|
+
fi
|
208
205
|
fi
|
209
206
|
|
210
207
|
install_ubuntu $rootfs $release $tarball
|
data/boxes/common/metadata.json
CHANGED
data/development/Vagrantfile
CHANGED
@@ -25,7 +25,10 @@ BOXES = {
|
|
25
25
|
},
|
26
26
|
raring: {
|
27
27
|
lxc_url: lxc_box_url('raring'),
|
28
|
-
vbox_url: 'http://
|
28
|
+
vbox_url: 'http://goo.gl/Y4aRr'
|
29
|
+
},
|
30
|
+
saucy: {
|
31
|
+
vbox_url: 'http://cloud-images.ubuntu.com/vagrant/saucy/current/saucy-server-cloudimg-amd64-vagrant-disk1.box'
|
29
32
|
},
|
30
33
|
squeeze: {
|
31
34
|
lxc_url: lxc_box_url('squeeze'),
|
@@ -83,9 +86,6 @@ Vagrant.configure("2") do |config|
|
|
83
86
|
end
|
84
87
|
end
|
85
88
|
|
86
|
-
config.vm.provision :shell, :inline => 'sudo apt-get update'
|
87
|
-
config.vm.provision :shell, :path => 'shell-provisioning/upgrade-kernel'
|
88
|
-
|
89
89
|
config.vm.provision :puppet do |puppet|
|
90
90
|
puppet.manifests_path = "."
|
91
91
|
puppet.manifest_file = "site.pp"
|
data/development/site.pp
CHANGED
@@ -1,5 +1,18 @@
|
|
1
1
|
Exec { path => [ '/bin/', '/sbin/' , '/usr/bin/', '/usr/sbin/', '/usr/local/bin'] }
|
2
2
|
|
3
|
+
stage { 'preinstall':
|
4
|
+
before => Stage['main']
|
5
|
+
}
|
6
|
+
|
7
|
+
class apt_get_update {
|
8
|
+
exec { 'apt-get -y update':
|
9
|
+
unless => "test -f /etc/default/lxc"
|
10
|
+
}
|
11
|
+
}
|
12
|
+
class { 'apt_get_update':
|
13
|
+
stage => preinstall
|
14
|
+
}
|
15
|
+
|
3
16
|
# Because I'm lazy ;)
|
4
17
|
exec {
|
5
18
|
'echo "alias be=\"bundle exec\"" >> /home/vagrant/.bashrc':
|
@@ -38,17 +51,18 @@ package {
|
|
38
51
|
;
|
39
52
|
}
|
40
53
|
|
54
|
+
# Upgrade kernel if needed
|
55
|
+
package {
|
56
|
+
[ 'linux-image-generic', 'linux-headers-generic' ]:
|
57
|
+
ensure => 'latest'
|
58
|
+
}
|
59
|
+
|
41
60
|
# Make sure we can create and boot nested containers
|
42
61
|
if $hostname == 'vbox' {
|
43
62
|
package { 'apparmor-utils': }
|
44
63
|
exec { 'aa-complain /usr/bin/lxc-start': }
|
45
64
|
}
|
46
65
|
|
47
|
-
# TMUX
|
48
|
-
package {
|
49
|
-
'tmux': ensure => 'installed';
|
50
|
-
}
|
51
|
-
|
52
66
|
# Allow gems to be installed on vagrant user home avoiding "sudo"s
|
53
67
|
# Tks to http://wiki.railsplayground.com/railsplayground/show/How+to+install+gems+and+non+root+user
|
54
68
|
file {
|
@@ -73,7 +87,7 @@ gem: --no-ri --no-rdoc
|
|
73
87
|
gemhome: /home/vagrant/gems
|
74
88
|
gempath:
|
75
89
|
- /home/vagrant/gems
|
76
|
-
- /
|
90
|
+
- /var/lib/gems/1.9.1
|
77
91
|
'
|
78
92
|
}
|
79
93
|
exec {
|
@@ -126,3 +140,14 @@ file {
|
|
126
140
|
mode => '0600',
|
127
141
|
require => Exec['download-private-key']
|
128
142
|
}
|
143
|
+
|
144
|
+
# Passwordless sudo wrapper script
|
145
|
+
file {
|
146
|
+
'/usr/bin/lxc-vagrant-wrapper':
|
147
|
+
ensure => 'present',
|
148
|
+
mode => '0755',
|
149
|
+
content => "
|
150
|
+
#!/usr/bin/env ruby
|
151
|
+
exec ARGV.join(' ')
|
152
|
+
"
|
153
|
+
}
|
data/lib/vagrant-lxc/action.rb
CHANGED
@@ -27,18 +27,22 @@ end
|
|
27
27
|
module Vagrant
|
28
28
|
module LXC
|
29
29
|
module Action
|
30
|
+
# Shortcuts
|
31
|
+
Builtin = Vagrant::Action::Builtin
|
32
|
+
Builder = Vagrant::Action::Builder
|
33
|
+
|
30
34
|
# This action is responsible for reloading the machine, which
|
31
35
|
# brings it down, sucks in new configuration, and brings the
|
32
36
|
# machine back up with the new configuration.
|
33
37
|
def self.action_reload
|
34
|
-
|
35
|
-
b.use
|
38
|
+
Builder.new.tap do |b|
|
39
|
+
b.use Builtin::Call, Created do |env1, b2|
|
36
40
|
if !env1[:result]
|
37
41
|
b2.use Message, :not_created
|
38
42
|
next
|
39
43
|
end
|
40
44
|
|
41
|
-
b2.use
|
45
|
+
b2.use Builtin::ConfigValidate
|
42
46
|
b2.use action_halt
|
43
47
|
b2.use action_start
|
44
48
|
end
|
@@ -48,35 +52,35 @@ module Vagrant
|
|
48
52
|
# This action boots the VM, assuming the VM is in a state that requires
|
49
53
|
# a bootup (i.e. not saved).
|
50
54
|
def self.action_boot
|
51
|
-
|
52
|
-
b.use
|
53
|
-
b.use
|
54
|
-
b.use
|
55
|
+
Builder.new.tap do |b|
|
56
|
+
b.use Builtin::Provision
|
57
|
+
b.use Builtin::EnvSet, :port_collision_repair => true
|
58
|
+
b.use Builtin::HandleForwardedPortCollisions
|
55
59
|
b.use ShareFolders
|
56
|
-
b.use
|
60
|
+
b.use Builtin::SetHostname
|
57
61
|
b.use ForwardPorts
|
58
62
|
b.use Boot
|
59
|
-
b.use
|
63
|
+
b.use Builtin::WaitForCommunicator
|
60
64
|
end
|
61
65
|
end
|
62
66
|
|
63
67
|
# This action just runs the provisioners on the machine.
|
64
68
|
def self.action_provision
|
65
|
-
|
66
|
-
b.use
|
67
|
-
b.use
|
69
|
+
Builder.new.tap do |b|
|
70
|
+
b.use Builtin::ConfigValidate
|
71
|
+
b.use Builtin::Call, Created do |env1, b2|
|
68
72
|
if !env1[:result]
|
69
73
|
b2.use Message, :not_created
|
70
74
|
next
|
71
75
|
end
|
72
76
|
|
73
|
-
b2.use
|
77
|
+
b2.use Builtin::Call, IsRunning do |env2, b3|
|
74
78
|
if !env2[:result]
|
75
79
|
b3.use Message, :not_running
|
76
80
|
next
|
77
81
|
end
|
78
82
|
|
79
|
-
b3.use
|
83
|
+
b3.use Builtin::Provision
|
80
84
|
end
|
81
85
|
end
|
82
86
|
end
|
@@ -85,12 +89,11 @@ module Vagrant
|
|
85
89
|
# This action starts a container, assuming it is already created and exists.
|
86
90
|
# A precondition of this action is that the container exists.
|
87
91
|
def self.action_start
|
88
|
-
|
89
|
-
b.use
|
90
|
-
b.use
|
92
|
+
Builder.new.tap do |b|
|
93
|
+
b.use Builtin::ConfigValidate
|
94
|
+
b.use Builtin::Call, IsRunning do |env, b2|
|
91
95
|
# If the VM is running, then our work here is done, exit
|
92
96
|
next if env[:result]
|
93
|
-
# TODO: Check if has been saved / frozen and resume
|
94
97
|
b2.use action_boot
|
95
98
|
end
|
96
99
|
end
|
@@ -99,12 +102,12 @@ module Vagrant
|
|
99
102
|
# This action brings the machine up from nothing, including creating the
|
100
103
|
# container, configuring metadata, and booting.
|
101
104
|
def self.action_up
|
102
|
-
|
103
|
-
b.use
|
104
|
-
b.use
|
105
|
+
Builder.new.tap do |b|
|
106
|
+
b.use Builtin::ConfigValidate
|
107
|
+
b.use Builtin::Call, Created do |env, b2|
|
105
108
|
# If the VM is NOT created yet, then do the setup steps
|
106
109
|
if !env[:result]
|
107
|
-
b2.use
|
110
|
+
b2.use Builtin::HandleBoxUrl
|
108
111
|
b2.use HandleBoxMetadata
|
109
112
|
b2.use Create
|
110
113
|
end
|
@@ -116,14 +119,14 @@ module Vagrant
|
|
116
119
|
# This is the action that is primarily responsible for halting
|
117
120
|
# the virtual machine, gracefully or by force.
|
118
121
|
def self.action_halt
|
119
|
-
|
120
|
-
b.use
|
122
|
+
Builder.new.tap do |b|
|
123
|
+
b.use Builtin::Call, Created do |env, b2|
|
121
124
|
if env[:result]
|
122
|
-
# TODO: Remove
|
125
|
+
# TODO: Remove once we drop support for vagrant 1.1
|
123
126
|
b2.use Disconnect
|
124
127
|
b2.use ClearForwardedPorts
|
125
128
|
b2.use RemoveTemporaryFiles
|
126
|
-
b2.use
|
129
|
+
b2.use Builtin::Call, Builtin::GracefulHalt, :stopped, :running do |env2, b3|
|
127
130
|
if !env2[:result]
|
128
131
|
b3.use ForcedHalt
|
129
132
|
end
|
@@ -138,21 +141,22 @@ module Vagrant
|
|
138
141
|
# This is the action that is primarily responsible for completely
|
139
142
|
# freeing the resources of the underlying virtual machine.
|
140
143
|
def self.action_destroy
|
141
|
-
|
142
|
-
b.use
|
144
|
+
Builder.new.tap do |b|
|
145
|
+
b.use Builtin::Call, Created do |env1, b2|
|
143
146
|
if !env1[:result]
|
144
147
|
b2.use Message, :not_created
|
145
148
|
next
|
146
149
|
end
|
147
150
|
|
148
|
-
|
151
|
+
# TODO: Use Vagrant's built in action once we drop support for vagrant 1.2
|
152
|
+
b2.use Builtin::Call, DestroyConfirm do |env2, b3|
|
149
153
|
if env2[:result]
|
150
|
-
b3.use
|
151
|
-
b3.use
|
154
|
+
b3.use Builtin::ConfigValidate
|
155
|
+
b3.use Builtin::EnvSet, :force_halt => true
|
152
156
|
b3.use action_halt
|
153
157
|
b3.use Destroy
|
154
158
|
if Vagrant::LXC.vagrant_1_3_or_later
|
155
|
-
b3.use
|
159
|
+
b3.use Builtin::ProvisionerCleanup
|
156
160
|
end
|
157
161
|
else
|
158
162
|
b3.use Message, :will_not_destroy
|
@@ -164,8 +168,8 @@ module Vagrant
|
|
164
168
|
|
165
169
|
# This action packages the virtual machine into a single box file.
|
166
170
|
def self.action_package
|
167
|
-
|
168
|
-
b.use
|
171
|
+
Builder.new.tap do |b|
|
172
|
+
b.use Builtin::Call, Created do |env1, b2|
|
169
173
|
if !env1[:result]
|
170
174
|
b2.use Message, :not_created
|
171
175
|
next
|
@@ -182,8 +186,8 @@ module Vagrant
|
|
182
186
|
# This action is called to read the IP of the container. The IP found
|
183
187
|
# is expected to be put into the `:machine_ip` key.
|
184
188
|
def self.action_fetch_ip
|
185
|
-
|
186
|
-
b.use
|
189
|
+
Builder.new.tap do |b|
|
190
|
+
b.use Builtin::ConfigValidate
|
187
191
|
b.use FetchIpWithLxcAttach
|
188
192
|
b.use FetchIpFromDnsmasqLeases
|
189
193
|
end
|
@@ -191,19 +195,19 @@ module Vagrant
|
|
191
195
|
|
192
196
|
# This is the action that will exec into an SSH shell.
|
193
197
|
def self.action_ssh
|
194
|
-
|
198
|
+
Builder.new.tap do |b|
|
195
199
|
b.use CheckCreated
|
196
200
|
b.use CheckRunning
|
197
|
-
b.use
|
201
|
+
b.use Builtin::SSHExec
|
198
202
|
end
|
199
203
|
end
|
200
204
|
|
201
205
|
# This is the action that will run a single SSH command.
|
202
206
|
def self.action_ssh_run
|
203
|
-
|
207
|
+
Builder.new.tap do |b|
|
204
208
|
b.use CheckCreated
|
205
209
|
b.use CheckRunning
|
206
|
-
b.use
|
210
|
+
b.use Builtin::SSHRun
|
207
211
|
end
|
208
212
|
end
|
209
213
|
end
|
@@ -18,7 +18,10 @@ module Vagrant
|
|
18
18
|
system "pkill -TERM -P #{pid}"
|
19
19
|
end
|
20
20
|
|
21
|
+
@logger.info "Removing redir pids files"
|
21
22
|
remove_redir_pids
|
23
|
+
else
|
24
|
+
@logger.info "No redir pids found"
|
22
25
|
end
|
23
26
|
|
24
27
|
@app.call env
|
@@ -33,6 +36,7 @@ module Vagrant
|
|
33
36
|
end
|
34
37
|
|
35
38
|
def is_redir_pid?(pid)
|
39
|
+
@logger.debug "Checking if #{pid} is a redir process with `ps -o cmd= #{pid}`"
|
36
40
|
`ps -o cmd= #{pid}`.strip.chomp =~ /redir/
|
37
41
|
end
|
38
42
|
|
@@ -17,7 +17,7 @@ module Vagrant
|
|
17
17
|
ip = nil
|
18
18
|
10.times do
|
19
19
|
dnsmasq_leases = read_dnsmasq_leases
|
20
|
-
@logger.debug
|
20
|
+
@logger.debug "Attempting to load ip from dnsmasq leases (mac: #{mac_address})"
|
21
21
|
@logger.debug dnsmasq_leases
|
22
22
|
if dnsmasq_leases =~ /#{Regexp.escape mac_address}\s+([0-9.]+)\s+/
|
23
23
|
ip = $1.to_s
|
@@ -12,17 +12,14 @@ module Vagrant
|
|
12
12
|
|
13
13
|
def call(env)
|
14
14
|
env[:machine_ip] ||= assigned_ip(env)
|
15
|
+
rescue LXC::Errors::NamespacesNotSupported
|
16
|
+
@logger.info 'The `lxc-attach` command available does not support the --namespaces parameter, falling back to dnsmasq leases to fetch container ip'
|
17
|
+
ensure
|
15
18
|
@app.call(env)
|
16
19
|
end
|
17
20
|
|
18
21
|
def assigned_ip(env)
|
19
|
-
driver
|
20
|
-
version = driver.version.match(/^(\d+\.\d+)\./)[1].to_f
|
21
|
-
unless version >= 0.8
|
22
|
-
@logger.debug "lxc version does not support the --namespaces argument to lxc-attach"
|
23
|
-
return nil
|
24
|
-
end
|
25
|
-
|
22
|
+
driver = env[:machine].provider.driver
|
26
23
|
ip = ''
|
27
24
|
retryable(:on => LXC::Errors::ExecuteError, :tries => 10, :sleep => 3) do
|
28
25
|
unless ip = get_container_ip_from_ip_addr(driver)
|