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.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/BOXES.md +55 -0
  3. data/CHANGELOG.md +14 -0
  4. data/CONTRIBUTING.md +20 -0
  5. data/Gemfile +1 -1
  6. data/Gemfile.lock +4 -3
  7. data/README.md +16 -19
  8. data/boxes/build-debian-box.sh +167 -0
  9. data/boxes/build-ubuntu-box.sh +151 -0
  10. data/boxes/common/install-babushka +4 -3
  11. data/boxes/common/install-chef +3 -2
  12. data/boxes/common/install-puppet +3 -2
  13. data/boxes/common/install-salt +3 -2
  14. data/boxes/common/lxc-template +10 -13
  15. data/boxes/common/metadata.json +2 -1
  16. data/development/Vagrantfile +4 -4
  17. data/development/site.pp +31 -6
  18. data/lib/vagrant-lxc/action.rb +44 -40
  19. data/lib/vagrant-lxc/action/clear_forwarded_ports.rb +4 -0
  20. data/lib/vagrant-lxc/action/fetch_ip_from_dnsmasq_leases.rb +1 -1
  21. data/lib/vagrant-lxc/action/fetch_ip_with_lxc_attach.rb +4 -7
  22. data/lib/vagrant-lxc/action/message.rb +1 -0
  23. data/lib/vagrant-lxc/action/setup_package_files.rb +1 -0
  24. data/lib/vagrant-lxc/action/wait_for_communicator.rb +9 -14
  25. data/lib/vagrant-lxc/driver.rb +10 -7
  26. data/lib/vagrant-lxc/driver/cli.rb +7 -1
  27. data/lib/vagrant-lxc/errors.rb +5 -0
  28. data/lib/vagrant-lxc/version.rb +1 -1
  29. data/locales/en.yml +8 -2
  30. data/spec/Vagrantfile +7 -2
  31. data/spec/unit/driver/cli_spec.rb +8 -0
  32. metadata +8 -18
  33. data/boxes/debian/download +0 -156
  34. data/boxes/debian/finalize +0 -195
  35. data/boxes/debian/lxc-template +0 -367
  36. data/boxes/debian/metadata.json.template +0 -9
  37. data/boxes/ubuntu/download +0 -113
  38. data/boxes/ubuntu/finalize +0 -374
  39. data/boxes/ubuntu/lxc-template +0 -559
  40. data/boxes/ubuntu/metadata.json.template +0 -9
  41. data/development/shell-provisioning/upgrade-kernel +0 -14
  42. data/example/Vagrantfile +0 -46
  43. data/example/cookbooks/hello-world/recipes/default.rb +0 -4
  44. data/example/puppet/manifests/site.pp +0 -5
  45. data/example/puppet/modules/hello_world/manifests/init.pp +0 -3
  46. data/tasks/boxes.rake +0 -115
  47. data/tasks/boxes.v2.rake +0 -188
@@ -1,6 +1,7 @@
1
1
  module Vagrant
2
2
  module LXC
3
3
  module Action
4
+ # XXX: Is this really needed? Should we contribute this back to Vagrant's core?
4
5
  class Message
5
6
  def initialize(app, env, msg_key, type = :info)
6
7
  @app = app
@@ -45,6 +45,7 @@ module Vagrant
45
45
  box_dir = @env[:machine].box.directory
46
46
  FileUtils.cp box_dir.join('lxc-template').to_s, @env['package.directory'].to_s
47
47
  FileUtils.cp box_dir.join('metadata.json').to_s, @env['package.directory'].to_s
48
+ # TODO: Update built-on metadata.json
48
49
  if (conf = box_dir.join('lxc.conf')).exist?
49
50
  FileUtils.cp conf.to_s, @env['package.directory'].to_s
50
51
  end
@@ -1,25 +1,25 @@
1
1
  # This acts like a backport of Vagrant's built in action from 1.3+ for older versions
2
+ # and will probably be deprecated on 0.8+
2
3
  # https://github.com/mitchellh/vagrant/blob/master/lib/vagrant/action/builtin/wait_for_communicator.rb
3
4
  module Vagrant
4
5
  module LXC
5
6
  module Action
6
7
  class WaitForCommunicator
7
- def initialize(app, env, states = [])
8
+ def initialize(app, env)
8
9
  @app = app
9
- @states = states
10
10
  end
