Skip to content

Instantly share code, notes, and snippets.

@basti
Last active November 9, 2016 15:37
Show Gist options
  • Save basti/e0ad825972f3a8ae6a63c2e71e54c128 to your computer and use it in GitHub Desktop.
Save basti/e0ad825972f3a8ae6a63c2e71e54c128 to your computer and use it in GitHub Desktop.
Heroku-like Vagrant setup

Summary

This will setup Heroku-like box using VirtualBox. For more information about base box go here

Requirements

You should have VirtualBox and Vagrant installed.

Steps

  • In your project root create Vagrantfile using template provided here.
  • On your host machine run commands from 2_host.sh
  • On your guest machine run commands from 3_guest.sh

After that you should have /vagrant on guest machine be a shared dir with host machine and it will contain the files from dir in which you created Vagrantfile.

Vagrant.configure("2") do |config|
config.vm.box = "lazygray/heroku-cedar-14"
config.vm.synced_folder ".", "/vagrant", :nfs => true
config.vm.network :private_network, ip: "192.168.1.42" # required for NFS
end
# run these on your host machine
# fix for Vagrant 1.8.7 which has problems with downloading boxes
# make sure you have system curl installed
# see https://github.com/mitchellh/vagrant/issues/7969
# NOTE: this step is only required if you are using Vagrant 1.8.7
sudo rm -rf /opt/vagrant/embedded/bin/curl
# for more about the box your are going to install visit:
# https://atlas.hashicorp.com/lazygray/boxes/heroku-cedar-14
# in dir where Vagrantfile is located
vagrant up
vagrant ssh
# run these on your guest machine, i.e. within your virtual machine
# upgrade ruby-build to be able to install newer Ruby versions
cd /home/vagrant/.rbenv/plugins/ruby-build && git pull
rbenv install 2.2.3
rbenv global 2.2.3
gem install bundler
@Ikera
Copy link

Ikera commented Nov 9, 2016

Potential problems:

  1. during bundle install I needed to install nikogiri gem separate gem install nokogiri -v '1.6.8'
  2. before rake db:create I needed to create postgres user with
    sudo -u postgres createuser --createdb vagrant
  3. after rake db:schema:load we need to go in rails console and create one House
    House.create(title: "First House", actual_value: 100000)
  4. start rails server: bundle exec rails s -b 0.0.0.0
  5. find app on 192.168.1.42:3000

For Cucumber:

  1. sudo apt-get update
  2. sudo apt-get install firefox
  3. sudo apt-get install xvfb
  4. sudo wget -O /etc/init.d/xvfb https://gist.github.com/basti/2db0b71e893ee4d6d015/raw/5a3d63996b61ef034074a6ffd6cd07d4801fcde7/xvfb
  5. sudo chmod a+x /etc/init.d/xvfb
  6. export DISPLAY=:10
  7. sudo /etc/init.d/xvfb start

Note: read this blog post http://icebergist.com/posts/headless-firefox-in-ubuntu-on-virtual-box-for-cucumber-testing/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment