vagrant-lxc 0.3.2 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7b9bb037d03a6aea1bdc901bbf62a7829461f0be
4
- data.tar.gz: 83a7cba30a46a536ef30844e9de0a66751554634
3
+ metadata.gz: e016d9b9740eb13e9c7ea4a907b11b68985c4375
4
+ data.tar.gz: 87be64028dec8c58df5d0ae1620f4dc6eccaab57
5
5
  SHA512:
6
- metadata.gz: 20fdc6c3d3a915661720a30394e8d0b7acfd162f080a2c2a447af71cd1e9e280aa6154ac8fd7e61eef6b1f758bb2396700401e33c584eaf09e6af9bd039cfa12
7
- data.tar.gz: 74ef01c112c43bfce60403a09952721b3d17fe22f7c893a095314a7b3b3876e6f6a5128a009253875d5e00ac5e92767b9f98e703a5f26d617bc01a5041f6f26f
6
+ metadata.gz: 3cb85194a618d8f52280ae67bb87be6a02c8fe69089ec0eb9858dbe34fad8328a11fbf21cc97378a1cb5cbd810191639b944f86329ace4289eb9dfecf1965e48
7
+ data.tar.gz: 6aff2121764c2d6f9149c861949cd2148b429d3df03d7adf95c1fbf5499f878aa23ab34786b7f63c421f3f280d3a3c5fbb10d187d6cd90c712b9e35f77266e91
data/.gitignore CHANGED
@@ -24,6 +24,7 @@ doc/
24
24
  /cache
25
25
 
26
26
  /boxes/**/*.tar.gz
27
- /boxes/quantal64/partial/
28
- /boxes/quantal64/rootfs/
27
+ /boxes/**/partial/
28
+ /boxes/**/rootfs/
29
+ /boxes/temp/
29
30
  /boxes/output/
data/.travis.yml CHANGED
@@ -5,4 +5,4 @@ rvm:
5
5
  matrix:
6
6
  allow_failures:
7
7
  - rvm: 2.0.0
