Finally a decent development environment 😎
This commit is contained in:
parent
a5d18567cb
commit
aa57fd794b
5 changed files with 16 additions and 181 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -22,8 +22,6 @@ doc/
|
|||
.vagrant
|
||||
/cache
|
||||
|
||||
Vagrantfile
|
||||
|
||||
/boxes/**/*.tar.gz
|
||||
/boxes/quantal64/rootfs-amd64/
|
||||
/boxes/output/
|
||||
|
|
|
@ -1,25 +0,0 @@
|
|||
# -*- mode: ruby -*-
|
||||
# vi: set ft=ruby :
|
||||
|
||||
if Vagrant::VERSION =~ /^1\.1/
|
||||
raise 'This Vagrantfile is meant to be used with Vagrant 1.0'
|
||||
end
|
||||
|
||||
Vagrant::Config.run do |config|
|
||||
config.vm.box = "quantal64"
|
||||
config.vm.box_url = "https://github.com/downloads/roderik/VagrantQuantal64Box/quantal64.box"
|
||||
|
||||
if defined? VagrantVbguest::Config
|
||||
config.vbguest.auto_update = false
|
||||
config.vbguest.no_remote = true
|
||||
end
|
||||
|
||||
config.vm.network :hostonly, "192.168.33.10"
|
||||
config.vm.customize [
|
||||
"modifyvm", :id,
|
||||
"--memory", 1024,
|
||||
"--cpus", "2"
|
||||
]
|
||||
|
||||
config.vm.share_folder("v-root", "/vagrant", ".", :nfs => true)
|
||||
end
|
|
@ -25,9 +25,16 @@ Vagrant.configure("2") do |config|
|
|||
"/var/cache/apt/archives/",
|
||||
name: "vagrant-cache"
|
||||
|
||||
config.vm.provider :lxc do |lxc|
|
||||
# Required to boot nested containers
|
||||
lxc.start_opts << 'lxc.aa_profile=unconfined'
|
||||
end
|
||||
|
||||
config.vm.provision :shell, inline: '
|
||||
if ! `which puppet > /dev/null`; then
|
||||
sudo apt-get update &&
|
||||
sudo apt-get install puppet -y'
|
||||
sudo apt-get install puppet -y
|
||||
fi'
|
||||
|
||||
config.vm.provision :puppet do |puppet|
|
||||
puppet.manifests_path = "."
|
||||
|
|
|
@ -2,19 +2,17 @@
|
|||
|
||||
set -e
|
||||
|
||||
# Package quantal64
|
||||
if ! [ -f ../boxes/output/lxc-quantal64.box ]; then
|
||||
bundle exec rake boxes:quantal64:build
|
||||
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
|
||||
bundle exec vagrant-lxc up --no-provision --provider=lxc
|
||||
|
||||
bundle exec vagrant-lxc ssh -c 'sudo apt-get update && sudo apt-get install puppet -y'
|
||||
bundle exec vagrant-lxc provision
|
||||
# apt-get and install puppet so we can provision the dev machine
|
||||
bundle exec vagrant-lxc provision --provision-with=shell
|
||||
|
||||
# Reload the container just to ensure it can boot properly after the upgrades
|
||||
# Actual setup
|
||||
bundle exec vagrant-lxc provision --provision-with=puppet
|
||||
|
||||
# Reload the container just to ensure it can boot properly after provisioning
|
||||
bundle exec vagrant-lxc reload
|
||||
|
|
|
@ -1,143 +0,0 @@
|
|||
#!/usr/bin/env ruby
|
||||
|
||||
# I know, we should be using something like puppet or chef but trust me, this
|
||||
# started as a small script :-)
|
||||
# Please check https://github.com/fgrehm/vagrant-lxc/issues/7 for the current status.
|
||||
|
||||
# In case something goes wrong after the machine has been set up, you can run this
|
||||
# script again and it will ask you if you want to restore a clean snapshot.
|
||||
|
||||
raise 'You should not run this script from the dev box' if ENV['USER'] == 'vagrant'
|
||||
|
||||
require 'bundler'
|
||||
require 'json'
|
||||
|
||||
IMAGE_ROOT = 'https://cloud-images.ubuntu.com/releases/quantal/release-20130206'
|
||||
IMAGE_NAME = 'ubuntu-12.10-server-cloudimg-amd64-root.tar.gz'
|
||||
|
||||
def download(source, destination)
|
||||
destination = "#{File.dirname __FILE__}/#{destination}"
|
||||
return if File.exists?(destination)
|
||||
|
||||
sh "wget #{source} -O #{destination}"
|
||||
end
|
||||
|
||||
def sh(cmd)
|
||||
Bundler.with_clean_env do
|
||||
puts cmd
|
||||
raise 'Errored!' unless system cmd
|
||||
end
|
||||
end
|
||||
|
||||
def restore_snapshot!
|
||||
sh 'vagrant halt -f'
|
||||
conf = JSON.parse File.read('.vagrant')
|
||||
id = conf['active']['default']
|
||||
sh "VBoxManage snapshot '#{id}' restore ready-to-rock"
|
||||
sh 'vagrant up'
|
||||
exit 0
|
||||
end
|
||||
|
||||
def vagrant_ssh(cmd)
|
||||
sh "vagrant ssh -c '#{cmd}'"
|
||||
end
|
||||
|
||||
Bundler.with_clean_env do
|
||||
# Ensure box has not been created yet
|
||||
unless `vagrant status` =~ /not created/
|
||||
print 'Vagrant box already created, do you want to [r]ecreate it, restore [s]napshot or [A]bort? '
|
||||
answer = gets.chomp
|
||||
exit 0 if answer.empty? || answer =~ /^a/i
|
||||
|
||||
case
|
||||
when answer =~ /^s/i
|
||||
restore_snapshot!
|
||||
when answer =~ /^r/i
|
||||
sh 'vagrant destroy -f'
|
||||
else
|
||||
puts 'Invalid option!'
|
||||
exit 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Cache development dependencies
|
||||
`mkdir -p cache`
|
||||
|
||||
# Fetches vagrant submodule
|
||||
`git submodule update --init`
|
||||
|
||||
# Download container image for building the base ubuntu-cloud box
|
||||
download "#{IMAGE_ROOT}/#{IMAGE_NAME}", "boxes/ubuntu-cloud/#{IMAGE_NAME}"
|
||||
|
||||
# Start vagrant
|
||||
sh 'vagrant up'
|
||||
|
||||
# Because I'm lazy ;)
|
||||
vagrant_ssh 'echo "cd /vagrant" >> ~/.bashrc'
|
||||
vagrant_ssh 'echo "alias be=\"bundle exec\"" >> ~/.bashrc'
|
||||
|
||||
# "be" archive is too slow for me
|
||||
vagrant_ssh 'sudo sed -i -e "s/be.archive/br.archive/g" /etc/apt/sources.list'
|
||||
|
||||
# Ensure we have the latest packages around
|
||||
vagrant_ssh "sudo apt-get update && sudo apt-get dist-upgrade -y"
|
||||
|
||||
# Ensure the machine can boot properly after upgrades and dependencies have been installed
|
||||
sh 'vagrant reload'
|
||||
|
||||
# Install dependencies
|
||||
vagrant_ssh "sudo apt-get install lxc rinetd libffi-dev bsdtar exuberant-ctags libffi-ruby ruby1.9.1-dev htop git virtualbox virtualbox-ose-dkms linux-headers-generic linux-headers-3.5.0-25-generic -y && sudo gem install bundler --no-ri --no-rdoc"
|
||||
# vagrant_ssh "sudo dkms install virtualbox/4.1.18"
|
||||
# vagrant_ssh "sudo service virtualbox start"
|
||||
|
||||
# Ensure the machine can boot properly after dependencies have been installed
|
||||
sh 'vagrant reload'
|
||||
|
||||
# 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
|
||||
vagrant_ssh 'mkdir -p ~/gems'
|
||||
vagrant_ssh "cat << EOF >> ~/.profile
|
||||
export GEM_HOME=$HOME/gems
|
||||
export GEM_PATH=$HOME/gems:/var/lib/gems/1.9.1
|
||||
export PATH=$PATH:$HOME/gems/bin
|
||||
EOF"
|
||||
vagrant_ssh "cat << EOF > .gemrc
|
||||
---
|
||||
: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/gems
|
||||
- /usr/local/lib/ruby/gems/1.8
|
||||
EOF"
|
||||
|
||||
# Backup rinetd config
|
||||
vagrant_ssh "cp /etc/rinetd.conf /vagrant/cache/rinetd.conf"
|
||||
|
||||
# Make rinetd writable by vagrant user
|
||||
vagrant_ssh 'sudo chown vagrant:vagrant /etc/rinetd.conf'
|
||||
|
||||
# Setup vagrant default ssh key
|
||||
vagrant_keys_path = '/vagrant/vendor/vagrant/keys'
|
||||
vagrant_ssh "mkdir -p ~/.ssh && cd /vagrant && cp #{vagrant_keys_path}/vagrant ~/.ssh/id_rsa && cp #{vagrant_keys_path}/vagrant.pub ~/.ssh/id_rsa.pub && chmod 600 ~/.ssh/id_rsa"
|
||||
|
||||
# Bundle!
|
||||
vagrant_ssh 'cd /vagrant && bundle && cd /vagrant/example && bundle'
|
||||
|
||||
# Add base box
|
||||
vagrant_ssh 'cd /vagrant && rake boxes:build:ubuntu-cloud'
|
||||
|
||||
# Click
|
||||
sh 'vagrant halt'
|
||||
conf = JSON.parse File.read('.vagrant')
|
||||
id = conf['active']['default']
|
||||
sh "VBoxManage snapshot '#{id}' take ready-to-rock"
|
||||
sh 'vagrant up'
|
Loading…
Reference in a new issue