Skip to content
This repository has been archived by the owner on Nov 24, 2022. It is now read-only.

NixOS compatibility #376

Merged
merged 5 commits into from
Aug 25, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
source 'https://rubygems.org'

group :development do
gem 'vagrant', git: 'https://github.com/mitchellh/vagrant.git', tag: 'v1.7.2'
gem 'vagrant', git: 'https://github.com/mitchellh/vagrant.git', tag: 'v1.7.4'
gem 'guard'
gem 'guard-rspec'
gem 'rb-inotify'
Expand Down
131 changes: 58 additions & 73 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
GIT
remote: https://github.com/fgrehm/vagrant-cachier.git
revision: 9f6b615e84364b851939a8e7ee8229fc0d276c73
revision: 40dddfb368526948e769492a00a7937c5a044a4d
specs:
vagrant-cachier (1.1.0)
vagrant-cachier (1.2.1)

GIT
remote: https://github.com/fgrehm/vagrant-pristine.git
revision: 503dbc47848c81d0fbfa6840491856f518d244a1
revision: 6d044265db17451c606f000bf43437e95a742bb4
specs:
vagrant-pristine (0.3.0)

Expand All @@ -22,16 +22,16 @@ GIT

GIT
remote: https://github.com/mitchellh/vagrant.git
revision: 1cd667b243f4a263cd5322b6455165cc676b6f7f
tag: v1.7.2
revision: 78ea5e4a78ce644717ab16d8001ab77430168f0f
tag: v1.7.4
specs:
vagrant (1.7.2)
bundler (>= 1.5.2, < 1.8.0)
vagrant (1.7.4)
bundler (>= 1.5.2, <= 1.10.5)
childprocess (~> 0.5.0)
erubis (~> 2.7.0)
hashicorp-checkpoint (~> 0.1.1)
i18n (~> 0.6.0)
listen (~> 2.8.0)
i18n (>= 0.6.0, <= 0.8.0)
listen (~> 3.0.2)
log4r (~> 1.1.9, < 1.1.11)
net-scp (~> 1.1.0)
net-sftp (~> 2.1)
Expand All @@ -40,7 +40,8 @@ GIT
rb-kqueue (~> 0.2.0)
rest-client (>= 1.6.0, < 2.0)
wdm (~> 0.1.0)
winrm (~> 1.1.3)
winrm (~> 1.3)
winrm-fs (~> 0.2.0)