11
11
 
12
12
  def call(env)
13
13
  @env = env
14
- raise Vagrant::Errors::VMFailedToBoot if !wait_for_boot
14
+
15
+ raise Vagrant::Errors::VMFailedToBoot if !wait_for_communicator
16
+
15
17
  @app.call env
16
18
  end
17
19
 
18
- # Stolen from the an old version of VagrantPlugins::ProviderVirtualBox::Action::Boot
19
- def wait_for_boot
20
- @env[:ui].info I18n.t("vagrant_lxc.messages.waiting_for_start")
21
-
22
- @env[:machine].config.ssh.max_tries.to_i.times do |i|
20
+ def wait_for_communicator
21
+ max_tries = @env[:machine].config.ssh.max_tries.to_i
22
+ max_tries.times do |i|
23
23
  if @env[:machine].communicate.ready?
24
24
  @env[:ui].info I18n.t("vagrant_lxc.messages.container_ready")
25
25
  return true
@@ -29,12 +29,7 @@ module Vagrant
29
29
  # get shown
30
30
  return true if @env[:interrupted]
31
31
 
32
- # If the VM is not starting or running, something went wrong
33
- # and we need to show a useful error.
34
- state = @env[:machine].provider.state.id
35
- raise Vagrant::Errors::VMFailedToRun unless @states.include?(state)
36
-
37
- sleep 2 if !@env["vagrant.test"]
32
+ sleep 1 if !@env["vagrant.test"]
38
33
  end
39
34
 
40
35
  @env[:ui].error I18n.t("vagrant.actions.vm.boot.failed")
@@ -111,9 +111,7 @@ module Vagrant
111
111
  @sudo_wrapper.run('tar', '--numeric-owner', '-czf', target_path, 'rootfs')
112
112
 
113
113
  @logger.info "Changing rootfs tarball owner"
114
-
115
- user_details=Etc.getpwnam(Etc.getlogin)
116
-
114
+ user_details = Etc.getpwnam(Etc.getlogin)
117
115
  @sudo_wrapper.run('chown', "#{user_details.uid}:#{user_details.gid}", target_path)
118
116
  end
119
117
 
@@ -151,12 +149,16 @@ module Vagrant
151
149
  template_name = "vagrant-tmp-#{@container_name}"
152
150
  tmp_template_path = templates_path.join("lxc-#{template_name}").to_s
153
151
 
154
- @logger.debug 'Copying LXC template into place'
152
+ @logger.info 'Copying LXC template into place'
155
153
  @sudo_wrapper.run('cp', path, tmp_template_path)
154
+ @sudo_wrapper.run('chmod', '+x', tmp_template_path)
156
155
 
157
156
  yield template_name
158
157
  ensure
159
- @sudo_wrapper.run('rm', tmp_template_path)
158
+ @logger.info 'Removing LXC template'
159
+ if tmp_template_path
160
+ @sudo_wrapper.run('rm', tmp_template_path)
161
+ end
160
162
  end
161
163
 
