vagrant-lxc 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +0 -1
- data/CHANGELOG.md +8 -0
- data/Gemfile.lock +1 -1
- data/README.md +9 -20
- data/boxes/quantal64/lxc-template +2 -2
- data/development/{Vagrantfile.1.1 → Vagrantfile} +2 -0
- data/lib/vagrant-lxc/action/create.rb +6 -1
- data/lib/vagrant-lxc/action/forward_ports.rb +1 -1
- data/lib/vagrant-lxc/config.rb +8 -1
- data/lib/vagrant-lxc/container/cli.rb +6 -3
- data/lib/vagrant-lxc/container.rb +5 -8
- data/lib/vagrant-lxc/provider.rb +2 -2
- data/lib/vagrant-lxc/version.rb +1 -1
- data/spec/unit/container/cli_spec.rb +23 -11
- data/spec/unit/container_spec.rb +7 -3
- metadata +3 -4
- data/development/Vagrantfile.1.0 +0 -36
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 92bccd1befe677dbdc19efd2a933735360940bbf
|
4
|
+
data.tar.gz: 94562a0d7b89f14d4813f3c914dc6ed71083358d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b45e42a6f567badf41f207056a47e408714c5c9571760502ec91d64439100558d9e20eac33810d0d40965a82a2bda9b091c7726ca56d950940ba989dfd55f49c
|
7
|
+
data.tar.gz: 730254e8c4288d87a36a60255e0c0c6aae18f2abacfccb76bea7ccad5d9b151cecbbd68c36b44e2e1859c35efa99651a2a57f5ecbf350671192819da827d7167
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
## [0.1.1](https://github.com/fgrehm/vagrant-lxc/pull/43)
|
2
|
+
|
3
|
+
- Removed support for development under Vagrant < 1.1
|
4
|
+
- Removed rsync from base quantal64 box to speed up containers creation [#40](https://github.com/fgrehm/vagrant-lxc/issues/40)
|
5
|
+
- Containers are now named after project's root dir [#14](https://github.com/fgrehm/vagrant-lxc/issues/14)
|
6
|
+
- Skip Vagrant's built in SSH redirect
|
7
|
+
- Allow setting rootfs from Vagrantfile [#30](https://github.com/fgrehm/vagrant-lxc/issues/30)
|
8
|
+
|
1
9
|
## 0.1.0
|
2
10
|
|
3
11
|
- Support for chef added to base quantal64 box
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
# vagrant-lxc [![Build Status](https://travis-ci.org/fgrehm/vagrant-lxc.png?branch=master)](https://travis-ci.org/fgrehm/vagrant-lxc) [![Gem Version](https://badge.fury.io/rb/vagrant-lxc.png)](http://badge.fury.io/rb/vagrant-lxc) [![Code Climate](https://codeclimate.com/github/fgrehm/vagrant-lxc.png)](https://codeclimate.com/github/fgrehm/vagrant-lxc)
|
2
2
|
|
3
|
-
Experimental Linux Containers support for Vagrant
|
3
|
+
Experimental Linux Containers support for Vagrant 1.1+
|
4
4
|
|
5
5
|
|
6
6
|
## Dependencies
|
7
7
|
|
8
|
-
Vagrant
|
8
|
+
Vagrant 1.1+ (1.1.4+ recommended), `lxc` and `redir` packages and a Kernel [higher than 3.5.0-17.28](#help-im-unable-to-restart-containers),
|
9
9
|
which on Ubuntu 12.10 means something like:
|
10
10
|
|
11
11
|
```
|
@@ -16,7 +16,7 @@ sudo dpkg -i /tmp/vagrant.deb
|
|
16
16
|
```
|
17
17
|
|
18
18
|
|
19
|
-
## What is currently supported? (v0.1.
|
19
|
+
## What is currently supported? (v0.1.1)
|
20
20
|
|
21
21
|
* Vagrant's `up`, `halt`, `reload`, `destroy`, and `ssh` commands
|
22
22
|
* Shared folders
|
@@ -30,7 +30,7 @@ for the most up to date list.*
|
|
30
30
|
|
31
31
|
## Current limitations
|
32
32
|
|
33
|
-
*
|
33
|
+
* Does not detect forwarded ports collision, right now you are responsible for taking care of that
|
34
34
|
* A hell lot of `sudo`s
|
35
35
|
* Only a [single ubuntu box supported](boxes), I'm still [figuring out what should go
|
36
36
|
on the .box file](https://github.com/fgrehm/vagrant-lxc/issues/4)
|
@@ -43,7 +43,7 @@ for the most up to date list.*
|
|
43
43
|
|
44
44
|
## Usage
|
45
45
|
|
46
|
-
Make sure you have [Vagrant 1.1](http://downloads.vagrantup.com/
|
46
|
+
Make sure you have [Vagrant 1.1+](http://downloads.vagrantup.com/) and run:
|
47
47
|
|
48
48
|
```
|
49
49
|
vagrant plugin install vagrant-lxc
|
@@ -52,8 +52,6 @@ vagrant plugin install vagrant-lxc
|
|
52
52
|
After that you can create a `Vagrantfile` like the one below and run `vagrant up --provider=lxc`:
|
53
53
|
|
54
54
|
```ruby
|
55
|
-
Vagrant.require_plugin 'vagrant-lxc'
|
56
|
-
|
57
55
|
Vagrant.configure("2") do |config|
|
58
56
|
config.vm.box = "lxc-quantal64"
|
59
57
|
config.vm.box_url = 'http://dl.dropbox.com/u/13510779/lxc-quantal64-2013-03-26.box'
|
@@ -65,6 +63,8 @@ Vagrant.configure("2") do |config|
|
|
65
63
|
config.vm.synced_folder "/tmp", "/host_tmp"
|
66
64
|
|
67
65
|
config.vm.provider :lxc do |lxc|
|
66
|
+
# Set the folder where container's rootfs will be stored when created
|
67
|
+
lxc.target_rootfs_path = '/path/to/container/rootfs'
|
68
68
|
# Same as 'customize ["modifyvm", :id, "--memory", "1024"]' for VirtualBox
|
69
69
|
lxc.start_opts << 'lxc.cgroup.memory.limit_in_bytes=400M'
|
70
70
|
# Limits swap size
|
@@ -111,7 +111,6 @@ sudo apt-get install apparmor-utils
|
|
111
111
|
sudo aa-complain /usr/bin/lxc-start
|
112
112
|
bundle install
|
113
113
|
cd development
|
114
|
-
ln -s Vagrantfile.1.1 Vagrantfile
|
115
114
|
bundle exec vagrant up lxc --provider=lxc
|
116
115
|
bundle exec vagrant ssh lxc
|
117
116
|
```
|
@@ -122,26 +121,16 @@ Keep in mind that you'll probably need to run `sudo aa-complain /usr/bin/lxc-sta
|
|
122
121
|
on the host whenever you want to hack on it, otherwise you won't be able to
|
123
122
|
start nested containers there to try things out.
|
124
123
|
|
125
|
-
### Using VirtualBox
|
124
|
+
### Using VirtualBox for development
|
126
125
|
|
127
126
|
```
|
128
127
|
cd development
|
129
|
-
ln -s Vagrantfile.1.1 Vagrantfile
|
130
128
|
bundle exec vagrant up vbox
|
129
|
+
# A reload is needed to ensure the updated kernel gets loaded
|
131
130
|
bundle exec vagrant reload vbox
|
132
131
|
bundle exec vagrant ssh vbox
|
133
132
|
```
|
134
133
|
|
135
|
-
### Using VirtualBox and Vagrant 1.0 for development
|
136
|
-
|
137
|
-
```
|
138
|
-
cd development
|
139
|
-
ln -s Vagrantfile.1.0 Vagrantfile
|
140
|
-
vagrant up
|
141
|
-
vagrant reload
|
142
|
-
vagrant ssh
|
143
|
-
```
|
144
|
-
|
145
134
|
|
146
135
|
## Protips
|
147
136
|
|
@@ -161,8 +161,8 @@ copy_ubuntu()
|
|
161
161
|
|
162
162
|
# make a local copy of the miniubuntu
|
163
163
|
echo "Copying rootfs to $rootfs ..."
|
164
|
-
mkdir -p $rootfs
|
165
|
-
|
164
|
+
mkdir -p $(dirname $rootfs)
|
165
|
+
mv $cache/rootfs-$arch $rootfs || return 1
|
166
166
|
return 0
|
167
167
|
}
|
168
168
|
|
@@ -50,6 +50,8 @@ Vagrant.configure("2") do |config|
|
|
50
50
|
|
51
51
|
config.vm.define :lxc do |lxc_config|
|
52
52
|
lxc_config.vm.hostname = 'lxc-dev-box'
|
53
|
+
# Uncomment to test boxes built locally:
|
54
|
+
# lxc_config.vm.box_url = '../boxes/output/lxc-quantal64.box'
|
53
55
|
lxc_config.vm.box_url = 'http://dl.dropbox.com/u/13510779/lxc-quantal64-2013-03-26.box'
|
54
56
|
|
55
57
|
lxc_config.vm.provider :lxc do |lxc|
|
@@ -3,7 +3,12 @@ module Vagrant
|
|
3
3
|
module Action
|
4
4
|
class Create < BaseAction
|
5
5
|
def call(env)
|
6
|
-
|
6
|
+
base_name = env[:root_path].basename.to_s
|
7
|
+
base_name.gsub!(/[^-a-z0-9_]/i, "")
|
8
|
+
|
9
|
+
target_rootfs_path = env[:machine].provider_config.target_rootfs_path
|
10
|
+
|
11
|
+
machine_id = env[:machine].provider.container.create(base_name, target_rootfs_path, env[:machine].box.metadata)
|
7
12
|
env[:machine].id = machine_id
|
8
13
|
env[:just_created] = true
|
9
14
|
@app.call env
|
data/lib/vagrant-lxc/config.rb
CHANGED
@@ -6,8 +6,15 @@ module Vagrant
|
|
6
6
|
# @return [Array]
|
7
7
|
attr_reader :start_opts
|
8
8
|
|
9
|
+
# Base directory to store container's rootfs
|
10
|
+
#
|
11
|
+
# Defaults to nil, which means it will be stored wherever the lxc template
|
12
|
+
# tells it to be stored
|
13
|
+
attr_accessor :target_rootfs_path
|
14
|
+
|
9
15
|
def initialize
|
10
|
-
@start_opts
|
16
|
+
@start_opts = []
|
17
|
+
@target_rootfs_path = nil
|
11
18
|
end
|
12
19
|
end
|
13
20
|
end
|
@@ -31,15 +31,18 @@ module Vagrant
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
-
def create(template, template_opts = {})
|
34
|
+
def create(template, target_rootfs_path, template_opts = {})
|
35
35
|
extra = template_opts.to_a.flatten
|
36
36
|
extra.unshift '--' unless extra.empty?
|
37
37
|
|
38
|
+
rootfs_args = target_rootfs_path ?
|
39
|
+
['-B', 'dir', '--dir', target_rootfs_path] :
|
40
|
+
[]
|
41
|
+
|
38
42
|
run :create,
|
39
|
-
# lxc-create options
|
40
43
|
'--template', template,
|
41
44
|
'--name', @name,
|
42
|
-
*extra
|
45
|
+
*(rootfs_args + extra)
|
43
46
|
end
|
44
47
|
|
45
48
|
def destroy
|
@@ -12,9 +12,6 @@ module Vagrant
|
|
12
12
|
# Root folder where containers are stored
|
13
13
|
CONTAINERS_PATH = '/var/lib/lxc'
|
14
14
|
|
15
|
-
# Default LXC configs
|
16
|
-
LXC_DEFAULTS_PATH = '/etc/default/lxc'
|
17
|
-
|
18
15
|
# Include this so we can use `Subprocess` more easily.
|
19
16
|
include Vagrant::Util::Retryable
|
20
17
|
|
@@ -39,13 +36,13 @@ module Vagrant
|
|
39
36
|
end
|
40
37
|
|
41
38
|
def rootfs_path
|
42
|
-
Pathname.new(
|
39
|
+
Pathname.new(base_path.join('config').read.match(/^lxc\.rootfs\s+=\s+(.+)$/)[1])
|
43
40
|
end
|
44
41
|
|
45
|
-
def create(metadata = {})
|
42
|
+
def create(base_name, target_rootfs_path, metadata = {})
|
46
43
|
@logger.debug('Creating container using lxc-create...')
|
47
44
|
|
48
|
-
@name = SecureRandom.hex(6)
|
45
|
+
@name = "#{base_name}-#{SecureRandom.hex(6)}"
|
49
46
|
public_key = Vagrant.source_root.join('keys', 'vagrant.pub').expand_path.to_s
|
50
47
|
meta_opts = metadata.fetch('template-opts', {}).merge(
|
51
48
|
'--auth-key' => public_key,
|
@@ -53,7 +50,7 @@ module Vagrant
|
|
53
50
|
)
|
54
51
|
|
55
52
|
@cli.name = @name
|
56
|
-
@cli.create(metadata.fetch('template-name'), meta_opts)
|
53
|
+
@cli.create(metadata.fetch('template-name'), target_rootfs_path, meta_opts)
|
57
54
|
|
58
55
|
@name
|
59
56
|
end
|
@@ -107,7 +104,7 @@ module Vagrant
|
|
107
104
|
retryable(:on => LXC::Errors::ExecuteError, :tries => 10, :sleep => 3) do
|
108
105
|
unless ip = get_container_ip_from_ifconfig
|
109
106
|
# retry
|
110
|
-
raise LXC::Errors::ExecuteError, :command =>
|
107
|
+
raise LXC::Errors::ExecuteError, :command => "lxc-attach"
|
111
108
|
end
|
112
109
|
end
|
113
110
|
ip
|
data/lib/vagrant-lxc/provider.rb
CHANGED
@@ -34,7 +34,7 @@ module Vagrant
|
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
-
# @see Vagrant::Plugin::
|
37
|
+
# @see Vagrant::Plugin::V2::Provider#action
|
38
38
|
def action(name)
|
39
39
|
# Attempt to get the action method from the Action class if it
|
40
40
|
# exists, otherwise return nil to show that we don't support the
|
@@ -53,7 +53,7 @@ module Vagrant
|
|
53
53
|
|
54
54
|
{
|
55
55
|
:host => @container.assigned_ip,
|
56
|
-
:port =>
|
56
|
+
:port => @machine.config.ssh.guest_port
|
57
57
|
}
|
58
58
|
end
|
59
59
|
|
data/lib/vagrant-lxc/version.rb
CHANGED
@@ -33,19 +33,31 @@ describe Vagrant::LXC::Container::CLI do
|
|
33
33
|
subject { described_class.new(name) }
|
34
34
|
|
35
35
|
before do
|
36
|
-
subject.stub(:run)
|
37
|
-
subject.create(template, template_args)
|
36
|
+
subject.stub(:run) { |*args| @run_args = args }
|
37
|
+
subject.create(template, rootfs, template_args)
|
38
38
|
end
|
39
39
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
40
|
+
context 'when no rootfs is passed' do
|
41
|
+
let(:rootfs) { nil }
|
42
|
+
|
43
|
+
it 'issues a lxc-create with provided template, container name and hash of arguments' do
|
44
|
+
subject.should have_received(:run).with(
|
45
|
+
:create,
|
46
|
+
'--template', template,
|
47
|
+
'--name', name,
|
48
|
+
'--',
|
49
|
+
'--extra-param', 'param',
|
50
|
+
'--other', 'value'
|
51
|
+
)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context 'when the rootfs is passed' do
|
56
|
+
let(:rootfs) { 'rootfs_path' }
|
57
|
+
|
58
|
+
it 'issues a lxc-create with the right rootfs arguments' do
|
59
|
+
@run_args.join(' ').should =~ /-B dir --dir #{rootfs}/
|
60
|
+
end
|
49
61
|
end
|
50
62
|
end
|
51
63
|
|
data/spec/unit/container_spec.rb
CHANGED
@@ -33,22 +33,26 @@ describe Vagrant::LXC::Container do
|
|
33
33
|
end
|
34
34
|
|
35
35
|
describe 'creation' do
|
36
|
-
let(:
|
36
|
+
let(:base_name) { 'container-name' }
|
37
|
+
let(:suffix) { 'random-suffix' }
|
37
38
|
let(:template_name) { 'template-name' }
|
38
39
|
let(:rootfs_cache) { '/path/to/cache' }
|
40
|
+
let(:target_rootfs) { '/path/to/rootfs' }
|
39
41
|
let(:public_key_path) { Vagrant.source_root.join('keys', 'vagrant.pub').expand_path.to_s }
|
40
42
|
let(:cli) { fire_double('Vagrant::LXC::Container::CLI', :create => true, :name= => true) }
|
41
43
|
|
42
44
|
subject { described_class.new(name, cli) }
|
43
45
|
|
44
46
|
before do
|
45
|
-
SecureRandom.stub(hex:
|
46
|
-
subject.create 'template-name' => template_name, 'rootfs-cache-path' => rootfs_cache, 'template-opts' => { '--foo' => 'bar'}
|
47
|
+
SecureRandom.stub(hex: suffix)
|
48
|
+
subject.create base_name, target_rootfs, 'template-name' => template_name, 'rootfs-cache-path' => rootfs_cache, 'template-opts' => { '--foo' => 'bar'}
|
47
49
|
end
|
48
50
|
|
49
51
|
it 'creates container with the right arguments' do
|
52
|
+
cli.should have_received(:name=).with("#{base_name}-#{suffix}")
|
50
53
|
cli.should have_received(:create).with(
|
51
54
|
template_name,
|
55
|
+
target_rootfs,
|
52
56
|
'--auth-key' => public_key_path,
|
53
57
|
'--cache' => rootfs_cache,
|
54
58
|
'--foo' => 'bar'
|
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.1.
|
4
|
+
version: 0.1.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-03-
|
11
|
+
date: 2013-03-29 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Linux Containers provider for Vagrant
|
14
14
|
email:
|
@@ -31,8 +31,7 @@ files:
|
|
31
31
|
- boxes/quantal64/download-ubuntu
|
32
32
|
- boxes/quantal64/lxc-template
|
33
33
|
- boxes/quantal64/metadata.json
|
34
|
-
- development/Vagrantfile
|
35
|
-
- development/Vagrantfile.1.1
|
34
|
+
- development/Vagrantfile
|
36
35
|
- development/lxc-configs/lxc-dev-box
|
37
36
|
- development/lxc-configs/vbox
|
38
37
|
- development/shell-provisioning/upgrade-kernel
|
data/development/Vagrantfile.1.0
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
# -*- mode: ruby -*-
|
2
|
-
# vi: set ft=ruby :
|
3
|
-
|
4
|
-
def local_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::Config.run do |config|
|
15
|
-
config.vm.box = "quantal64"
|
16
|
-
config.vm.box_url = "https://github.com/downloads/roderik/VagrantQuantal64Box/quantal64.box"
|
17
|
-
config.vm.host_name = 'lxc-dev-box'
|
18
|
-
|
19
|
-
cache_dir = local_cache(config.vm.box)
|
20
|
-
config.vm.share_folder "v-root", "/vagrant", "../"
|
21
|
-
config.vm.share_folder "v-cache", "/var/cache/apt/archives", cache_dir
|
22
|
-
|
23
|
-
if defined? VagrantVbguest::Config
|
24
|
-
config.vbguest.auto_update = false
|
25
|
-
config.vbguest.no_remote = true
|
26
|
-
end
|
27
|
-
|
28
|
-
config.vm.provision :shell, :path => 'shell-provisioning/upgrade-kernel'
|
29
|
-
|
30
|
-
config.vm.provision :puppet do |puppet|
|
31
|
-
puppet.manifests_path = "."
|
32
|
-
puppet.manifest_file = "site.pp"
|
33
|
-
# Pass DEBUG=1 to vagrant commands if you want to make some debugging noise
|
34
|
-
puppet.options << [ "--verbose", "--debug" ] if ENV["DEBUG"] == '1'
|
35
|
-
end
|
36
|
-
end
|