vagrant-lxc 0.3.3 → 0.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +14 -0
- data/Gemfile +3 -6
- data/Gemfile.lock +25 -25
- data/README.md +44 -32
- data/boxes/common/cleanup +7 -0
- data/boxes/common/install-babushka +15 -0
- data/boxes/{ubuntu → common}/install-chef +0 -0
- data/boxes/{ubuntu → common}/install-puppet +1 -1
- data/boxes/debian/download +156 -0
- data/boxes/debian/lxc-template +363 -0
- data/boxes/debian/metadata.json.template +9 -0
- data/boxes/ubuntu/download +11 -0
- data/boxes/ubuntu/lxc-template +14 -23
- data/development/Vagrantfile +69 -95
- data/development/lxc-configs/sid +37 -0
- data/development/lxc-configs/squeeze +37 -0
- data/development/lxc-configs/wheezy +37 -0
- data/development/shell-provisioning/upgrade-kernel +2 -2
- data/development/site.pp +3 -0
- data/example/Vagrantfile +15 -1
- data/lib/vagrant-lxc/action.rb +3 -1
- data/lib/vagrant-lxc/action/forced_halt.rb +1 -3
- data/lib/vagrant-lxc/action/remove_temporary_files.rb +23 -0
- data/lib/vagrant-lxc/driver.rb +3 -3
- data/lib/vagrant-lxc/driver/cli.rb +20 -2
- data/lib/vagrant-lxc/version.rb +1 -1
- data/spec/Vagrantfile +10 -19
- data/spec/acceptance/sanity_check_spec.rb +11 -2
- data/spec/acceptance/support/test_ui.rb +1 -1
- data/spec/unit/driver/cli_spec.rb +5 -6
- data/spec/unit/driver_spec.rb +10 -2
- data/tasks/boxes.rake +136 -36
- metadata +13 -4
data/lib/vagrant-lxc/version.rb
CHANGED
data/spec/Vagrantfile
CHANGED
@@ -1,33 +1,24 @@
|
|
1
1
|
# -*- mode: ruby -*-
|
2
2
|
# vi: set ft=ruby :
|
3
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
4
|
Vagrant.require_plugin 'vagrant-lxc'
|
5
|
+
Vagrant.require_plugin 'vagrant-cachier'
|
15
6
|
|
16
|
-
|
17
|
-
config.vm.box = "quantal64"
|
18
|
-
config.vm.hostname = 'lxc-test-box'
|
7
|
+
ENV['BOX_NAME'] ||= 'quantal64'
|
19
8
|
|
20
|
-
|
21
|
-
|
22
|
-
#
|
9
|
+
Vagrant.configure("2") do |config|
|
10
|
+
config.vm.box = ENV['BOX_NAME']
|
11
|
+
# FIXME: Find out why this does not work for debian boxes
|
12
|
+
unless %w( squeeze64 wheezy64 sid64 ).include? config.vm.box
|
13
|
+
config.vm.hostname = 'lxc-test-box'
|
14
|
+
end
|
23
15
|
|
24
|
-
|
25
|
-
config.vm.synced_folder cache_dir, "/var/cache/apt/archives", id: "vagrant-apt-cache"
|
16
|
+
config.cache.enable :apt
|
26
17
|
|
27
18
|
config.vm.provision :shell,
|
28
19
|
inline: 'mkdir -p /vagrant/tmp && echo -n "Provisioned" > /vagrant/tmp/provisioning'
|
29
20
|
|
30
21
|
config.vm.network :forwarded_port, guest: 80, host: 8080
|
31
22
|
config.vm.provision :shell,
|
32
|
-
inline: 'sudo apt-get install
|
23
|
+
inline: 'sudo apt-get install apache2 -y'
|
33
24
|
end
|
@@ -20,7 +20,10 @@ describe 'Sanity check' do
|
|
20
20
|
end
|
21
21
|
|
22
22
|
it "is able to be SSH'ed" do
|
23
|
-
|
23
|
+
expected = 'lxc-test-box'
|
24
|
+
# HACK:
|
25
|
+
expected = ENV['BOX_NAME'].gsub(/64$/, '') if %w( squeeze64 wheezy64 sid64 ).include? ENV['BOX_NAME']
|
26
|
+
expect(vagrant_ssh('hostname')).to eq expected
|
24
27
|
end
|
25
28
|
|
26
29
|
it 'mounts shared folders with the right permissions' do
|
@@ -36,7 +39,7 @@ describe 'Sanity check' do
|
|
36
39
|
|
37
40
|
it 'forwards configured ports' do
|
38
41
|
output = `curl -s localhost:8080`.strip.chomp
|
39
|
-
expect(output).to include '
|
42
|
+
expect(output).to include 'It works!'
|
40
43
|
end
|
41
44
|
end
|
42
45
|
|
@@ -44,6 +47,7 @@ describe 'Sanity check' do
|
|
44
47
|
before(:all) do
|
45
48
|
destroy_container
|
46
49
|
vagrant_up
|
50
|
+
vagrant_ssh 'touch /tmp/{some,files}'
|
47
51
|
vagrant_halt
|
48
52
|
end
|
49
53
|
|
@@ -61,6 +65,11 @@ describe 'Sanity check' do
|
|
61
65
|
processes = `pgrep redir`
|
62
66
|
expect($?.exitstatus).to_not eq 0
|
63
67
|
end
|
68
|
+
|
69
|
+
it 'removes files under `/tmp`' do
|
70
|
+
container_tmp = Pathname("/var/lib/lxc/#{vagrant_container_name}/rootfs/tmp")
|
71
|
+
expect(container_tmp.entries).to have(2).items # basically '.' and '..'
|
72
|
+
end
|
64
73
|
end
|
65
74
|
|
66
75
|
context '`vagrant destroy`' do
|
@@ -157,9 +157,11 @@ describe Vagrant::LXC::Driver::CLI do
|
|
157
157
|
let(:name) { 'a-running-container' }
|
158
158
|
subject { described_class.new(name) }
|
159
159
|
|
160
|
-
before
|
160
|
+
before do
|
161
|
+
subject.stub(run: true, sleep: true, state: :stopped)
|
162
|
+
end
|
161
163
|
|
162
|
-
it 'yields cli object' do
|
164
|
+
it 'yields a cli object' do
|
163
165
|
subject.stub(:shutdown)
|
164
166
|
subject.transition_to(:stopped) { |c| c.shutdown }
|
165
167
|
subject.should have_received(:shutdown)
|
@@ -171,9 +173,6 @@ describe Vagrant::LXC::Driver::CLI do
|
|
171
173
|
}.to raise_error(described_class::TransitionBlockNotProvided)
|
172
174
|
end
|
173
175
|
|
174
|
-
|
175
|
-
subject.transition_to(:running) { }
|
176
|
-
subject.should have_received(:run).with(:wait, '--name', name, '--state', 'RUNNING')
|
177
|
-
end
|
176
|
+
pending 'waits for the expected container state'
|
178
177
|
end
|
179
178
|
end
|
data/spec/unit/driver_spec.rb
CHANGED
@@ -2,6 +2,7 @@ require 'unit_helper'
|
|
2
2
|
|
3
3
|
require 'vagrant'
|
4
4
|
require 'vagrant-lxc/driver'
|
5
|
+
require 'vagrant-lxc/driver/cli'
|
5
6
|
|
6
7
|
describe Vagrant::LXC::Driver do
|
7
8
|
describe 'container name validation' do
|
@@ -101,12 +102,19 @@ describe Vagrant::LXC::Driver do
|
|
101
102
|
|
102
103
|
it 'delegates to cli shutdown' do
|
103
104
|
cli.should_receive(:shutdown)
|
104
|
-
subject.
|
105
|
+
subject.forced_halt
|
105
106
|
end
|
106
107
|
|
107
108
|
it 'expects a transition to running state to take place' do
|
108
109
|
cli.should_receive(:transition_to).with(:stopped)
|
109
|
-
subject.
|
110
|
+
subject.forced_halt
|
111
|
+
end
|
112
|
+
|
113
|
+
it 'attempts to force the container to stop in case a shutdown doesnt work' do
|
114
|
+
cli.stub(:shutdown).and_raise(Vagrant::LXC::Driver::CLI::TargetStateNotReached.new :target, :source)
|
115
|
+
cli.should_receive(:transition_to).with(:stopped).twice
|
116
|
+
cli.should_receive(:stop)
|
117
|
+
subject.forced_halt
|
110
118
|
end
|
111
119
|
end
|
112
120
|
|
data/tasks/boxes.rake
CHANGED
@@ -1,79 +1,179 @@
|
|
1
|
+
require 'pathname'
|
1
2
|
require 'rake/tasklib'
|
2
3
|
|
3
|
-
class
|
4
|
+
class BuildGenericBoxTask < ::Rake::TaskLib
|
4
5
|
include ::Rake::DSL
|
5
6
|
|
6
7
|
attr_reader :name
|
7
8
|
|
8
|
-
def initialize(name, release, arch, opts = {})
|
9
|
-
@name
|
10
|
-
@
|
11
|
-
@
|
12
|
-
@
|
13
|
-
@
|
14
|
-
@
|
15
|
-
|
16
|
-
|
9
|
+
def initialize(name, distrib, release, arch, opts = {})
|
10
|
+
@name = name
|
11
|
+
@distrib = distrib
|
12
|
+
@release = release.to_s
|
13
|
+
@arch = arch.to_s
|
14
|
+
@install_chef = opts.fetch(:chef, true)
|
15
|
+
@install_puppet = opts.fetch(:puppet, true)
|
16
|
+
@install_babushka = opts.fetch(:babushka, true)
|
17
|
+
@file = opts[:file] || default_box_file
|
18
|
+
@scripts_path = Pathname(Dir.pwd).join('boxes')
|
19
|
+
|
20
|
+
desc "Build an #{distrib.upcase} #{release} #{arch} box" unless
|
21
|
+
::Rake.application.last_comment
|
17
22
|
task name do
|
18
23
|
RakeFileUtils.send(:verbose, true) do
|
19
|
-
|
24
|
+
build
|
20
25
|
end
|
21
26
|
end
|
22
27
|
end
|
23
28
|
|
24
|
-
def
|
25
|
-
|
26
|
-
|
27
|
-
|
29
|
+
def default_box_file
|
30
|
+
require 'time'
|
31
|
+
"lxc-#{@release}-#{@arch}-#{Date.today}.box"
|
32
|
+
end
|
33
|
+
|
34
|
+
def run(script_name, *args)
|
35
|
+
unless (script = @scripts_path.join(@distrib, script_name)).readable?
|
36
|
+
script = @scripts_path.join('common', script_name)
|
28
37
|
end
|
29
38
|
|
30
|
-
if
|
31
|
-
|
39
|
+
if script.readable?
|
40
|
+
sh "sudo #{script} #{args.join(' ')}"
|
41
|
+
else
|
42
|
+
STDERR.puts "cannot execute #{install_path} (not found?)"
|
32
43
|
exit 1
|
33
44
|
end
|
45
|
+
end
|
34
46
|
|
47
|
+
def build
|
48
|
+
check_if_box_has_been_built!
|
49
|
+
|
50
|
+
FileUtils.mkdir_p 'boxes/temp' unless File.exist? 'base/temp'
|
51
|
+
check_for_partially_built_box!
|
52
|
+
|
53
|
+
pwd = Dir.pwd
|
35
54
|
sh 'mkdir -p boxes/temp/'
|
36
55
|
Dir.chdir 'boxes/temp' do
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
sh 'sudo rm -f rootfs.tar.gz'
|
41
|
-
sh 'sudo tar --numeric-owner -czf rootfs.tar.gz ./rootfs/*'
|
56
|
+
download
|
57
|
+
install_cfg_engines
|
58
|
+
prepare_package_contents pwd
|
42
59
|
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
60
|
sh "tar -czf tmp-package.box ./*"
|
50
61
|
end
|
51
62
|
|
63
|
+
sh 'mkdir -p boxes/output'
|
52
64
|
sh "cp boxes/temp/tmp-package.box boxes/output/#{@file}"
|
53
65
|
sh "rm -rf boxes/temp"
|
54
66
|
end
|
55
67
|
|
56
|
-
def
|
57
|
-
|
58
|
-
|
68
|
+
def check_if_box_has_been_built!
|
69
|
+
return unless File.exists?("./boxes/output/#{@file}")
|
70
|
+
|
71
|
+
puts 'Box has been built already!'
|
72
|
+
exit 1
|
73
|
+
end
|
74
|
+
|
75
|
+
def check_for_partially_built_box!
|
76
|
+
return unless Dir.entries('boxes/temp').size > 2
|
77
|
+
|
78
|
+
puts 'There is a partially built box under ' +
|
79
|
+
File.expand_path('./boxes/temp') +
|
80
|
+
', please remove it before building a new box'
|
81
|
+
exit 1
|
82
|
+
end
|
83
|
+
|
84
|
+
def download
|
85
|
+
run 'download', @arch, @release
|
86
|
+
end
|
87
|
+
|
88
|
+
def install_cfg_engines
|
89
|
+
[ :puppet, :chef, :babushka ].each do |cfg_engine|
|
90
|
+
next unless instance_variable_get :"@install_#{cfg_engine}"
|
91
|
+
script_name = "install-#{cfg_engine}"
|
92
|
+
run script_name
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def prepare_package_contents(pwd)
|
97
|
+
run 'cleanup'
|
98
|
+
sh 'sudo rm -f rootfs.tar.gz'
|
99
|
+
sh 'sudo tar --numeric-owner -czf rootfs.tar.gz ./rootfs/*'
|
100
|
+
sh "sudo chown #{ENV['USER']}:#{ENV['USER']} rootfs.tar.gz"
|
101
|
+
sh "cp #{pwd}/boxes/#{@distrib}/lxc-template ."
|
102
|
+
compile_metadata(pwd)
|
103
|
+
end
|
104
|
+
|
105
|
+
def compile_metadata(pwd)
|
106
|
+
metadata = File.read("#{pwd}/boxes/#{@distrib}/metadata.json.template")
|
107
|
+
metadata.gsub!('ARCH', @arch)
|
108
|
+
metadata.gsub!('RELEASE', @release)
|
109
|
+
File.open('metadata.json', 'w') { |f| f.print metadata }
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
class BuildDebianBoxTask < BuildGenericBoxTask
|
114
|
+
def initialize(name, release, arch, opts = {})
|
115
|
+
super(name, 'debian', release, arch, opts)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
class BuildUbuntuBoxTask < BuildGenericBoxTask
|
120
|
+
def initialize(name, release, arch, opts = {})
|
121
|
+
super(name, 'ubuntu', release, arch, opts)
|
59
122
|
end
|
60
123
|
end
|
61
124
|
|
125
|
+
chef = ENV['CHEF'] == '1'
|
126
|
+
puppet = ENV['PUPPET'] == '1'
|
127
|
+
babushka = ENV['BABUSHKA'] == '1'
|
128
|
+
|
62
129
|
namespace :boxes do
|
63
130
|
namespace :ubuntu do
|
64
131
|
namespace :build do
|
65
|
-
chef = ENV['CHEF'] != '0'
|
66
|
-
puppet = ENV['PUPPET'] != '0'
|
67
132
|
|
68
133
|
desc 'Build an Ubuntu Precise 64 bits box'
|
69
|
-
BuildUbuntuBoxTask.
|
134
|
+
BuildUbuntuBoxTask.
|
135
|
+
new(:precise64,
|
136
|
+
:precise, 'amd64', chef: chef, puppet: puppet, babushka: babushka)
|
70
137
|
|
71
138
|
desc 'Build an Ubuntu Quantal 64 bits box'
|
72
|
-
BuildUbuntuBoxTask.
|
139
|
+
BuildUbuntuBoxTask.
|
140
|
+
new(:quantal64,
|
141
|
+
:quantal, 'amd64', chef: chef, puppet: puppet, babushka: babushka)
|
73
142
|
|
74
143
|
# FIXME: Find out how to install chef on raring
|
75
144
|
desc 'Build an Ubuntu Raring 64 bits box'
|
76
|
-
BuildUbuntuBoxTask.
|
145
|
+
BuildUbuntuBoxTask.
|
146
|
+
new(:raring64,
|
147
|
+
:raring, 'amd64', chef: false, puppet: puppet, babushka: babushka)
|
148
|
+
|
149
|
+
desc 'Build all Ubuntu boxes'
|
150
|
+
task :all => %w( precise64 quantal64 raring64 )
|
77
151
|
end
|
78
152
|
end
|
153
|
+
|
154
|
+
# FIXME: Find out how to install chef on debian boxes
|
155
|
+
namespace :debian do
|
156
|
+
namespace :build do
|
157
|
+
desc 'Build an Debian Squeeze 64 bits box'
|
158
|
+
BuildDebianBoxTask.
|
159
|
+
new(:squeeze64,
|
160
|
+
:squeeze, 'amd64', chef: false, puppet: puppet, babushka: babushka)
|
161
|
+
|
162
|
+
desc 'Build an Debian Wheezy 64 bits box'
|
163
|
+
BuildDebianBoxTask.
|
164
|
+
new(:wheezy64,
|
165
|
+
:wheezy, 'amd64', chef: false, puppet: puppet, babushka: babushka)
|
166
|
+
|
167
|
+
desc 'Build an Debian Sid/unstable 64 bits box'
|
168
|
+
BuildDebianBoxTask.
|
169
|
+
new(:sid64,
|
170
|
+
:sid, 'amd64', chef: false, puppet: puppet, babushka: babushka)
|
171
|
+
|
172
|
+
desc 'Build all Debian boxes'
|
173
|
+
task :all => %w( squeeze64 wheezy64 sid64 )
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
desc 'Build all base boxes for release'
|
178
|
+
task :build_all => %w( ubuntu:build:all debian:build:all )
|
79
179
|
end
|
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.
|
4
|
+
version: 0.3.4
|
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-
|
11
|
+
date: 2013-05-09 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Linux Containers provider for Vagrant
|
14
14
|
email:
|
@@ -28,14 +28,22 @@ files:
|
|
28
28
|
- LICENSE.txt
|
29
29
|
- README.md
|
30
30
|
- Rakefile
|
31
|
+
- boxes/common/cleanup
|
32
|
+
- boxes/common/install-babushka
|
33
|
+
- boxes/common/install-chef
|
34
|
+
- boxes/common/install-puppet
|
35
|
+
- boxes/debian/download
|
36
|
+
- boxes/debian/lxc-template
|
37
|
+
- boxes/debian/metadata.json.template
|
31
38
|
- boxes/ubuntu/download
|
32
|
-
- boxes/ubuntu/install-chef
|
33
|
-
- boxes/ubuntu/install-puppet
|
34
39
|
- boxes/ubuntu/lxc-template
|
35
40
|
- boxes/ubuntu/metadata.json.template
|
36
41
|
- development/Vagrantfile
|
37
42
|
- development/lxc-configs/lxc-dev-box
|
43
|
+
- development/lxc-configs/sid
|
44
|
+
- development/lxc-configs/squeeze
|
38
45
|
- development/lxc-configs/vbox
|
46
|
+
- development/lxc-configs/wheezy
|
39
47
|
- development/shell-provisioning/upgrade-kernel
|
40
48
|
- development/site.pp
|
41
49
|
- example/Vagrantfile
|
@@ -59,6 +67,7 @@ files:
|
|
59
67
|
- lib/vagrant-lxc/action/handle_box_metadata.rb
|
60
68
|
- lib/vagrant-lxc/action/is_running.rb
|
61
69
|
- lib/vagrant-lxc/action/message.rb
|
70
|
+
- lib/vagrant-lxc/action/remove_temporary_files.rb
|
62
71
|
- lib/vagrant-lxc/action/setup_package_files.rb
|
63
72
|
- lib/vagrant-lxc/action/share_folders.rb
|
64
73
|
- lib/vagrant-lxc/config.rb
|