8
- script: "bundle exec rake"
8
+ script: "bundle exec rake ci"
data/.vimrc CHANGED
@@ -1 +1 @@
1
- set wildignore+=*/boxes/quantal64/rootfs/*,*/boxes/quantal64/partial/*
1
+ set wildignore+=*/boxes/*/rootfs/*,*/boxes/*/partial/*
data/CHANGELOG.md CHANGED
@@ -1,3 +1,14 @@
1
+ ## [0.3.3](https://github.com/fgrehm/vagrant-lxc/compare/v0.3.2...v0.3.3) (April 23, 2013)
2
+
3
+ BUG FIXES:
4
+
5
+ - Properly kill `redir` child processes [#59][]
6
+
7
+ IMPROVEMENTS:
8
+
9
+ - Initial acceptance test suite
10
+ - New rake tasks for building Ubuntu precise and raring base amd64 boxes
11
+
1
12
  ## [0.3.2](https://github.com/fgrehm/vagrant-lxc/compare/v0.3.1...v0.3.2) (April 18, 2013)
2
13
 
3
14
  - Do not display port forwarding message in case no forwarded ports were set
@@ -14,6 +25,7 @@ BACKWARDS INCOMPATIBILITIES:
14
25
  - `start_opts` config was renamed to `customize`, please check the README for the expected parameters
15
26
  - V1 boxes are no longer supported
16
27
  - `target_rootfs_path` is no longer supported, just symlink `/var/lib/lxc` to the desired folder in case you want to point it to another partition
28
+ - Removed support for configuring private networks. It will come back at some point in the future but if you need it you should be able to set using `customize 'network.ipv4', '1.2.3.4'`
17
29
 
18
30
  IMPROVEMENTS:
19
31
 
data/Gemfile.lock CHANGED
@@ -15,7 +15,7 @@ GIT
15
15
  PATH
16
16
  remote: .
17
17
  specs:
18
- vagrant-lxc (0.3.2)
18
+ vagrant-lxc (0.3.3)
19
19
 
20
20
  GEM
21
21
  remote: https://rubygems.org/
data/Guardfile CHANGED
@@ -1,6 +1,3 @@
1
- # A sample Guardfile
2
- # More info at https://github.com/guard/guard#readme
3
-
4
1
  guard 'bundler' do
5
2
  watch('Gemfile')
6
3
  watch(/^.+\.gemspec/)
@@ -15,20 +12,7 @@ guard 'rspec' do
15
12
  watch(%r{^spec/.+_spec\.rb$})
16
13
  watch(%r{^lib/vagrant-lxc/(.+)\.rb$}) { |m| "spec/unit/#{m[1]}_spec.rb" }
17
14
  watch('spec/unit_helper.rb') { "spec/unit" }
15
+ watch('spec/acceptance_helper.rb') { "spec/acceptance" }
18
16
  watch('spec/spec_helper.rb') { "spec/" }
19
-
20
- # Rails example
21
- watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
22
- watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
23
- watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
24
- watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
25
- watch('config/routes.rb') { "spec/routing" }
26
- watch('app/controllers/application_controller.rb') { "spec/controllers" }
27
-
28
- # Capybara features specs
29
- watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/features/#{m[1]}_spec.rb" }
30
-
31
- # Turnip features and steps
32
- watch(%r{^spec/acceptance/(.+)\.feature$})
33
- watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
17
+ watch(%r{^spec/support/(.+)\.rb$}) { "spec/" }
34
18
  end
data/README.md CHANGED
@@ -8,7 +8,6 @@ Linux Containers support for Vagrant 1.1+
8
8
  * Vagrant 1.1+ (1.1.3+ recommended)
9
9
  * lxc 0.7.5+ (0.8.0-rc1+ recommended)
10
10
  * redir (if you are planning to use port forwarding)
11
- * arch command (uname -m) on PATH
12
11
  * A Kernel [higher than 3.5.0-17.28](#help-im-unable-to-restart-containers)
13
12
 
14
13
  On a clean Ubuntu 12.10 machine it means something like:
@@ -22,7 +21,7 @@ sudo dpkg -i /tmp/vagrant.deb
22
21
  ```
23
22
 
24
23
 
25
- ## What is currently supported? (v0.3.0)
24
+ ## What is currently supported?
26
25
 
27
26
  Pretty much everything you need from Vagrant:
28
27
 
@@ -40,8 +39,6 @@ and the [changelog](CHANGELOG.md) for most up to date information.*
40
39
 
41
40
  * Does not detect forwarded ports collision, right now you are responsible for taking care of that
42
41
  * A hell lot of `sudo`s (this will probably be like this until [user namespaces](http://s3hh.wordpress.com/2013/02/12/user-namespaces-lxc-meeting/) are supported)
43
- * Only a [single ubuntu box supported](boxes)
44
- * "[works on my machine](https://github.com/fgrehm/vagrant-lxc/issues/20)" (TM)
45
42
  * [Does not tell you if dependencies are not met](https://github.com/fgrehm/vagrant-lxc/issues/11)
46
43
  (will probably just throw up some random error)
47
44
  * + bunch of other [core features](https://github.com/fgrehm/vagrant-lxc/issues?labels=core&milestone=&page=1&state=open)
@@ -56,16 +53,17 @@ vagrant plugin install vagrant-lxc
56
53
 
57
54
  ## Usage
58
55
 
59
- After installing, add the quantal64 base box using any name you want:
56
+ After installing, add a [base box](#available-boxes) using any name you want, for example:
60
57
 
61
58
  ```
62
- vagrant box add lxc-quantal64 http://dl.dropbox.com/u/13510779/lxc-quantal64-2013-04-10.box
59
+ vagrant box add lxc-quantal64 http://dl.dropbox.com/u/13510779/lxc-quantal-amd64-2013-04-21.box
63
60
  ```
64
61
 
65
62
  Make a Vagrantfile that looks like the following, filling in your information where necessary:
66
63
 
67
64
  ```ruby
68
65
  Vagrant.configure("2") do |config|
66
+ # Change it to the name of the box you have just added
69
67
  config.vm.box = "lxc-quantal64"
70
68
 
71
69
  # You can omit this block if you don't need to override any container setting
@@ -83,6 +81,24 @@ And finally run `vagrant up --provider=lxc`.
83
81
  If you are on a mac or window host and still want to try this plugin out, you
84
82
  can use the [same Vagrant VirtualBox machine I use for development](#using-virtualbox-for-development).
85
83
 
84
+ ### Available boxes
85
+
86
+ | LINK | DESCRIPTION |
87
+ | --- | --- |
88
+ | [lxc-raring-amd64-2013-04-21.box](http://dl.dropbox.com/u/13510779/lxc-raring-amd64-2013-04-21.box) | Ubuntu 13.04 Raring x86_64 (Puppet 3.1.1) |
89
+ | [lxc-quantal-amd64-2013-04-21.box](http://dl.dropbox.com/u/13510779/lxc-quantal-amd64-2013-04-21.box) | Ubuntu 12.10 Quantal x86_64 (Puppet 3.1.1 & Chef 11.4.0) |
90
+ | [lxc-precise-amd64-2013-04-21.box](http://dl.dropbox.com/u/13510779/lxc-precise-amd64-2013-04-21.box) | Ubuntu 12.04 Precise x86_64 (Puppet 3.1.1 & Chef 11.4.0) |
91
+
92
+ *Please note that I'm currently using only the quantal x86_64 on a daily basis,
93
+ and I've only done some basic testing with the others*
94
+
95
+ You can also build a clean box by providing `CHEF=0` and `PUPPET=0` to the available
96
+ [rake tasks](tasks/boxes.rake). For example:
97
+
98
+ ```
99
+ CHEF=0 PUPPET=0 rake boxes:ubuntu:build:precise64
100
+ ```
101
+
86
102
  ### Storing container's rootfs on a separate partition
87
103
 
88
104
  Before the 0.3.0 version of this plugin, there used to be a support for specifying
@@ -104,7 +120,13 @@ If want to develop from your physical machine, just sing that same old song:
104
120
  git clone git://github.com/fgrehm/vagrant-lxc.git
105
121
  cd vagrant-lxc
106
122
  bundle install
107
- bundle exec rake # to run all specs
123
+ bundle exec rake # to run unit specs
124
+ ```
125
+
126
+ To run acceptance specs, you'll have to ssh into one of the [development boxes](development/Vagrantfile) and run:
127
+
128
+ ```
129
+ bundle exec rake spec:acceptance
108
130
  ```
109
131
 
110
132
  To build the provided quantal64 box:
@@ -179,6 +201,11 @@ and try to `vagrant reload` the dev box. If it still doesn't work,
179
201
  please file a bug at the [issue tracker](https://github.com/fgrehm/vagrant-lxc/issues).
180
202
 
181
203
 
204
+ ## Similar projects
205
+
206
+ * [vagabond](https://github.com/chrisroberts/vagabond) - "a tool integrated with Chef to build local nodes easily"
207
+ * [vagueant](https://github.com/neerolyte/vagueant) - "vaguely like Vagrant for linux containers (lxc)"
208
+
182
209
  ## Contributing
183
210
 
184
211
  1. Fork it
@@ -3,7 +3,6 @@
3
3
  # This is the code extracted from /usr/share/lxc/templates/lxc-ubuntu
4
4
  # that comes with Ubuntu 12.10 which is responsible for downloading the
5
5
  # rootfs files / packages
6
- # It also installs puppet and chef on the container
7
6
 
8
7
  set -e
9
8
 
@@ -92,8 +91,8 @@ EOF
92
91
  }
93
92
 
94
93
  declare cache=`readlink -f .` \
95
- arch=amd64 \
96
- release=quantal
94
+ arch=$1 \
95
+ release=$2
97
96
 
98
97
  if [ -d "${cache}/rootfs" ]; then
99
98
  echo 'The rootfs cache has been built already, please remove it if you want to update'
@@ -101,21 +100,3 @@ if [ -d "${cache}/rootfs" ]; then
101
100
  fi
102
101
 
103
102
  download_ubuntu $cache $arch $release
104
-
105
- rootfs="${cache}/rootfs"
106
-
107
- echo "installing puppet"
108
- wget http://apt.puppetlabs.com/puppetlabs-release-precise.deb -O "${rootfs}/tmp/puppetlabs-release-${release}.deb"
109
- chroot $rootfs dpkg -i "/tmp/puppetlabs-release-${release}.deb"
110
- chroot $rootfs apt-get update
111
- chroot $rootfs apt-get install puppet -y
112
-
113
- echo "installing chef"
114
- cat > $rootfs/tmp/install-chef.sh << EOF
115
- #!/bin/sh
116
- curl -L https://www.opscode.com/chef/install.sh -k | sudo bash
117
- EOF
118
- chmod +x $rootfs/tmp/install-chef.sh
119
- chroot $rootfs /tmp/install-chef.sh
120
-
121
- rm -rf $rootfs/tmp/*
@@ -0,0 +1,14 @@
1
+ #!/bin/bash
2
+
3
+ cache=`readlink -f .`
4
+ rootfs="${cache}/rootfs"
5
+
6
+ echo "installing chef"
7
+ cat > $rootfs/tmp/install-chef.sh << EOF
8
+ #!/bin/sh
9
+ curl -L https://www.opscode.com/chef/install.sh -k | sudo bash
10
+ EOF
11
+ chmod +x $rootfs/tmp/install-chef.sh
12
+ chroot $rootfs /tmp/install-chef.sh
13
+
14
+ rm -rf $rootfs/tmp/*
@@ -0,0 +1,12 @@
1
+ #!/bin/bash
2
+
3
+ cache=`readlink -f .`
4
+ rootfs="${cache}/rootfs"
5
+
6
+ echo "installing puppet"
7
+ wget http://apt.puppetlabs.com/puppetlabs-release-stable.deb -O "${rootfs}/tmp/puppetlabs-release-stable.deb"
8
+ chroot $rootfs dpkg -i "/tmp/puppetlabs-release-stable.deb"
9
+ chroot $rootfs apt-get update
10
+ chroot $rootfs apt-get install puppet -y
11
+
12
+ rm -rf $rootfs/tmp/*
@@ -469,7 +469,7 @@ if [ -f /etc/lsb-release ]; then
469
469
  fi
470
470
  fi
471
471
 
472
- arch=$(arch)
472
+ arch=$(uname -m)
473
473
 
474
474
  # Code taken from debootstrap
475
475
  if [ -x /usr/bin/dpkg ] && /usr/bin/dpkg --print-architecture >/dev/null 2>&1; then
@@ -477,7 +477,7 @@ if [ -x /usr/bin/dpkg ] && /usr/bin/dpkg --print-architecture >/dev/null 2>&1; t
477
477
  elif type udpkg >/dev/null 2>&1 && udpkg --print-architecture >/dev/null 2>&1; then
478
478
  arch=`/usr/bin/udpkg --print-architecture`
479
479
  else
480
- arch=$(arch)
480
+ arch=$(uname -m)
481
481
  if [ "$arch" = "i686" ]; then
482
482
  arch="i386"
483
483
  elif [ "$arch" = "x86_64" ]; then
@@ -3,7 +3,7 @@
3
3
  "version": "2",
4
4
 
5
5
  "template-opts": {
6
- "--arch": "amd64",
7
- "--release": "quantal"
6
+ "--arch": "ARCH",
7
+ "--release": "RELEASE"
8
8
  }
9
9
  }
@@ -25,17 +25,11 @@ end
25
25
  Vagrant.require_plugin 'vagrant-lxc'
26
26
 
27
27
  Vagrant.configure("2") do |config|
28
- config.vm.box = "quantal64"
29
-
30
- config.vm.synced_folder "../", "/vagrant", id: 'vagrant-root'
31
-
32
- cache_dir = local_apt_cache(config.vm.box)
33
- config.vm.synced_folder cache_dir, "/var/cache/apt/archives", id: "vagrant-apt-cache"
34
-
35
- cache_dir = local_gem_cache(config.vm.box)
36
- config.vm.synced_folder cache_dir, "/home/vagrant/gems/cache", id: "vagrant-gem-cache"
28
+ config.vm.synced_folder "../", "/vagrant", id: 'vagrant-root', nfs: true
37
29
 
38
30
  config.vm.define :vbox do |vb_config|
31
+ vb_config.vm.network :private_network, ip: "192.168.50.33"
32
+ vb_config.vm.box = 'quantal64'
39
33
  vb_config.vm.box_url = "https://github.com/downloads/roderik/VagrantQuantal64Box/quantal64.box"
40
34
  vb_config.vm.hostname = 'vbox'
41
35
 
@@ -47,17 +41,62 @@ Vagrant.configure("2") do |config|
47
41
  "--cpus", '2'
48
42
  ]
49
43
  end
44
+
45
+ cache_dir = local_apt_cache(vb_config.vm.box)
46
+ vb_config.vm.synced_folder cache_dir, "/var/cache/apt/archives", id: "vagrant-apt-cache"
47
+
48
+ cache_dir = local_gem_cache(vb_config.vm.box)
49
+ vb_config.vm.synced_folder cache_dir, "/home/vagrant/gems/cache", id: "vagrant-gem-cache"
50
50
  end
51
51
 
52
52
  config.vm.define :precise do |precise|
53
+ precise.vm.network :private_network, ip: "192.168.50.32"
53
54
  precise.vm.box = 'precise64'
54
55
  precise.vm.hostname = 'vbox'
55
56
  precise.vm.box_url = 'http://files.vagrantup.com/precise64.box'
57
+
58
+ precise.vm.provider :virtualbox do |vb|
59
+ # Configure VM to use 1.5gb of ram and 2 cpus
60
+ vb.customize [
61
+ "modifyvm", :id,
62
+ "--memory", '1536',
63
+ "--cpus", '2'
64
+ ]
65
+ end
66
+
67
+ cache_dir = local_apt_cache(precise.vm.box)
68
+ precise.vm.synced_folder cache_dir, "/var/cache/apt/archives", id: "vagrant-apt-cache"
69
+
70
+ cache_dir = local_gem_cache(precise.vm.box)
71
+ precise.vm.synced_folder cache_dir, "/home/vagrant/gems/cache", id: "vagrant-gem-cache"
72
+ end
73
+
74
+ config.vm.define :raring do |raring|
75
+ raring.vm.network :private_network, ip: "192.168.50.34"
76
+ raring.vm.box = 'raring64'
77
+ raring.vm.hostname = 'vbox'
78
+ raring.vm.box_url = 'http://cloud-images.ubuntu.com/vagrant/raring/current/raring-server-cloudimg-amd64-vagrant-disk1.box'
79
+
80
+ raring.vm.provider :virtualbox do |vb|
81
+ # Configure VM to use 1.5gb of ram and 2 cpus
82
+ vb.customize [
83
+ "modifyvm", :id,
84
+ "--memory", '1536',
85
+ "--cpus", '2'
86
+ ]
87
+ end
88
+
89
+ cache_dir = local_apt_cache(raring.vm.box)
90
+ raring.vm.synced_folder cache_dir, "/var/cache/apt/archives", id: "vagrant-apt-cache"
91
+
92
+ cache_dir = local_gem_cache(raring.vm.box)
93
+ raring.vm.synced_folder cache_dir, "/home/vagrant/gems/cache", id: "vagrant-gem-cache"
56
94
  end
57
95
 
58
96
  config.vm.define :lxc do |lxc_config|
97
+ lxc_config.vm.box = 'quantal64'
59
98
  lxc_config.vm.hostname = 'lxc-dev-box'
60
- lxc_config.vm.box_url = 'http://dl.dropbox.com/u/13510779/lxc-quantal64-2013-04-10.box'
99
+ lxc_config.vm.box_url = 'http://dl.dropbox.com/u/13510779/lxc-quantal64-2013-04-21.box'
61
100
  # Uncomment to test boxes built locally:
62
101
  # lxc_config.vm.box_url = '../boxes/output/lxc-quantal64.box'
63
102
 
data/development/site.pp CHANGED
@@ -21,7 +21,7 @@ exec {
21
21
  # Install dependencies
22
22
  package {
23
23
  [ 'libffi-dev', 'bsdtar', 'exuberant-ctags', 'ruby1.9.1-dev', 'htop', 'git',
24
- 'build-essential', 'redir' ]:
24
+ 'build-essential', 'redir', 'curl' ]:
25
25
  ensure => 'installed'
26
26
  ;
27
27
 
@@ -43,7 +43,7 @@ if $hostname == 'vbox' {
43
43
 
44
44
  # TMUX
45
45
  package {
46
- 'tmux': ensure => 'installed';
46
+ 'tmux': ensure => 'installed';
47
47
  }
48
48
 
49
49
  # Allow gems to be installed on vagrant user home avoiding "sudo"s
data/example/Vagrantfile CHANGED
@@ -5,15 +5,8 @@
5
5
  Vagrant.require_plugin 'vagrant-lxc'
6
6
 
7
7
  Vagrant.configure("2") do |config|
8
- config.vm.box = "quantal64"
9
- config.vm.box_url = 'http://dl.dropbox.com/u/13510779/lxc-quantal64-2013-04-10.box'
10
- # Uncomment if you want to try out a box built locally
11
- # config.vm.box_url = '../boxes/output/lxc-quantal64.box'
12
- config.vm.hostname = 'lxc-quantal64-example'
13
-
14
8
  config.vm.synced_folder "/tmp", "/vagrant_data"
15
9
 
16
-
17
10
  config.vm.provider :lxc do |lxc|
18
11
  lxc.customize 'cgroup.memory.limit_in_bytes', '400M'
19
12
  lxc.customize 'cgroup.memory.memsw.limit_in_bytes', '500M'
@@ -33,4 +26,17 @@ echo "Hi there I'm a shell script used for provisioning"
33
26
  chef.add_recipe "hello-world"
34
27
  chef.log_level = :debug
35
28
  end
29
+
30
+ port = 8080
31
+ releases = %w(precise quantal raring)
32
+ releases.each do |release|
33
+ config.vm.define(release) do |lxc_config|
34
+ lxc_config.vm.box = "#{release}64"
35
+ lxc_config.vm.box_url = "http://dl.dropbox.com/u/13510779/lxc-#{release}-amd64-2013-04-21.box"
36
+ # Uncomment if you want to try out a box built locally
37
+ # lxc_config.vm.box_url = "../boxes/output/lxc-#{release}64.box"
38
+ lxc_config.vm.hostname = "lxc-#{release}64-example"
39
+ lxc_config.vm.network :forwarded_port, guest: 80, host: (port += 1)
40
+ end
41
+ end
36
42
  end
@@ -15,7 +15,7 @@ module Vagrant
15
15
  redir_pids.each do |pid|
16
16
  next unless is_redir_pid?(pid)
17
17
  @logger.debug "Killing pid #{pid}"
18
- system "sudo pkill -9 -P #{pid}"
18
+ system "sudo pkill -TERM -P #{pid}"
19
19
  end
20
20
 
21
21
  remove_redir_pids
@@ -68,7 +68,7 @@ module Vagrant
68
68
  redir_cmd = "sudo redir --laddr=127.0.0.1 --lport=#{host} --cport=#{guest} --caddr=#{@container_ip} 2>/dev/null"
69
69
 
70
70
  @logger.debug "Forwarding port with `#{redir_cmd}`"
71
- fork { exec redir_cmd }
71
+ spawn redir_cmd
72
72
  end
73
73
 
74
74
  def store_redir_pid(host_port, redir_pid)
@@ -1,5 +1,5 @@
1
1
  module Vagrant
2
2
  module LXC
3
- VERSION = "0.3.2"
3
+ VERSION = "0.3.3"
4
4
  end
5
5
  end
data/spec/Vagrantfile ADDED
@@ -0,0 +1,33 @@
1
+ # -*- mode: ruby -*-
2
+ # vi: set ft=ruby :
3
+
4
+ def local_apt_cache(box_name)
5
+ cache_dir = File.join(File.expand_path(Vagrant::Environment::DEFAULT_HOME),
6
+ 'cache',
7
+ 'apt',
8
+ box_name)
9
+ partial_dir = File.join(cache_dir, 'partial')
10
+ FileUtils.mkdir_p(partial_dir) unless File.exists? partial_dir
11
+ cache_dir
12
+ end
13
+
14
+ Vagrant.require_plugin 'vagrant-lxc'
15
+
16
+ Vagrant.configure("2") do |config|
17
+ config.vm.box = "quantal64"
18
+ config.vm.hostname = 'lxc-test-box'
19
+
20
+ config.vm.box_url = 'http://dl.dropbox.com/u/13510779/lxc-quantal64-2013-04-10.box'
21
+ # Uncomment to test boxes built locally:
22
+ # config.vm.box_url = '../boxes/output/lxc-quantal64.box'
23
+
24
+ cache_dir = local_apt_cache(config.vm.box)
25
+ config.vm.synced_folder cache_dir, "/var/cache/apt/archives", id: "vagrant-apt-cache"
26
+
27
+ config.vm.provision :shell,
28
+ inline: 'mkdir -p /vagrant/tmp && echo -n "Provisioned" > /vagrant/tmp/provisioning'
29
+
30
+ config.vm.network :forwarded_port, guest: 80, host: 8080
31
+ config.vm.provision :shell,
32
+ inline: 'sudo apt-get install nginx -y && sudo service nginx start'
33
+ end
@@ -0,0 +1,79 @@
1
+ require 'acceptance_helper'
2
+
3
+ describe 'Sanity check' do
4
+ after(:all) { destroy_container }
5
+
6
+ context 'running `vagrant up` from scratch' do
7
+ before(:all) do
8
+ destroy_container
9
+ vagrant_up
10
+ end
11
+
12
+ it 'creates a container' do
13
+ containers = `sudo lxc-ls`.chomp.split(/\s+/).uniq
14
+ expect(containers).to include vagrant_container_name
15
+ end
16
+
17
+ it 'starts the newly created container' do
18
+ status = `sudo lxc-info -n #{vagrant_container_name}`
19
+ expect(status).to include 'RUNNING'
20
+ end
21
+
22
+ it "is able to be SSH'ed" do
23
+ expect(vagrant_ssh('hostname')).to eq 'lxc-test-box'
24
+ end
25
+
26
+ it 'mounts shared folders with the right permissions' do
27
+ vagrant_ssh 'mkdir -p /vagrant/tmp && echo -n "Shared" > /vagrant/tmp/shared'
28
+ shared_file_contents = File.read('/vagrant/spec/tmp/shared')
29
+ expect(shared_file_contents).to eq 'Shared'
30
+ end
31
+
32
+ it 'provisions the container based on Vagrantfile configs' do
33
+ provisioned_file_contents = File.read('/vagrant/spec/tmp/provisioning')
34
+ expect(provisioned_file_contents).to eq 'Provisioned'
35
+ end
36
+
37
+ it 'forwards configured ports' do
38
+ output = `curl -s localhost:8080`.strip.chomp
39
+ expect(output).to include 'Welcome to nginx!'
40
+ end
41
+ end
42
+
43
+ context '`vagrant halt` on a running container' do
44
+ before(:all) do
45
+ destroy_container
46
+ vagrant_up
47
+ vagrant_halt
48
+ end
49
+
50
+ it 'shuts down container' do
51
+ status = `sudo lxc-info -n #{vagrant_container_name}`
52
+ expect(status).to include 'STOPPED'
53
+ end
54
+
55
+ it 'clears forwarded ports' do
56
+ `curl -s localhost:8080 --connect-timeout 2`
57
+ expect($?.exitstatus).to_not eq 0
58
+ end
59
+
60
+ it 'kills redir processes' do
61
+ processes = `pgrep redir`
62
+ expect($?.exitstatus).to_not eq 0
63
+ end
64
+ end
65
+
66
+ context '`vagrant destroy`' do
67
+ before(:all) do
68
+ destroy_container
69
+ vagrant_up
70
+ @container_name = vagrant_container_name
71
+ vagrant_destroy
72
+ end
73
+
74
+ it 'destroys the underlying container' do
75
+ containers = `sudo lxc-ls`.chomp.split(/\s+/).uniq
76
+ expect(containers).to_not include @container_name
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,56 @@
1
+ module AcceptanceExampleGroup
2
+ def self.included(base)
3
+ base.metadata[:type] = :acceptance
4
+ end
5
+
6
+ ID_FILE = "/vagrant/spec/.vagrant/machines/default/lxc/id"
7
+ def vagrant_container_name
8
+ File.read(ID_FILE).strip.chomp if File.exists?(ID_FILE)
9
+ end
10
+
11
+ def destroy_container
12
+ if name = vagrant_container_name
13
+ `sudo lxc-shutdown -n #{name} 2>/dev/null`
14
+ `sudo lxc-wait -n #{name} --state STOPPED 2>/dev/null`
15
+ `sudo lxc-destroy -n #{name} 2>/dev/null`
16
+ end
17
+ `sudo killall -9 redir 2>/dev/null`
18
+ end
19
+
20
+ def with_vagrant_environment
21
+ opts = { cwd: 'spec', ui_class: TestUI }
22
+ env = Vagrant::Environment.new(opts)
23
+ yield env
24
+ env.unload
25
+ end
26
+
27
+ def vagrant_up
28
+ with_vagrant_environment do |env|
29
+ env.cli('up', '--provider', 'lxc')
30
+ end
31
+ end
32
+
33
+ def vagrant_halt
34
+ with_vagrant_environment do |env|
35
+ env.cli('halt')
36
+ end
37
+ end
38
+
39
+ def vagrant_destroy
40
+ with_vagrant_environment do |env|
41
+ env.cli('destroy', '-f')
42
+ end
43
+ end
44
+
45
+ def vagrant_ssh(cmd)
46
+ output = nil
47
+ with_vagrant_environment do |env|
48
+ result = env.cli('ssh', '-c', cmd)
49
+ if result.to_i != 0
50
+ raise "SSH command failed: '#{cmd}'\n#{env.ui.messages.inspect}"
51
+ end
52
+ output = env.ui.messages[:info].join("\n").chomp
53
+ end
54
+ output
55
+ end
56
+ end
@@ -0,0 +1,13 @@
1
+ # Monkey patch vagrant in order to reuse the UI test object that is set on
2
+ # our Vagrant::Environments
3
+ #
4
+ # TODO: Find out if this makes sense to be on vagrant core itself
5
+ require 'vagrant/machine'
6
+ Vagrant::Machine.class_eval do
7
+ alias :old_action :action
8
+
9
+ define_method :action do |name, extra_env = nil|
10
+ extra_env = { ui: @env.ui }.merge(extra_env || {})
11
+ old_action name, extra_env
12
+ end
13
+ end
@@ -0,0 +1,22 @@
1
+ class TestUI < Vagrant::UI::Interface
2
+ attr_reader :messages
3
+
4
+ METHODS = [:clear_line, :report_progress, :warn, :error, :info, :success]
5
+
6
+ def initialize(resource = nil)
7
+ super
8
+ @messages = METHODS.each_with_object({}) { |m, h| h[m] = [] }
9
+ end
10
+
11
+ def ask(*args)
12
+ super
13
+ # Automated tests should not depend on user input, obviously.
14
+ raise Errors::UIExpectsTTY
15
+ end
16
+
17
+ METHODS.each do |method|
18
+ define_method(method) do |message, *opts|
19
+ @messages[method].push message
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ unless ENV['USER'] == 'vagrant'
4
+ puts 'Acceptance specs are supposed to run from one of the vagrant-lxc dev machines'
5
+ exit 1
6
+ end
7
+
8
+ if defined? SimpleCov
9
+ SimpleCov.command_name 'acceptance'
10
+ end
11
+
12
+ require 'vagrant'
13
+ require 'vagrant-lxc'
14
+
15
+ Dir[File.dirname(__FILE__) + "/acceptance/support/**/*.rb"].each { |f| require f }
16
+
17
+ RSpec.configure do |config|
18
+ config.include AcceptanceExampleGroup, :type => :acceptance, :example_group => {
19
+ :file_path => /\bspec\/acceptance\//
20
+ }
21
+ end
data/spec/spec_helper.rb CHANGED
@@ -2,14 +2,8 @@ if ENV['COVERAGE']
2
2
  require 'simplecov'