PATH
remote: .
Expand All @@ -50,52 +51,44 @@ PATH
GEM
remote: https://rubygems.org/
specs:
akami (1.2.2)
gyoku (>= 0.4.0)
nokogiri
builder (3.2.2)
celluloid (0.16.0)
timers (~> 4.0.0)
childprocess (0.5.5)
childprocess (0.5.6)
ffi (~> 1.0, >= 1.0.11)
coderay (1.1.0)
coveralls (0.7.1)
coveralls (0.7.2)
multi_json (~> 1.3)
rest-client
rest-client (= 1.6.7)
simplecov (>= 0.7)
term-ansicolor
thor
term-ansicolor (= 1.2.2)
thor (= 0.18.1)
diff-lcs (1.2.5)
docile (1.1.5)
erubis (2.7.0)
ffi (1.9.6)
ffi (1.9.10)
formatador (0.2.5)
gssapi (1.0.3)
gssapi (1.2.0)
ffi (>= 1.0.1)
guard (2.11.1)
guard (2.12.8)
formatador (>= 0.2.4)
listen (~> 2.7)
listen (>= 2.7, <= 4.0)
lumberjack (~> 1.0)
nenv (~> 0.1)
notiffany (~> 0.0)
pry (>= 0.9.12)
shellany (~> 0.0)
thor (>= 0.18.1)
guard-compat (1.2.0)
guard-rspec (4.5.0)
guard-compat (1.2.1)
guard-rspec (4.6.2)
guard (~> 2.1)
guard-compat (~> 1.1)
rspec (>= 2.99.0, < 4.0)
gyoku (1.2.2)
gyoku (1.3.1)
builder (>= 2.1.2)
hashicorp-checkpoint (0.1.4)
hitimes (1.2.2)
httpclient (2.6.0.1)
httpi (0.9.7)
rack
i18n (0.6.11)
listen (2.8.5)
celluloid (>= 0.15.2)
i18n (0.7.0)
json (1.8.3)
listen (3.0.2)
rb-fsevent (>= 0.9.3)
rb-inotify (>= 0.9)
little-plugger (1.1.3)
Expand All @@ -105,79 +98,71 @@ GEM
multi_json (>= 1.8.4)
lumberjack (1.0.9)
method_source (0.8.2)
mime-types (2.4.3)
mime-types (2.6.1)
mini_portile (0.6.0)
multi_json (1.10.1)
nenv (0.1.1)
multi_json (1.11.2)
nenv (0.2.0)
net-scp (1.1.2)
net-ssh (>= 2.6.5)
net-sftp (2.1.2)
net-ssh (>= 2.6.5)
net-ssh (2.9.1)
netrc (0.10.2)
net-ssh (2.9.2)
nokogiri (1.6.3.1)
mini_portile (= 0.6.0)
nori (1.1.5)
notiffany (0.0.2)
nori (2.6.0)
notiffany (0.0.6)
nenv (~> 0.1)
shellany (~> 0.0)
pry (0.10.1)
coderay (~> 1.1.0)
method_source (~> 0.8.1)
slop (~> 3.4)
rack (1.6.0)
rake (10.4.2)
rb-fsevent (0.9.4)
rb-fsevent (0.9.5)
rb-inotify (0.9.5)
ffi (>= 0.5.0)
rb-kqueue (0.2.3)
rb-kqueue (0.2.4)
ffi (>= 0.5.0)
rest-client (1.7.2)
mime-types (>= 1.16, < 3.0)
netrc (~> 0.7)
rest-client (1.6.7)
mime-types (>= 1.16)
rspec (2.99.0)
rspec-core (~> 2.99.0)
rspec-expectations (~> 2.99.0)
rspec-mocks (~> 2.99.0)
rspec-core (2.99.2)
rspec-expectations (2.99.2)
diff-lcs (>= 1.1.3, < 2.0)
rspec-mocks (2.99.2)
rubyntlm (0.1.1)
savon (0.9.5)
akami (~> 1.0)
builder (>= 2.1.2)
gyoku (>= 0.4.0)
httpi (~> 0.9)
nokogiri (>= 1.4.0)
nori (~> 1.0)
wasabi (~> 1.0)
rspec-mocks (2.99.4)
rubyntlm (0.4.0)
rubyzip (1.1.7)
shellany (0.0.1)
simplecov (0.9.1)
simplecov (0.10.0)
docile (~> 1.1.0)
multi_json (~> 1.0)
simplecov-html (~> 0.8.0)
simplecov-html (0.8.0)
json (~> 1.8)
simplecov-html (~> 0.10.0)
simplecov-html (0.10.0)
slop (3.6.0)
term-ansicolor (1.3.0)
tins (~> 1.0)
term-ansicolor (1.2.2)
tins (~> 0.8)
thor (0.18.1)
timers (4.0.1)
hitimes
tins (1.3.3)
tins (0.13.2)
uuidtools (2.1.5)
vagrant-omnibus (1.4.1)
wasabi (1.0.0)
nokogiri (>= 1.4.0)
wdm (0.1.0)
winrm (1.1.3)
gssapi (~> 1.0.0)
wdm (0.1.1)
winrm (1.3.3)
builder (>= 2.1.2)
gssapi (~> 1.2)
gyoku (~> 1.0)
httpclient (~> 2.2, >= 2.2.0.2)
logging (~> 1.6, >= 1.6.1)
nokogiri (~> 1.5)
rubyntlm (~> 0.1.1)
savon (= 0.9.5)
nori (~> 2.0)
rubyntlm (~> 0.4.0)
uuidtools (~> 2.1.2)
winrm-fs (0.2.0)
erubis (~> 2.7)
logging (~> 1.6, >= 1.6.1)
rubyzip (~> 1.1)
winrm (~> 1.3.0)

PLATFORMS
ruby
Expand Down
41 changes: 3 additions & 38 deletions lib/vagrant-lxc/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,8 @@ def config_string
def create(name, backingstore, backingstore_options, template_path, config_file, template_options = {})
@cli.name = @container_name = name

import_template(template_path) do |template_name|
@logger.debug "Creating container..."
@cli.create template_name, backingstore, backingstore_options, config_file, template_options
end
@logger.debug "Creating container..."
@cli.create template_path, backingstore, backingstore_options, config_file, template_options
end

def share_folders(folders)
Expand All @@ -92,7 +90,7 @@ def share_folders(folders)
end