162
164
  TEMPLATES_PATH_LOOKUP = %w(
@@ -169,8 +171,9 @@ module Vagrant
169
171
  return @templates_path if @templates_path
170
172
 
171
173
  path = TEMPLATES_PATH_LOOKUP.find { |candidate| File.directory?(candidate) }
172
- # TODO: Raise an user friendly error
173
- raise 'Unable to identify lxc templates path!' unless path
174
+ if !path
175
+ raise Errors::TemplatesDirMissing.new paths: TEMPLATES_PATH_LOOKUP.inspect
176
+ end
174
177
 
175
178
  @templates_path = Pathname(path)
176
179
  end
@@ -81,7 +81,12 @@ module Vagrant
81
81
  if cmd.last.is_a?(Hash)
82
82
  opts = cmd.pop
83
83
  namespaces = Array(opts[:namespaces]).map(&:upcase).join('|')
84
- extra = ['--namespaces', namespaces] if namespaces
84
+
85
+ if run(:attach, '-h').include?('--namespaces')
86
+ extra = ['--namespaces', namespaces] if namespaces
87
+ else
88
+ raise LXC::Errors::NamespacesNotSupported
89
+ end
85
90
  end
86
91
 
87
92
  run :attach, '--name', @name, *((extra || []) + cmd)
@@ -99,6 +104,7 @@ module Vagrant
99
104
  end
100
105
 
101
106
  unless last_state == target_state
107
+ # TODO: Raise an user friendly message
102
108
  raise TargetStateNotReached.new target_state, last_state
103
109
  end
104
110
  end
@@ -6,6 +6,8 @@ module Vagrant
6
6
  class ExecuteError < Vagrant::Errors::VagrantError
7
7
  error_key(:lxc_execute_error)
8
8
  end
9
+ class NamespacesNotSupported < Vagrant::Errors::VagrantError
10
+ end
9
11
 
10
12
  class LxcNotInstalled < Vagrant::Errors::VagrantError
11
13
  error_key(:lxc_not_installed)
@@ -15,6 +17,9 @@ module Vagrant
15
17
  class TemplateFileMissing < Vagrant::Errors::VagrantError
16
18
  error_key(:lxc_template_file_missing)
17
19
  end
20
+ class TemplatesDirMissing < Vagrant::Errors::VagrantError
21
+ error_key(:lxc_templates_dir_missing)
22
+ end
18
23
  class RootFSTarballMissing < Vagrant::Errors::VagrantError
19
24
  error_key(:lxc_invalid_box_version)
20
25
  end
@@ -1,5 +1,5 @@
1
1
  module Vagrant
2
2
  module LXC
3
- VERSION = "0.6.0"
3
+ VERSION = "0.6.1"
4
4
  end
5
5
  end
@@ -10,12 +10,13 @@ en:
10
10
  was declined.
11
11
  starting: |-
12
12
  Starting container...
13
+ force_shutdown: |-
14
+ Forcing shutdown of container...
15
+ # TODO: Remove the following keys after we drop support for vagrant < 1.3
13
16
  waiting_for_start: |-
14
17
  Waiting for container to start. This should not take long.
15
18
  container_ready: |-
16
19
  Container started and ready for use!
17
- force_shutdown: |-
18
- Forcing shutdown of container...
19
20
 
20
21
  vagrant:
21
22
  commands:
@@ -45,6 +46,11 @@ en:
45
46
  The template file used for creating the container was not found for %{name}
46
47
  box.
47
48
 
49
+ lxc_templates_dir_missing: |-
50
+ Unable to identify lxc templates path.
51
+
52
+ Looked up under: %{paths}
53
+
48
54
  lxc_not_installed: |-
49
55
  The `lxc` package does not seem to be installed or is not accessible on the PATH.
50
56
 
@@ -5,17 +5,22 @@ Vagrant.require_plugin 'vagrant-lxc'
5
5
  Vagrant.require_plugin 'vagrant-cachier'
6
6
 
7
7
  ENV['BOX_NAME'] ||= 'quantal64'
8
+ puts "Running specs using #{ENV['BOX_NAME']} box"
8
9
 
9
10
  Vagrant.configure("2") do |config|
10
11
  config.vm.box = ENV['BOX_NAME']
11
12
  config.vm.hostname = 'lxc-test-box'
13
+ config.vm.network :forwarded_port, guest: 80, host: 8080
14
+
15
+ config.cache.auto_detect = true
12
16
 
13
- config.cache.enable :apt
17
+ config.vm.provider :lxc do |lxc|
18
+ lxc.sudo_wrapper = '/usr/bin/lxc-vagrant-wrapper'
19
+ end
14
20
 
15
21
  config.vm.provision :shell,
16
22
  inline: 'mkdir -p /vagrant/tmp && echo -n "Provisioned" > /vagrant/tmp/provisioning'
17
23
 
18
- config.vm.network :forwarded_port, guest: 80, host: 8080
19
24
  config.vm.provision :shell,
20
25
  inline: 'sudo apt-get install apache2 -y'
21
26
  end
@@ -146,9 +146,17 @@ describe Vagrant::LXC::Driver::CLI do
146
146
  end
147
147
 
148
148
  it 'supports a "namespaces" parameter' do
149
+ subject.stub(:run).with(:attach, '-h').and_return('--namespaces')
149
150
  subject.attach *(command + [{namespaces: ['network', 'mount']}])
150
151
  subject.should have_received(:run).with(:attach, '--name', name, '--namespaces', 'NETWORK|MOUNT', '--', *command)
151
152
  end
153
+
154
+ it 'raises a NamespacesNotSupported error if not supported' do
155
+ subject.stub(:run).with(:attach, '-h').and_return('not supported')
156
+ expect {
157
+ subject.attach *(command + [{namespaces: ['network', 'mount']}])
158
+ }.to raise_error(Vagrant::LXC::Errors::NamespacesNotSupported)
159
+ end
152
160
  end
153
161
 
154
162
  describe 'transition block' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-lxc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fabio Rehm
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-12 00:00:00.000000000 Z
11
+ date: 2013-10-03 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Linux Containers provider for Vagrant
14
14
  email:
@@ -21,13 +21,17 @@ files:
21
21
  - .rspec
22
22
  - .travis.yml
23
23
  - .vimrc
24
+ - BOXES.md
24
25
  - CHANGELOG.md
26
+ - CONTRIBUTING.md
25
27
  - Gemfile
26
28
  - Gemfile.lock
27
29
  - Guardfile
28
30
  - LICENSE.txt
29
31
  - README.md
30
32
  - Rakefile
33
+ - boxes/build-debian-box.sh
34
+ - boxes/build-ubuntu-box.sh
31
35
  - boxes/common/cleanup
32
36
  - boxes/common/install-babushka
33
37
  - boxes/common/install-chef
@@ -36,26 +40,13 @@ files:
36
40
  - boxes/common/lxc-template
37
41
  - boxes/common/lxc.conf
38
42
  - boxes/common/metadata.json
39
- - boxes/debian/download
40
- - boxes/debian/finalize
41
- - boxes/debian/lxc-template
42
- - boxes/debian/metadata.json.template
43
- - boxes/ubuntu/download
44
- - boxes/ubuntu/finalize
45
- - boxes/ubuntu/lxc-template
46
- - boxes/ubuntu/metadata.json.template
47
43
  - development/Vagrantfile
48
44
  - development/lxc-configs/lxc-dev-box
49
45
  - development/lxc-configs/sid
50
46
  - development/lxc-configs/squeeze
51
47
  - development/lxc-configs/vbox
52
48
  - development/lxc-configs/wheezy
53
- - development/shell-provisioning/upgrade-kernel
54
49
  - development/site.pp
55
- - example/Vagrantfile
56
- - example/cookbooks/hello-world/recipes/default.rb
57
- - example/puppet/manifests/site.pp
58
- - example/puppet/modules/hello_world/manifests/init.pp
59
50
  - lib/vagrant-lxc.rb
60
51
  - lib/vagrant-lxc/action.rb
61
52
  - lib/vagrant-lxc/action/boot.rb
@@ -106,8 +97,6 @@ files:
106
97
  - spec/unit/driver_spec.rb
107
98
  - spec/unit/support/unit_example_group.rb
108
99
  - spec/unit_helper.rb
109
- - tasks/boxes.rake
110
- - tasks/boxes.v2.rake
111
100
  - tasks/spec.rake
112
101
  - vagrant-lxc.gemspec
113
102
  homepage: https://github.com/fgrehm/vagrant-lxc
@@ -130,7 +119,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
130
119
  version: '0'
131
120
  requirements: []
132
121
  rubyforge_project:
133
- rubygems_version: 2.0.7
122
+ rubygems_version: 2.1.5
134
123
  signing_key:
135
124
  specification_version: 4
136
125
  summary: Linux Containers provider for Vagrant
@@ -153,3 +142,4 @@ test_files:
153
142
  - spec/unit/driver_spec.rb
154
143
  - spec/unit/support/unit_example_group.rb
155
144
  - spec/unit_helper.rb
145
+ has_rdoc:
@@ -1,156 +0,0 @@
1
- #!/bin/bash
2
-
3
- # This is the code extracted from /usr/share/lxc/templates/lxc-debian
4
- # that comes with Ubuntu 13.04 which is responsible for downloading the
5
- # rootfs files / packages
6
-
7
- set -e
8
-
9
- suggest_flush()
10
- {
11
- echo <<EOF
12
- Container upgrade failed. The container cache may be out of date,
13
- in which case flushing the case (see -F in the hep output) may help.
14
- EOF
15
- }
16
-
17
- cleanup()
18
- {
19
- rm -rf $cache/partial
20
- rm -rf $cache/rootfs
21
- }
22
-
23
- write_sourceslist()
24
- {
25
- rootfs=$1
26
- arch=$2
27
- release=$3
28
-
29
- MIRROR=${MIRROR:-http://ftp.debian.org/debian}
30
- SECURITY_MIRROR=${SECURITY_MIRROR:-http://security.debian.org/debian-security}
31
-
32
-
33
- if [ 'sid' == "${release}" -o 'unstable' == "${release}" ]; then
34
- cat <<EOF > ${rootfs}/etc/apt/sources.list
35
- # ${release}
36
- #------------------------------------------------------------------------------
37
- deb ${MIRROR} ${release} main contrib non-free
38
- EOF
39
- else
40
- cat <<EOF > ${rootfs}/etc/apt/sources.list
41
- # ${release}
42
- #------------------------------------------------------------------------------
43
- deb ${MIRROR} ${release} main contrib non-free
44
-
45
- # ${release} security
46
- #------------------------------------------------------------------------------
47
- deb ${SECURITY_MIRROR} ${release}/updates main contrib non-free
48
-
49
- # ${release} updates
50
- #------------------------------------------------------------------------------
51
- deb ${MIRROR} ${release}-updates main contrib non-free
52
-
53
- # ${release} proposed updates
54
- #------------------------------------------------------------------------------
55
- deb ${MIRROR} ${release}-proposed-updates main contrib non-free
56
- EOF
57
- fi
58
- }
59
-
60
- download_debian()
61
- {
62
- cache=$1
63
- arch=$2
64
- release=$3
65
-
66
- packages=\
67
- sudo,\
68
- ifupdown,\
69
- locales,\
70
- libui-dialog-perl,\
71
- dialog,\
72
- isc-dhcp-client,\
73
- netbase,\
74
- net-tools,\
75
- iproute,\
76
- openssh-server,\
77
- vim,\
78
- jed,\
79
- jed-extra,\
80
- ssh,\
81
- curl,\
82
- wget,\
83
- bash-completion,\
84
- manpages,\
85
- man-db,\
86
- psmisc,\
87
- bind9-host,\
88
- telnet,\
89
- mtr-tiny,\
90
- iputils-ping,\
91
- ca-certificates
92
-
93
- if [ ! -z "${ADDITIONAL_PACKAGES}" ]; then
94
- packages=${ADDITIONAL_PACKAGES},${packages}
95
- fi
96
-
97
- echo "installing packages: ${packages}"
98
-
99
- trap cleanup EXIT SIGHUP SIGINT SIGTERM
100
- # check the mini debian was not already downloaded
101
- partial=${cache}/partial
102
- mkdir -p ${partial}
103
- if [ $? -ne 0 ]; then
104
- echo "Failed to create '${partial}' directory"
105
- return 1
106
- fi
107
-
108
- # download a mini debian into a cache
109
- echo "Downloading debian ${release} minimal ..."
110
- debootstrap \
111
- --variant=minbase \
112
- --verbose \
113
- --components=main,contrib,non-free \
114
- --arch=${arch} \
115
- --include=${packages} ${release} ${partial} ${MIRROR}
116
-
117
- if [ $? -ne 0 ]; then
118
- echo 'Failed to download the rootfs, aborting.'
119
- return 1
120
- fi
121
-
122
- echo 'Installing updates'
123
- write_sourceslist ${partial} ${arch} ${release}
124
-
125
- chroot ${partial} apt-get update
126
- if [ $? -ne 0 ]; then
127
- echo 'Failed to update the apt cache'
128
- return 1
129
- fi
130
-
131
- lxc-unshare -s MOUNT -- chroot ${partial} \
132
- apt-get dist-upgrade -y || { suggest_flush; false; }
133
-
134
- chroot ${partial} apt-get clean
135
-
136
- mv ${partial} ${cache}/rootfs
137
- trap EXIT
138
- trap SIGINT
139
- trap SIGTERM
140
- trap SIGHUP
141
- echo 'Download complete'
142
- return 0
143
- }
144
-
145
- declare cache=`readlink -f .` \
146
- arch=$1 \
147
- release=$2
148
-
149
- if [ -d ${cache}/rootfs ]; then
150
- echo <<EOF
151
- The rootfs cache has been built already, please remove it if you want to update
152
- EOF
153
- exit 1
154
- fi
155
-
156
- download_debian ${cache} ${arch} ${release}