3
3
  require 'coveralls'
4
4
 
5
- SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
6
- SimpleCov::Formatter::HTMLFormatter,
7
- Coveralls::SimpleCov::Formatter
8
- ]
9
-
10
- SimpleCov.start do
11
- add_filter { |source_file| source_file.filename =~ /\/spec\/support/ }
12
- end
5
+ SimpleCov.start { add_filter '/spec/' }
6
+ SimpleCov.merge_timeout 300
13
7
  end
14
8
 
15
9
  require 'bundler/setup'
File without changes
@@ -28,15 +28,15 @@ describe Vagrant::LXC::Action::ClearForwardedPorts do
28
28
 
29
29
  context 'with a valid redir pid' do
30
30
  it 'kills known processes' do
31
- subject.should have_received(:system).with("sudo pkill -9 -P #{pid}")
31
+ subject.should have_received(:system).with("sudo pkill -TERM -P #{pid}")
32
32
  end
33
33
  end
34
34
 
35
35
  context 'with an invalid pid' do
36
- let(:pid_cmd) { 'sudo ls' }
36
+ let(:pid_cmd) { 'sudo ls' }
37
37
 
38
38
  it 'does not kill the process' do
39
- subject.should_not have_received(:system).with("sudo pkill -9 -P #{pid}")
39
+ subject.should_not have_received(:system).with("sudo pkill -TERM -P #{pid}")
40
40
  end
