First stab at setting up a lxc container for developing the gem itself
This commit is contained in:
parent
9a168950fe
commit
72893299f4
4 changed files with 221 additions and 0 deletions
46
development/Vagrantfile
vendored
Normal file
46
development/Vagrantfile
vendored
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
# -*- mode: ruby -*-
|
||||||
|
# vi: set ft=ruby :
|
||||||
|
|
||||||
|
def local_cache(box_name)
|
||||||
|
cache_dir = File.join(File.expand_path(Vagrant::Environment::DEFAULT_HOME),
|
||||||
|
'cache',
|
||||||
|
'apt',
|
||||||
|
box_name)
|
||||||
|
partial_dir = File.join(cache_dir, 'partial')
|
||||||
|
FileUtils.mkdir_p(partial_dir) unless File.exists? partial_dir
|
||||||
|
cache_dir
|
||||||
|
end
|
||||||
|
|
||||||
|
Vagrant.require_plugin 'vagrant-lxc'
|
||||||
|
|
||||||
|
Vagrant.configure("2") do |config|
|
||||||
|
config.vm.box = "lxc-quantal64"
|
||||||
|
config.vm.box_url = 'http://dl.dropbox.com/u/13510779/lxc-quantal64-2013-03-08.box'
|
||||||
|
config.vm.hostname = 'lxc-quantal64'
|
||||||
|
|
||||||
|
config.vm.synced_folder "../", "/vagrant", name: 'vagrant-root'
|
||||||
|
|
||||||
|
cache_dir = local_cache(config.vm.box)
|
||||||
|
config.vm.synced_folder cache_dir,
|
||||||
|
"/var/cache/apt/archives/",
|
||||||
|
name: "vagrant-cache"
|
||||||
|
|
||||||
|
config.vm.provider :lxc do |lxc|
|
||||||
|
# Not sure we need this
|
||||||
|
lxc.start_opts << 'lxc.aa_profile=unconfined'
|
||||||
|
end
|
||||||
|
|
||||||
|
config.vm.provision :shell, inline: '
|
||||||
|
if ! [ -f /home/vagrant/.updated ]; then
|
||||||
|
sudo apt-get update &&
|
||||||
|
sudo apt-get install puppet -y &&
|
||||||
|
touch /home/vagrant/.updated
|
||||||
|
fi'
|
||||||
|
|
||||||
|
config.vm.provision :puppet do |puppet|
|
||||||
|
puppet.manifests_path = "."
|
||||||
|
puppet.manifest_file = "site.pp"
|
||||||
|
# Pass DEBUG=1 to vagrant commands if you want to make some debugging noise
|
||||||
|
puppet.options << [ '--verbose', '--debug' ] if ENV['DEBUG'] == '1'
|
||||||
|
end
|
||||||
|
end
|
37
development/lxc-configs/lxc-dev-default
Normal file
37
development/lxc-configs/lxc-dev-default
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
###############################################################################
|
||||||
|
# This file has the same configs as the built in /etc/default/lxc on Ubuntu,
|
||||||
|
# we only changed IPs to 10.0.254.* to avoid collision with LXC default 10.0.3.*
|
||||||
|
# which is likely to be running from the host machine
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
|
||||||
|
# MIRROR to be used by ubuntu template at container creation:
|
||||||
|
# Leaving it undefined is fine
|
||||||
|
#MIRROR="http://archive.ubuntu.com/ubuntu"
|
||||||
|
# or
|
||||||
|
#MIRROR="http://<host-ip-addr>:3142/archive.ubuntu.com/ubuntu"
|
||||||
|
|
||||||
|
# LXC_AUTO - whether or not to start containers symlinked under
|
||||||
|
# /etc/lxc/auto
|
||||||
|
LXC_AUTO="true"
|
||||||
|
|
||||||
|
# Leave USE_LXC_BRIDGE as "true" if you want to use lxcbr0 for your
|
||||||
|
# containers. Set to "false" if you'll use virbr0 or another existing
|
||||||
|
# bridge, or mavlan to your host's NIC.
|
||||||
|
USE_LXC_BRIDGE="true"
|
||||||
|
|
||||||
|
# If you change the LXC_BRIDGE to something other than lxcbr1, then
|
||||||
|
# you will also need to update your /etc/lxc/lxc.conf as well as the
|
||||||
|
# configuration (/var/lib/lxc/<container>/config) for any containers
|
||||||
|
# already created using the default config to reflect the new bridge
|
||||||
|
# name.
|
||||||
|
# If you have the dnsmasq daemon installed, you'll also have to update
|
||||||
|
# /etc/dnsmasq.d/lxc and restart the system wide dnsmasq daemon.
|
||||||
|
LXC_BRIDGE="lxcbr1"
|
||||||
|
LXC_ADDR="10.0.254.1"
|
||||||
|
LXC_NETMASK="255.255.255.0"
|
||||||
|
LXC_NETWORK="10.0.254.0/24"
|
||||||
|
LXC_DHCP_RANGE="10.0.254.2,10.0.254.254"
|
||||||
|
LXC_DHCP_MAX="253"
|
||||||
|
|
||||||
|
LXC_SHUTDOWN_TIMEOUT=120
|
25
development/setup-lxc-dev-box
Executable file
25
development/setup-lxc-dev-box
Executable file
|
@ -0,0 +1,25 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# Package ubuntu-cloud
|
||||||
|
if ! [ -f ../boxes/output/ubuntu-cloud.box ]; then
|
||||||
|
bundle exec rake boxes:build:ubuntu-cloud
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Fresh start
|
||||||
|
bundle exec vagrant-lxc destroy
|
||||||
|
|
||||||
|
# Skip provisioning as we need to apt-get update first
|
||||||
|
bundle exec vagrant-lxc up --provider=lxc --no-provision
|
||||||
|
|
||||||
|
# Trigger an update from here instead of doing it from puppet as we don't need to
|
||||||
|
# apt-get update every time we boot the container. If there is a way to do it
|
||||||
|
# from puppet I don't know. If you do, feel free to send a pull request ;)
|
||||||
|
bundle exec vagrant-lxc ssh -c '
|
||||||
|
sudo sed -i -e "s/archive./br.archive./g" /etc/apt/sources.list &&
|
||||||
|
sudo apt-get update'
|
||||||
|
bundle exec vagrant-lxc provision
|
||||||
|
|
||||||
|
# Reload the container just to ensure it can boot properly after the upgrades
|
||||||
|
bundle exec vagrant-lxc reload
|
113
development/site.pp
Normal file
113
development/site.pp
Normal file
|
@ -0,0 +1,113 @@
|
||||||
|
Exec { path => [ '/bin/', '/sbin/' , '/usr/bin/', '/usr/sbin/', '/usr/local/bin'] }
|
||||||
|
|
||||||
|
# Because I'm lazy ;)
|
||||||
|
exec {
|
||||||
|
'echo "alias be=\"bundle exec\"" >> ~/.bashrc':
|
||||||
|
unless => 'grep -q "bundle exec" ~/.bashrc';
|
||||||
|
|
||||||
|
'echo "cd /vagrant" >> ~/.bashrc':
|
||||||
|
unless => 'grep -q "cd /vagrant" ~/.bashrc';
|
||||||
|
}
|
||||||
|
|
||||||
|
# Overwrite LXC default configs
|
||||||
|
exec {
|
||||||
|
'config-lxc':
|
||||||
|
# We need to do this otherwise IPs will collide with the host's lxc dhcp server.
|
||||||
|
# If we install the package prior to setting this configs the container will go crazy.
|
||||||
|
command => 'cp /vagrant/development/lxc-configs/lxc-dev-default /etc/default/lxc',
|
||||||
|
unless => 'grep -q "10.0.4" /etc/default/lxc'
|
||||||
|
}
|
||||||
|
|
||||||
|
# Install dependencies
|
||||||
|
package {
|
||||||
|
[ 'libffi-dev', 'bsdtar', 'exuberant-ctags', 'ruby1.9.1-dev', 'htop', 'git', 'build-essential' ]:
|
||||||
|
ensure => 'installed'
|
||||||
|
;
|
||||||
|
|
||||||
|
'lxc':
|
||||||
|
require => Exec['config-lxc']
|
||||||
|
;
|
||||||
|
|
||||||
|
'bundler':
|
||||||
|
ensure => 'installed',
|
||||||
|
provider => 'gem'
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
# Allow gems to be installed on vagrant user home avoiding "sudo"s
|
||||||
|
# Tks to http://wiki.railsplayground.com/railsplayground/show/How+to+install+gems+and+non+root+user
|
||||||
|
file {
|
||||||
|
'/home/vagrant/gems':
|
||||||
|
ensure => directory,
|
||||||
|
owner => 'vagrant',
|
||||||
|
group => 'vagrant'
|
||||||
|
;
|
||||||
|
|
||||||
|
'/home/vagrant/.gemrc':
|
||||||
|
content => '
|
||||||
|
---
|
||||||
|
:verbose: true
|
||||||
|
gem: --no-ri --no-rdoc
|
||||||
|
:update_sources: true
|
||||||
|
:sources:
|
||||||
|
- http://gems.rubyforge.org
|
||||||
|
- http://gems.github.com
|
||||||
|
:backtrace: false
|
||||||
|
:bulk_threshold: 1000
|
||||||
|
:benchmark: false
|
||||||
|
gemhome: $HOME/gems
|
||||||
|
gempath:
|
||||||
|
- /home/vagrant/gems
|
||||||
|
- /usr/local/lib/ruby/gems/1.8
|
||||||
|
'
|
||||||
|
}
|
||||||
|
exec {
|
||||||
|
'set-gem-paths':
|
||||||
|
command => 'cat << EOF >> /home/vagrant/.profile
|
||||||
|
export GEM_HOME=/home/vagrant/gems
|
||||||
|
export GEM_PATH=/home/vagrant/gems:/var/lib/gems/1.9.1
|
||||||
|
export PATH=$PATH:/vagrant/gems/bin
|
||||||
|
EOF',
|
||||||
|
unless => 'grep -q "GEM_HOME" /home/vagrant/.profile'
|
||||||
|
}
|
||||||
|
|
||||||
|
# Bundle!
|
||||||
|
exec {
|
||||||
|
'su -l vagrant -c "cd /vagrant && bundle install"':
|
||||||
|
# We are checking for guard-rspec here but it could be any gem...
|
||||||
|
unless => 'gem list guard | grep -q rspec',
|
||||||
|
cwd => '/vagrant',
|
||||||
|
require => [
|
||||||
|
Exec['set-gem-paths'],
|
||||||
|
File['/home/vagrant/gems', '/home/vagrant/.gemrc'],
|
||||||
|
Package['bundler']
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
# Setup vagrant default ssh key
|
||||||
|
file {
|
||||||
|
'/home/vagrant/.ssh':
|
||||||
|
ensure => directory,
|
||||||
|
owner => 'vagrant',
|
||||||
|
group => 'vagrant'
|
||||||
|
}
|
||||||
|
exec {
|
||||||
|
'download-private-key':
|
||||||
|
command => 'wget https://raw.github.com/mitchellh/vagrant/master/keys/vagrant -O /home/vagrant/.ssh/id_rsa',
|
||||||
|
creates => '/home/vagrant/.ssh/id_rsa',
|
||||||
|
require => File['/home/vagrant/.ssh'],
|
||||||
|
user => 'vagrant'
|
||||||
|
;
|
||||||
|
|
||||||
|
'wget https://raw.github.com/mitchellh/vagrant/master/keys/vagrant.pub -O /home/vagrant/.ssh/id_rsa.pub':
|
||||||
|
creates => '/home/vagrant/.ssh/id_rsa.pub',
|
||||||
|
require => File['/home/vagrant/.ssh'],
|
||||||
|
user => 'vagrant'
|
||||||
|
;
|
||||||
|
}
|
||||||
|
file {
|
||||||
|
'/home/vagrant/.ssh/id_rsa':
|
||||||
|
ensure => 'present',
|
||||||
|
mode => '0600',
|
||||||
|
require => Exec['download-private-key']
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue