You can use those bootstrap script to deploy your Rails application to Virtualbox. It's not intended to replace Chef or Puppet, but since its plain bash, its very readable and you can copy some lines and paste to your ssh session...
After installing Vagrant software run vagrant init
and edit your Vagrantfile
# Vagrantfile
Vagrant.configure(2) do |config|
config.vm.provider :virtualbox do |vb, override|
# list of all machines can be found https://atlas.hashicorp.com/boxes/search
override.vm.box = "ubuntu/trusty64"
vb.customize ["modifyvm", :id, "--memory", "2048"]
vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
override.vm.network "forwarded_port", guest: 3000, host: 3000
override.vm.provision :shell, path: 'vagrant/create_deployer_user_and_other_root_tasks.sh', keep_color: true
override.vm.provision :shell, inline: 'sudo -i -u deployer /bin/bash --login -c "source /vagrant/vagrant/bootstrap_ruby_on_rails.sh"', keep_color: true
end
end
then fork this repo and clone locally and simply run vagrant up
git clone https://gist.github.com/8815e439905dbd326a41.git vagrant
vagrant up
- read ruby version from .ruby-version file or from Gemfil or use ruby 2.0
- projects environment secrets should be in
.vagrant.env
. Ignore this file in .gitignore if it contains private keys. It contains env variables that can change deployment process:
# .vagrant.env
export RAILS_ENV=production # use this if you want to run in production mode
export ADDITIONAL_PACKAGES="libmagickwand-dev libqtwebkit-dev" # if your project use gem rmagic and capybara-webkit
export DATABASE_URL=postgresql://deployer@localhost/rails_db # this is default, but you can change to mysql2 adapter and other credentials
export DATABASE_EXTENSIONS="hstore " # if you use postgres hstore
export AWS_SECRET_ACCESS_KEY=123asd # export any third party keys
If you spot any errors, you can rerun script with vagrant provision | tee log/vagrant
.
Note about scripts:
- script should be idempotent so you can provision it several times.
- provision should stop on error since its
set -e
- does not stop in test commands, for example
if [
some_error= "" ]; then echo yo;fi
- does not stop in test commands, for example
- it should work on Rails 3 and Rails 4
- default is postgresql, but works for mysql as well, just put in your
~/.my_staging_secrets.yml
export ADDITIONAL_PACKAGES="mysql-server mysql-client libmysqlclient-dev"
export DATABASE_URL=mysql2://deployer@localhost/rails_db
If something is not working for you please write a comment so we can update the script. I tested with all projects from http://www.opensourcerails.com/
When you set up deployer password, you can ssh directly on VirtalBox :
ssh -p 2222 [email protected]
It should work on Windows as well. Just install VirtualBox, Vagrant and Railsinstaller .
If it is using a Hyper-V than you need to edit env variable. Start -> Computer (right click) -> Properties -> Advanced system settings -> Environment Variables Find system variable: VBOX_MSI_INSTALL_PATH and change its name to VBOX_INSTALL_PATH and value: C:\Program Files\Oracle\VirtualBox hashicorp/vagrant#3896