41
41
  end
42
42
  end
@@ -22,14 +22,14 @@ describe Vagrant::LXC::Action::ForwardPorts do
22
22
  machine.stub(provider: provider, data_dir: data_dir)
23
23
 
24
24
  subject.stub(exec: true)
25
- subject.stub(:fork) { |&block| block.call; pid }
25
+ subject.stub(spawn: pid)
26
26
  subject.call(env)
27
27
  end
28
28
 
29
29
  after { FileUtils.rm_rf data_dir.to_s }
30
30
 
31
31
  it 'forwards ports using redir' do
32
- subject.should have_received(:exec).with(
32
+ subject.should have_received(:spawn).with(
33
33
  "sudo redir --laddr=127.0.0.1 --lport=#{host_port} --cport=#{guest_port} --caddr=#{container_ip} 2>/dev/null"
34
34
  )
35
35
  end
@@ -14,6 +14,9 @@ module UnitExampleGroup
14
14
  Object.any_instance.stub(:fork) { |*args, &block|
15
15
  UnitExampleGroup.prevent_system_calls(*args, &block)
16
16
  }
17
+ Object.any_instance.stub(:spawn) { |*args, &block|
18
+ UnitExampleGroup.prevent_system_calls(*args, &block)
19
+ }
17
20
  require 'vagrant/util/subprocess'
18
21
  Vagrant::Util::Subprocess.stub(:execute) { |*args, &block|
19
22
  UnitExampleGroup.prevent_system_calls(*args, &block)
data/spec/unit_helper.rb CHANGED
@@ -1,5 +1,11 @@
1
1
  require 'spec_helper'
2
2
 
3
+ Dir[File.dirname(__FILE__) + "/unit/support/**/*.rb"].each { |f| require f }
4
+
5
+ if defined? SimpleCov
6
+ SimpleCov.command_name 'unit'
7
+ end
8
+
3
9
  RSpec.configure do |config|
4
10
  config.include RSpec::Fire
5
11
 
data/tasks/boxes.rake CHANGED
@@ -1,18 +1,79 @@
1
- namespace :boxes do
2
- namespace :quantal64 do
3
- desc 'Build Ubuntu Quantal 64 bits Vagrant LXC box'
4
- task :build do
5
- if File.exists?('./boxes/output/lxc-quantal64.box')
6
- puts 'Box has been built already!'
7
- exit 1
1
+ require 'rake/tasklib'
2
+
3
+ class BuildUbuntuBoxTask < ::Rake::TaskLib
4
+ include ::Rake::DSL
5
+
6
+ attr_reader :name
7
+
8
+ def initialize(name, release, arch, opts = {})
9
+ @name = name
10
+ @release = release.to_s
11
+ @arch = arch.to_s
12
+ @install_chef = opts.fetch(:chef, true)
13
+ @install_puppet = opts.fetch(:puppet, true)
14
+ @file = opts[:file] || default_box_file
15
+
16
+ desc "Build an Ubuntu #{release} #{arch} box" unless ::Rake.application.last_comment
17
+ task name do
18
+ RakeFileUtils.send(:verbose, true) do
19
+ run_task
8
20
  end
21
+ end
22
+ end
23
+
24
+ def run_task
25
+ if File.exists?("./boxes/output/#{@file}")
26
+ puts 'Box has been built already!'
27
+ exit 1
28
+ end
29
+
30
+ if Dir.exists?('boxes/temp')
31
+ puts "There is a partially built box under #{File.expand_path('./boxes/temp')}, please remove it before building a new box"
32
+ exit 1
33
+ end
34
+
35
+ sh 'mkdir -p boxes/temp/'
36
+ Dir.chdir 'boxes/temp' do
37
+ sh "sudo ../ubuntu/download #{@arch} #{@release}"
38
+ sh "sudo ../ubuntu/install-puppet" if @install_puppet
39
+ sh "sudo ../ubuntu/install-chef" if @install_chef
40
+ sh 'sudo rm -f rootfs.tar.gz'
41
+ sh 'sudo tar --numeric-owner -czf rootfs.tar.gz ./rootfs/*'
42
+ sh 'sudo rm -rf rootfs'
43
+ sh "sudo chown #{ENV['USER']}:#{ENV['USER']} rootfs.tar.gz"
44
+ sh "cp ../ubuntu/lxc-template ."
45
+ metadata = File.read('../ubuntu/metadata.json.template')
46
+ metadata.gsub!('ARCH', @arch)
47
+ metadata.gsub!('RELEASE', @release)
48
+ File.open('metadata.json', 'w') { |f| f.print metadata }
49
+ sh "tar -czf tmp-package.box ./*"
50
+ end
51
+
52
+ sh "cp boxes/temp/tmp-package.box boxes/output/#{@file}"
53
+ sh "rm -rf boxes/temp"
54
+ end
55
+
56
+ def default_box_file
57
+ require 'time'
58
+ "lxc-#{@release}-#{@arch}-#{Date.today}.box"
59
+ end
60
+ end
61
+
62
+ namespace :boxes do
63
+ namespace :ubuntu do
64
+ namespace :build do
65
+ chef = ENV['CHEF'] != '0'
66
+ puppet = ENV['PUPPET'] != '0'
67
+
68
+ desc 'Build an Ubuntu Precise 64 bits box'
69
+ BuildUbuntuBoxTask.new(:precise64, :precise, 'amd64', chef: chef, puppet: puppet)
70
+
71
+ desc 'Build an Ubuntu Quantal 64 bits box'
72
+ BuildUbuntuBoxTask.new(:quantal64, :quantal, 'amd64', chef: chef, puppet: puppet)
9
73
 
10
- sh 'mkdir -p boxes/output'
11
- sh 'cd boxes/quantal64 && sudo ./download-ubuntu'
12
- sh 'rm -f boxes/quantal64/rootfs.tar.gz'
13
- sh 'cd boxes/quantal64 && sudo tar --numeric-owner -czf rootfs.tar.gz ./rootfs/*'
14
- sh 'cd boxes/quantal64 && sudo rm -rf rootfs'
15
- sh "cd boxes/quantal64 && sudo chown #{ENV['USER']}:#{ENV['USER']} rootfs.tar.gz && tar -czf ../output/lxc-quantal64.box ./* --exclude=download-ubuntu"
74
+ # FIXME: Find out how to install chef on raring
75
+ desc 'Build an Ubuntu Raring 64 bits box'
76
+ BuildUbuntuBoxTask.new(:raring64, :raring, 'amd64', chef: false, puppet: puppet)
16
77
  end
17
78
  end
18
79
  end
data/tasks/spec.rake CHANGED
@@ -1,12 +1,15 @@
1
1
  begin
2
2
  require 'rspec/core/rake_task'
3
+ require 'coveralls/rake/task'
3
4
 
4
- # TODO: add 'spec:acceptance' and 'spec:integration' then they are in place
5
5
  desc 'Run all specs'
6
- task :spec => ['spec:unit']
6
+ task :spec => ['spec:unit', 'spec:acceptance']
7
7
 
8
8
  desc 'Default task which runs all specs with code coverage enabled'
9
- task :default => ['spec:set_coverage', 'spec']
9
+ task :default => ['spec:set_coverage', 'spec:unit']
10
+
11
+ Coveralls::RakeTask.new
12
+ task :ci => ['spec:set_coverage', 'spec:unit', 'coveralls:push']
10
13
  rescue LoadError; end
11
14
 
12
15
  namespace :spec 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.3.2
4
+ version: 0.3.3
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-04-19 00:00:00.000000000 Z
11
+ date: 2013-04-23 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Linux Containers provider for Vagrant
14
14
  email:
@@ -28,9 +28,11 @@ files:
28
28
  - LICENSE.txt
29
29
  - README.md
30
30
  - Rakefile
31
- - boxes/quantal64/download-ubuntu
32
- - boxes/quantal64/lxc-template
33
- - boxes/quantal64/metadata.json
31
+ - boxes/ubuntu/download
32
+ - boxes/ubuntu/install-chef
33
+ - boxes/ubuntu/install-puppet
34
+ - boxes/ubuntu/lxc-template
35
+ - boxes/ubuntu/metadata.json.template
34
36
  - development/Vagrantfile
35
37
  - development/lxc-configs/lxc-dev-box
36
38
  - development/lxc-configs/vbox
@@ -70,9 +72,15 @@ files:
70
72
  - lib/vagrant-lxc/provider.rb
71
73
  - lib/vagrant-lxc/version.rb
72
74
  - locales/en.yml
75
+ - spec/Vagrantfile
76
+ - spec/acceptance/sanity_check_spec.rb
77
+ - spec/acceptance/support/acceptance_example_group.rb
78
+ - spec/acceptance/support/machine_ext.rb
79
+ - spec/acceptance/support/test_ui.rb
80
+ - spec/acceptance_helper.rb
73
81
  - spec/fixtures/sample-ip-addr-output
74
82
  - spec/spec_helper.rb
75
- - spec/support/unit_example_group.rb
83
+ - spec/support/.gitkeep
76
84
  - spec/unit/action/clear_forwarded_ports_spec.rb
77
85
  - spec/unit/action/compress_rootfs_spec.rb
78
86
  - spec/unit/action/forward_ports_spec.rb
@@ -80,6 +88,7 @@ files:
80
88
  - spec/unit/action/setup_package_files_spec.rb
81
89
  - spec/unit/driver/cli_spec.rb
82
90
  - spec/unit/driver_spec.rb
91
+ - spec/unit/support/unit_example_group.rb
83
92
  - spec/unit_helper.rb
84
93
  - tasks/boxes.rake
85
94
  - tasks/spec.rake
@@ -108,9 +117,15 @@ signing_key:
108
117
  specification_version: 4
109
118
  summary: Linux Containers provider for Vagrant
110
119
  test_files:
120
+ - spec/Vagrantfile
121
+ - spec/acceptance/sanity_check_spec.rb
122
+ - spec/acceptance/support/acceptance_example_group.rb
123
+ - spec/acceptance/support/machine_ext.rb
124
+ - spec/acceptance/support/test_ui.rb
125
+ - spec/acceptance_helper.rb
111
126
  - spec/fixtures/sample-ip-addr-output
112
127
  - spec/spec_helper.rb
113
- - spec/support/unit_example_group.rb
128
+ - spec/support/.gitkeep
114
129
  - spec/unit/action/clear_forwarded_ports_spec.rb
115
130
  - spec/unit/action/compress_rootfs_spec.rb
116
131
  - spec/unit/action/forward_ports_spec.rb
@@ -118,4 +133,5 @@ test_files:
118
133
  - spec/unit/action/setup_package_files_spec.rb
119
134
  - spec/unit/driver/cli_spec.rb
120
135
  - spec/unit/driver_spec.rb
136
+ - spec/unit/support/unit_example_group.rb
121
137
  - spec/unit_helper.rb