From 64240323f03ce2e34e151640c136c45d49917168 Mon Sep 17 00:00:00 2001 From: Robin Gloster Date: Thu, 14 May 2015 12:42:32 +0200 Subject: [PATCH 1/5] fix shebang in template --- scripts/lxc-template | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/lxc-template b/scripts/lxc-template index 8036bba4..50baf96a 100755 --- a/scripts/lxc-template +++ b/scripts/lxc-template @@ -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 From 2b91983cae665f7791aefc6d231470c93732c3a0 Mon Sep 17 00:00:00 2001 From: Robin Gloster Date: Thu, 14 May 2015 12:43:47 +0200 Subject: [PATCH 2/5] do not copy the lxc template instead use the full path --- lib/vagrant-lxc/driver.rb | 41 +++------------------------------------ spec/unit/driver_spec.rb | 2 +- templates/sudoers.rb.erb | 6 ------ 3 files changed, 4 insertions(+), 45 deletions(-) diff --git a/lib/vagrant-lxc/driver.rb b/lib/vagrant-lxc/driver.rb index 9fe09932..a7d960fb 100644 --- a/lib/vagrant-lxc/driver.rb +++ b/lib/vagrant-lxc/driver.rb @@ -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) @@ -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"] @@ -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 diff --git a/spec/unit/driver_spec.rb b/spec/unit/driver_spec.rb index 0aed4b5d..571c2bf9 100644 --- a/spec/unit/driver_spec.rb +++ b/spec/unit/driver_spec.rb @@ -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, diff --git a/templates/sudoers.rb.erb b/templates/sudoers.rb.erb index e9e6fd5e..fd4d40ca 100644 --- a/templates/sudoers.rb.erb +++ b/templates/sudoers.rb.erb @@ -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 @@ -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} From 5cd32c76dfedf8d095b80efeaa0c6108b46b98dc Mon Sep 17 00:00:00 2001 From: Robin Gloster Date: Sat, 18 Jul 2015 23:20:21 +0000 Subject: [PATCH 3/5] Update gems to resolve dependencies on NixOS --- Gemfile | 2 +- Gemfile.lock | 131 +++++++++++++++++++++++---------------------------- 2 files changed, 59 insertions(+), 74 deletions(-) diff --git a/Gemfile b/Gemfile index b0d8fc3e..92fea226 100644 --- a/Gemfile +++ b/Gemfile @@ -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' diff --git a/Gemfile.lock b/Gemfile.lock index 9b8e1474..68d2007e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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) @@ -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) @@ -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: . @@ -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) @@ -105,36 +98,33 @@ 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) @@ -142,42 +132,37 @@ GEM 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 From 9c67e13fb8ea9eb181d253cf3066fedb54ac9794 Mon Sep 17 00:00:00 2001 From: Robin Gloster Date: Sat, 18 Jul 2015 23:21:31 +0000 Subject: [PATCH 4/5] Fix test on NixOS Tempfile can be created in /run, too. --- spec/unit/driver_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/unit/driver_spec.rb b/spec/unit/driver_spec.rb index 571c2bf9..9851acd2 100644 --- a/spec/unit/driver_spec.rb +++ b/spec/unit/driver_spec.rb @@ -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 From 4b78c04a4784ddf0522413bfc675ad236689da1b Mon Sep 17 00:00:00 2001 From: Robin Gloster Date: Sun, 2 Aug 2015 10:13:40 +0000 Subject: [PATCH 5/5] Use /usr/bin/env CMD instead of hardcoded paths This fixes commands that currently rely on hardcoded paths and break on systems like NixOS that don't have all binaries in /usr/bin etc. --- lib/vagrant-lxc/provider.rb | 2 +- lib/vagrant-lxc/sudo_wrapper.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/vagrant-lxc/provider.rb b/lib/vagrant-lxc/provider.rb index ab562796..dead6abb 100644 --- a/lib/vagrant-lxc/provider.rb +++ b/lib/vagrant-lxc/provider.rb @@ -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 diff --git a/lib/vagrant-lxc/sudo_wrapper.rb b/lib/vagrant-lxc/sudo_wrapper.rb index 406c0f05..f344d9f0 100644 --- a/lib/vagrant-lxc/sudo_wrapper.rb +++ b/lib/vagrant-lxc/sudo_wrapper.rb @@ -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