Compare commits
18 commits
Author | SHA1 | Date | |
---|---|---|---|
a47660a1e5 | |||
3575d65ffb | |||
|
938a29ed96 | ||
|
ff58ecd5f2 | ||
|
df6b78c4ed | ||
|
4d53acb9fb | ||
|
b88d50fb68 | ||
4e3306ed74 | |||
|
c167ac7f83 | ||
|
a112b072aa | ||
|
f750bf406c | ||
|
2a5510b34c | ||
|
a1aa60ded5 | ||
|
61c921ac6f | ||
|
437b5e7a2e | ||
|
2c2630a788 | ||
|
5a1f6ab2cb | ||
|
f71de429a1 |
11 changed files with 34 additions and 108 deletions
7
Gemfile
7
Gemfile
|
@ -1,7 +1,7 @@
|
||||||
source 'https://rubygems.org'
|
source 'https://rubygems.org'
|
||||||
|
|
||||||
group :development do
|
group :development do
|
||||||
gem 'vagrant', git: 'https://github.com/mitchellh/vagrant.git', tag: 'v1.8.7'
|
gem 'vagrant', git: 'https://github.com/mitchellh/vagrant.git'
|
||||||
gem 'guard'
|
gem 'guard'
|
||||||
gem 'guard-rspec'
|
gem 'guard-rspec'
|
||||||
gem 'rb-inotify'
|
gem 'rb-inotify'
|
||||||
|
@ -9,10 +9,9 @@ end
|
||||||
|
|
||||||
group :development, :test do
|
group :development, :test do
|
||||||
gem 'rake', '~> 10.4.2'
|
gem 'rake', '~> 10.4.2'
|
||||||
gem 'rspec', '~> 2.99.0'
|
gem 'rspec', '~> 3.5.0'
|
||||||
gem 'coveralls', '~> 0.7.2', require: (ENV['COVERAGE'] == 'true')
|
gem 'coveralls', '~> 0.7.2', require: (ENV['COVERAGE'] == 'true')
|
||||||
# The is the ref *just* before we switch to childprocess 0.6, which conflicts with vagrant 1.8 deps.
|
gem 'vagrant-spec', git: 'https://github.com/mitchellh/vagrant-spec.git'
|
||||||
gem 'vagrant-spec', git: 'https://github.com/mitchellh/vagrant-spec.git', ref: '5006bc73cd8796465ca09307d4774f8ec8375aa0'
|
|
||||||
end
|
end
|
||||||
|
|
||||||
group :plugins do
|
group :plugins do
|
||||||
|
|
15
README.md
15
README.md
|
@ -1,8 +1,12 @@
|
||||||
|
🟢 We plan to support and maintain vagrant-lxc, as well as clean it up.<br/>
|
||||||
|
🟢 Please feel free to contribute Issues and pull requests.<br/>
|
||||||
|
🟢 P.S: Thanks [Fabio Rehm](https://fabiorehm.com) for the amazing initial project.
|
||||||
|
|
||||||
# vagrant-lxc
|
# vagrant-lxc
|
||||||
|
|
||||||
[](https://travis-ci.org/fgrehm/vagrant-lxc) [](http://badge.fury.io/rb/vagrant-lxc) [](https://codeclimate.com/github/fgrehm/vagrant-lxc) [](https://coveralls.io/r/fgrehm/vagrant-lxc) [](https://gitter.im/fgrehm/vagrant-lxc)
|
[](https://travis-ci.org/fgrehm/vagrant-lxc) [](http://badge.fury.io/rb/vagrant-lxc) [](https://codeclimate.com/github/fgrehm/vagrant-lxc) [](https://coveralls.io/r/fgrehm/vagrant-lxc) [](https://gitter.im/fgrehm/vagrant-lxc)
|
||||||
|
|
||||||
[LXC](http://lxc.sourceforge.net/) provider for [Vagrant](http://www.vagrantup.com/) 1.8+
|
[LXC](http://lxc.sourceforge.net/) provider for [Vagrant](http://www.vagrantup.com/) 1.9+
|
||||||
|
|
||||||
This is a Vagrant plugin that allows it to control and provision Linux Containers
|
This is a Vagrant plugin that allows it to control and provision Linux Containers
|
||||||
as an alternative to the built in VirtualBox provider for Linux hosts. Check out
|
as an alternative to the built in VirtualBox provider for Linux hosts. Check out
|
||||||
|
@ -17,8 +21,8 @@ to see it in action.
|
||||||
|
|
||||||
## Requirements
|
## Requirements
|
||||||
|
|
||||||
* [Vagrant 1.8+](http://www.vagrantup.com/downloads.html)
|
* [Vagrant 1.9+](http://www.vagrantup.com/downloads.html)
|
||||||
* lxc >=1.0
|
* lxc >=2.1
|
||||||
* `redir` (if you are planning to use port forwarding)
|
* `redir` (if you are planning to use port forwarding)
|
||||||
* `brctl` (if you are planning to use private networks, on Ubuntu this means `apt-get install bridge-utils`)
|
* `brctl` (if you are planning to use private networks, on Ubuntu this means `apt-get install bridge-utils`)
|
||||||
|
|
||||||
|
@ -51,8 +55,9 @@ _More information about skipping the `--provider` argument can be found at the
|
||||||
|
|
||||||
## Base boxes
|
## Base boxes
|
||||||
|
|
||||||
Base boxes can be found on [Atlas](https://atlas.hashicorp.com/boxes/search?provider=lxc)
|
Base boxes provided on Atlas haven't been refreshed for a good while and shouldn't be relied on.
|
||||||
and some scripts to build your own are available at [fgrehm/vagrant-lxc-base-boxes](https://github.com/fgrehm/vagrant-lxc-base-boxes).
|
Your best best is to build your boxes yourself. Some scripts to build your own are available at
|
||||||
|
[hsoft/vagrant-lxc-base-boxes](https://github.com/hsoft/vagrant-lxc-base-boxes).
|
||||||
|
|
||||||
If you want to build your own boxes, please have a look at [`BOXES.md`](https://github.com/fgrehm/vagrant-lxc/tree/master/BOXES.md)
|
If you want to build your own boxes, please have a look at [`BOXES.md`](https://github.com/fgrehm/vagrant-lxc/tree/master/BOXES.md)
|
||||||
for more information.
|
for more information.
|
||||||
|
|
|
@ -21,6 +21,7 @@ module Vagrant
|
||||||
fetch_ip_tries = config.fetch_ip_tries
|
fetch_ip_tries = config.fetch_ip_tries
|
||||||
driver = env[:machine].provider.driver
|
driver = env[:machine].provider.driver
|
||||||
ip = ''
|
ip = ''
|
||||||
|
return config.ssh_ip_addr if not config.ssh_ip_addr.nil?
|
||||||
retryable(:on => LXC::Errors::ExecuteError, :tries => fetch_ip_tries, :sleep => 3) do
|
retryable(:on => LXC::Errors::ExecuteError, :tries => fetch_ip_tries, :sleep => 3) do
|
||||||
unless ip = get_container_ip_from_ip_addr(driver)
|
unless ip = get_container_ip_from_ip_addr(driver)
|
||||||
# retry
|
# retry
|
||||||
|
|
|
@ -108,7 +108,7 @@ module Vagrant
|
||||||
def redir_version
|
def redir_version
|
||||||
stdout, stderr, _ = Open3.capture3 "redir --version"
|
stdout, stderr, _ = Open3.capture3 "redir --version"
|
||||||
# For some weird reason redir printed version information in STDERR prior to 3.2
|
# For some weird reason redir printed version information in STDERR prior to 3.2
|
||||||
version = stdout || stderr
|
version = stdout.empty? ? stderr : stdout
|
||||||
version.split('.')[0].to_i
|
version.split('.')[0].to_i
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,8 @@ module Vagrant
|
||||||
|
|
||||||
attr_accessor :fetch_ip_tries
|
attr_accessor :fetch_ip_tries
|
||||||
|
|
||||||
|
attr_accessor :ssh_ip_addr
|
||||||
|
|
||||||
# Whether the container needs to be privileged. Defaults to true (unprivileged containers
|
# Whether the container needs to be privileged. Defaults to true (unprivileged containers
|
||||||
# is a very new feature in vagrant-lxc). If false, will try creating an unprivileged
|
# is a very new feature in vagrant-lxc). If false, will try creating an unprivileged
|
||||||
# container. If it can't, will revert to the old "sudo wrapper" method to create a privileged
|
# container. If it can't, will revert to the old "sudo wrapper" method to create a privileged
|
||||||
|
@ -37,6 +39,7 @@ module Vagrant
|
||||||
@container_name = UNSET_VALUE
|
@container_name = UNSET_VALUE
|
||||||
@tmpfs_mount_size = UNSET_VALUE
|
@tmpfs_mount_size = UNSET_VALUE
|
||||||
@fetch_ip_tries = UNSET_VALUE
|
@fetch_ip_tries = UNSET_VALUE
|
||||||
|
@ssh_ip_addr = UNSET_VALUE
|
||||||
@privileged = UNSET_VALUE
|
@privileged = UNSET_VALUE
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -66,6 +69,7 @@ module Vagrant
|
||||||
@existing_container_name = nil if @existing_container_name == UNSET_VALUE
|
@existing_container_name = nil if @existing_container_name == UNSET_VALUE
|
||||||
@tmpfs_mount_size = '2G' if @tmpfs_mount_size == UNSET_VALUE
|
@tmpfs_mount_size = '2G' if @tmpfs_mount_size == UNSET_VALUE
|
||||||
@fetch_ip_tries = 10 if @fetch_ip_tries == UNSET_VALUE
|
@fetch_ip_tries = 10 if @fetch_ip_tries == UNSET_VALUE
|
||||||
|
@ssh_ip_addr = nil if @ssh_ip_addr == UNSET_VALUE
|
||||||
@privileged = true if @privileged == UNSET_VALUE
|
@privileged = true if @privileged == UNSET_VALUE
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -50,20 +50,20 @@ module Vagrant
|
||||||
end
|
end
|
||||||
|
|
||||||
def rootfs_path
|
def rootfs_path
|
||||||
config_entry = config_string.match(/^lxc\.rootfs\s+=\s+(.+)$/)[1]
|
pathtype, path = config_string.match(/^lxc\.rootfs(?:\.path)?\s+=\s+(.+:)?(.+)$/)[1..2]
|
||||||
case config_entry
|
case pathtype
|
||||||
when /^overlayfs:/
|
when 'overlayfs:'
|
||||||
# Split on colon (:), ignoring any colon escaped by an escape character ( \ )
|
# Split on colon (:), ignoring any colon escaped by an escape character ( \ )
|
||||||
# Pays attention to when the escape character is itself escaped.
|
# Pays attention to when the escape character is itself escaped.
|
||||||
fs_type, master_path, overlay_path = config_entry.split(/(?<!\\)(?:\\\\)*:/)
|
_, overlay_path = config_entry.split(/(?<!\\)(?:\\\\)*:/)
|
||||||
if overlay_path
|
if overlay_path
|
||||||
Pathname.new(overlay_path)
|
Pathname.new(overlay_path)
|
||||||
else
|
else
|
||||||
# Malformed: fall back to prior behaviour
|
# Malformed: fall back to prior behaviour
|
||||||
Pathname.new(config_entry)
|
Pathname.new(path)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
Pathname.new(config_entry)
|
Pathname.new(path)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -122,10 +122,6 @@ module Vagrant
|
||||||
@cli.destroy
|
@cli.destroy
|
||||||
end
|
end
|
||||||
|
|
||||||
def supports_attach?
|
|
||||||
@cli.supports_attach?
|
|
||||||
end
|
|
||||||
|
|
||||||
def attach(*command)
|
def attach(*command)
|
||||||
@cli.attach(*command)
|
@cli.attach(*command)
|
||||||
end
|
end
|
||||||
|
|
|
@ -89,14 +89,13 @@ module Vagrant
|
||||||
# Man Page:
|
# Man Page:
|
||||||
# 2 The specified container exists but was not running.
|
# 2 The specified container exists but was not running.
|
||||||
def stop
|
def stop
|
||||||
attach '/sbin/halt' if supports_attach?
|
|
||||||
begin
|
begin
|
||||||
run :stop, '--name', @name
|
run :stop, '--name', @name
|
||||||
rescue LXC::Errors::ExecuteError => e
|
rescue LXC::Errors::ExecuteError => e
|
||||||
if e.exitcode == 2
|
if e.exitcode == 2
|
||||||
@logger.debug "Machine already stopped, lxc-stop returned 2"
|
@logger.debug "Machine already stopped, lxc-stop returned 2"
|
||||||
else
|
else
|
||||||
raise e
|
raise e
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -142,19 +141,6 @@ module Vagrant
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def supports_attach?
|
|
||||||
unless defined?(@supports_attach)
|
|
||||||
begin
|
|
||||||
@supports_attach = true
|
|
||||||
run(:attach, '--name', @name, '--', '/bin/true')
|
|
||||||
rescue LXC::Errors::ExecuteError
|
|
||||||
@supports_attach = false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
return @supports_attach
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def run(command, *args)
|
def run(command, *args)
|
||||||
|
|
|
@ -10,7 +10,7 @@ module Vagrant
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
provider(:lxc, parallel: true, priority: 7) do
|
provider(:lxc, parallel: true, priority: 7) do
|
||||||
require File.expand_path("../provider", __FILE__)
|
require_relative 'provider'
|
||||||
init!
|
init!
|
||||||
Provider
|
Provider
|
||||||
end
|
end
|
||||||
|
@ -22,13 +22,13 @@ module Vagrant
|
||||||
end
|
end
|
||||||
|
|
||||||
config(:lxc, :provider) do
|
config(:lxc, :provider) do
|
||||||
require File.expand_path("../config", __FILE__)
|
require_relative 'config'
|
||||||
init!
|
init!
|
||||||
Config
|
Config
|
||||||
end
|
end
|
||||||
|
|
||||||
synced_folder(:lxc) do
|
synced_folder(:lxc) do
|
||||||
require File.expand_path("../synced_folder", __FILE__)
|
require_relative 'synced_folder'
|
||||||
SyncedFolder
|
SyncedFolder
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -390,7 +390,7 @@ else
|
||||||
;;
|
;;
|
||||||
"")
|
"")
|
||||||
if installed ipcalc; then
|
if installed ipcalc; then
|
||||||
eval $(ipcalc -b $IPADDR)
|
eval "$(ipcalc -b $IPADDR)"
|
||||||
ip netns exec "$NSPID" ip addr add "$IPADDR" brd "$BROADCAST" dev "$CONTAINER_IFNAME"
|
ip netns exec "$NSPID" ip addr add "$IPADDR" brd "$BROADCAST" dev "$CONTAINER_IFNAME"
|
||||||
else
|
else
|
||||||
ip netns exec "$NSPID" ip addr add "$IPADDR" dev "$CONTAINER_IFNAME"
|
ip netns exec "$NSPID" ip addr add "$IPADDR" dev "$CONTAINER_IFNAME"
|
||||||
|
|
|
@ -134,36 +134,11 @@ describe Vagrant::LXC::Driver::CLI do
|
||||||
|
|
||||||
before do
|
before do
|
||||||
allow(subject).to receive(:run)
|
allow(subject).to receive(:run)
|
||||||
|
subject.stop
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'lxc-attach is supported' do
|
it 'issues a lxc-stop with provided container name' do
|
||||||
before do
|
expect(subject).to have_received(:run).with(:stop, '--name', name)
|
||||||
subject.stub(attach: true, supports_attach?: true)
|
|
||||||
subject.stop
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'runs a /sbin/halt within the container' do
|
|
||||||
expect(subject).to have_received(:attach).with('/sbin/halt')
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'issues a lxc-stop with provided container name' do
|
|
||||||
expect(subject).to have_received(:run).with(:stop, '--name', name)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'lxc-attach is not supported' do
|
|
||||||
before do
|
|
||||||
subject.stub(attach: false, supports_attach?: false)
|
|
||||||
subject.stop
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'runs a /sbin/halt within the container' do
|
|
||||||
expect(subject).to_not have_received(:attach)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'issues a lxc-stop with provided container name' do
|
|
||||||
expect(subject).to have_received(:run).with(:stop, '--name', name)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -231,33 +206,4 @@ describe Vagrant::LXC::Driver::CLI do
|
||||||
|
|
||||||
skip 'waits for the expected container state'
|
skip 'waits for the expected container state'
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'check for whether lxc-attach is supported' do
|
|
||||||
let(:name) { 'a-running-container' }
|
|
||||||
subject { described_class.new(sudo_wrapper, name) }
|
|
||||||
|
|
||||||
context 'lxc-attach is present on system' do
|
|
||||||
before { subject.stub(run: true) }
|
|
||||||
|
|
||||||
it 'returns true if `lxc-attach --name CNAME -- /bin/true` works' do
|
|
||||||
expect(subject.supports_attach?).to be_truthy
|
|
||||||
expect(subject).to have_received(:run).with(
|
|
||||||
:attach, '--name', name, '--', '/bin/true'
|
|
||||||
)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'lxc-attach is not present on system' do
|
|
||||||
before do
|
|
||||||
allow(subject).to receive(:run).and_raise(Vagrant::LXC::Errors::ExecuteError.new('msg'))
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'returns true if `lxc-attach --name CNAME -- /bin/true` works' do
|
|
||||||
expect(subject.supports_attach?).to be_falsy
|
|
||||||
expect(subject).to have_received(:run).with(
|
|
||||||
:attach, '--name', name, '--', '/bin/true'
|
|
||||||
)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -75,17 +75,6 @@ describe Vagrant::LXC::Driver do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'supports_attach?' do
|
|
||||||
let(:cli) { double(Vagrant::LXC::Driver::CLI, supports_attach?: true) }
|
|
||||||
|
|
||||||
subject { described_class.new('name', nil, cli) }
|
|
||||||
|
|
||||||
it 'delegates to cli object' do
|
|
||||||
expect(subject.supports_attach?).to be_truthy
|
|
||||||
expect(cli).to have_received(:supports_attach?)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe 'start' do
|
describe 'start' do
|
||||||
let(:customizations) { [['a', '1'], ['b', '2']] }
|
let(:customizations) { [['a', '1'], ['b', '2']] }
|
||||||
let(:internal_customization) { ['internal', 'customization'] }
|
let(:internal_customization) { ['internal', 'customization'] }
|
||||||
|
|
Loading…
Add table
Reference in a new issue