def share_folder(host_path, guest_path, mount_options = nil)
guest_path = guest_path.gsub(/^\//, '').gsub(' ', '\\\040')
guest_path = guest_path.gsub(/^\//, '').gsub(' ', '\\\040')
mount_options = Array(mount_options || ['bind', 'create=dir'])
host_path = host_path.to_s.gsub(' ', '\\\040')
@customizations << ['mount.entry', "#{host_path} #{guest_path} none #{mount_options.join(',')} 0 0"]
Expand Down Expand Up @@ -239,39 +237,6 @@ def write_config(contents)
@sudo_wrapper.run 'chown', 'root:root', base_path.join('config').to_s
end
end

def import_template(path)
template_name = "vagrant-tmp-#{@container_name}"
tmp_template_path = templates_path.join("lxc-#{template_name}").to_s

@logger.info 'Copying LXC template into place'
@sudo_wrapper.run('cp', path, tmp_template_path)
@sudo_wrapper.run('chmod', '+x', tmp_template_path)

yield template_name
ensure
@logger.info 'Removing LXC template'
if tmp_template_path
@sudo_wrapper.run('rm', tmp_template_path)
end
end

TEMPLATES_PATH_LOOKUP = %w(
/usr/share/lxc/templates
/usr/lib/lxc/templates
/usr/lib64/lxc/templates
/usr/local/lib/lxc/templates
)
def templates_path
return @templates_path if @templates_path

path = TEMPLATES_PATH_LOOKUP.find { |candidate| File.directory?(candidate) }
if !path
raise Errors::TemplatesDirMissing.new paths: TEMPLATES_PATH_LOOKUP.inspect
end

@templates_path = Pathname(path)
end
end
end
end
2 changes: 1 addition & 1 deletion lib/vagrant-lxc/provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def sudo_wrapper

def ensure_lxc_installed!
begin
sudo_wrapper.run("/usr/bin/which", "lxc-create")
sudo_wrapper.run("which", "lxc-create")
rescue Vagrant::LXC::Errors::ExecuteError
raise Errors::LxcNotInstalled
end
Expand Down
2 changes: 1 addition & 1 deletion lib/vagrant-lxc/sudo_wrapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def initialize(wrapper_path = nil)
def run(*command)
options = command.last.is_a?(Hash) ? command.last : {}
command.unshift @wrapper_path if @wrapper_path && !options[:no_wrapper]
execute *(['sudo'] + command)
execute *(['sudo', '/usr/bin/env'] + command)
end

private
Expand Down
2 changes: 1 addition & 1 deletion scripts/lxc-template
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash

# This is a modified version of /usr/share/lxc/templates/lxc-download
# that comes with ubuntu-lxc 1.0.0 stable from ppa changed to suit vagrant-lxc needs
Expand Down
4 changes: 2 additions & 2 deletions spec/unit/driver_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@

it 'creates container with the right arguments' do
expect(cli).to have_received(:create).with(
template_name,
template_path,
backingstore,
backingstore_opts,
config_file,
Expand Down Expand Up @@ -97,7 +97,7 @@
before do
sudo.should_receive(:run).with('cat', '/var/lib/lxc/name/config').exactly(2).times.
and_return('# CONFIGURATION')
sudo.should_receive(:run).twice.with('cp', '-f', %r{/tmp/.*}, '/var/lib/lxc/name/config')
sudo.should_receive(:run).twice.with('cp', '-f', %r{/(run|tmp)/.*}, '/var/lib/lxc/name/config')
sudo.should_receive(:run).twice.with('chown', 'root:root', '/var/lib/lxc/name/config')

subject.customizations << internal_customization
Expand Down
6 changes: 0 additions & 6 deletions templates/sudoers.rb.erb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ end

base = "/var/lib/lxc"
base_path = %r{\A#{base}/.*\z}
templates_path = %r{\A/usr/(share|lib|lib64|local/lib)/lxc/templates/.*\z}

##
# Commands from provider.rb
Expand All @@ -96,11 +95,6 @@ Whitelist.add '<%= cmd_paths['mkdir'] %>', '-p', base_path
# - Container config customizations and pruning
Whitelist.add '<%= cmd_paths['cp'] %>', '-f', %r{/tmp/.*}, base_path
Whitelist.add '<%= cmd_paths['chown'] %>', 'root:root', base_path
# - Template import
Whitelist.add '<%= cmd_paths['cp'] %>', %r{\A.*\z}, templates_path
Whitelist.add '<%= cmd_paths['chmod'] %>', '+x', templates_path
# - Template removal
Whitelist.add '<%= cmd_paths['rm'] %>', templates_path
# - Packaging
Whitelist.add '<%= cmd_paths['tar'] %>', '--numeric-owner', '-cvzf', %r{/tmp/.*/rootfs.tar.gz}, '-C', base_path, './rootfs'
Whitelist.add '<%= cmd_paths['chown'] %>', /\A\d+:\d+\z/, %r{\A/tmp/.*/rootfs\.tar\.gz\z}
Expand Down