Skip to content
This repository was archived by the owner on Jan 22, 2026. It is now read-only.

Commit 690c7e0

Browse files
author
Bill Heaton
committed
Add Vagrant setup for local Ubuntu box
1 parent c48bf33 commit 690c7e0

6 files changed

Lines changed: 137 additions & 2 deletions

File tree

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@
1515
config/database.yml
1616
config/secrets.yml
1717

18+
# Ingore seeds, see db/seeds.example.rb
19+
db/seeds.rb
20+
21+
# Ignore Vagrant/Chef setup for local dev in Ubuntu using VirtualBox
22+
/cookbooks
23+
/.vagrant
24+
1825
# Ignore all logfiles and tempfiles.
1926
/log/*
2027
!/log/.keep

.ruby-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.2.2
1+
2.2.1

Cheffile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
site "http://community.opscode.com/api/v1"
2+
3+
cookbook 'apt'
4+
cookbook 'build-essential'
5+
cookbook 'postgresql', '~> 3.4.18'
6+
cookbook 'ruby_build'
7+
cookbook 'nodejs'
8+
cookbook 'rbenv', git: 'https://github.com/aminin/chef-rbenv'
9+
cookbook 'vim'

README.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,28 @@ Copy the db/seeds.example.rb and add records for an user, author and posts
4949

5050
## Tests
5151

52-
* `bundle exec rspec`
52+
* `bundle exec rspec`
53+
54+
55+
## Vagrant
56+
57+
After provisioning with `vagrant up` use `vagrant ssh` then `cd
58+
/vagrant` and execute `rbenv rehash` and `bundle install`
59+
60+
Also add ENV vars: `BLOG_API_DB_USR`, `BLOG_API_DB_PWORD`, `SECRET_KEY_BASE` to the
61+
file /home/vagrant/.profile
62+
63+
Setup the postgres dev db with user/pword:
64+
65+
sudo su - postgres
66+
createuser -P -s -e blog-api
67+
createdb blog_api_development
68+
69+
Start the rails app from the shared folder
70+
71+
vagrant ssh
72+
cd /vagrant
73+
bundle exec rails s -b 0.0.0.0
5374

5475

5576
## Notes / Reference

Vagrantfile

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# -*- mode: ruby -*-
2+
# vi: set ft=ruby :
3+
4+
VAGRANTFILE_API_VERSION = "2"
5+
6+
variables = %w{POSTGRES_PWORD}
7+
missing = variables.find_all { |v| ENV[v] == nil }
8+
unless missing.empty?
9+
puts "FATAL: The following variables are missing and are needed to run this script: #{missing.join(', ')}."
10+
exit
11+
end
12+
13+
# Script to setup vagrant user
14+
$script = <<SCRIPT
15+
16+
echo 'setup .gemrc file'
17+
cat > /home/vagrant/.gemrc << 'EOF'
18+
gem: --no-ri --no-rdoc
19+
EOF
20+
chown vagrant:vagrant /home/vagrant/.gemrc
21+
22+
echo 'append rbenv setup to .profile'
23+
cat << 'EOF' >> /home/vagrant/.profile
24+
export RBENV_ROOT="/home/vagrant/.rbenv"
25+
26+
if [ -d "${RBENV_ROOT}" ]; then
27+
export PATH="${RBENV_ROOT}/bin:${PATH}"
28+
eval "$(rbenv init -)"
29+
fi
30+
31+
alias be="bundle exec"
32+
EOF
33+
34+
SCRIPT
35+
36+
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
37+
# Use Ubuntu 14.04 Trusty Tahr 64-bit as our operating system
38+
config.vm.box = "ubuntu/trusty64"
39+
40+
# Configurate the virtual machine to use 2GB of RAM
41+
config.vm.provider :virtualbox do |vb|
42+
vb.customize ["modifyvm", :id, "--memory", "2048"]
43+
end
44+
45+
# Forward the Rails server default port to the host
46+
config.vm.network :forwarded_port, guest: 3000, host: 3000
47+
# config.vm.network :public_network, bridge: "wlan0", ip: "192.168.10.25"
48+
49+
config.vm.network "public_network", :bridge => "en0: Wi-Fi (AirPort)"
50+
# use `ifconfig` to find ip after `vagrant ssh` or use:
51+
52+
config.ssh.forward_agent = true
53+
54+
# Run the script to setup vagrant user
55+
config.vm.provision :shell, inline: $script
56+
57+
# Use Chef Solo to provision our virtual machine
58+
config.vm.provision :chef_solo do |chef|
59+
60+
chef.cookbooks_path = ["cookbooks", "site-cookbooks"]
61+
62+
chef.add_recipe "apt"
63+
chef.add_recipe "nodejs"
64+
chef.add_recipe "ruby_build"
65+
chef.add_recipe "rbenv::user"
66+
chef.add_recipe "rbenv::vagrant"
67+
chef.add_recipe "vim"
68+
chef.add_recipe "postgresql::server"
69+
chef.add_recipe "postgresql::client"
70+
71+
chef.json = {
72+
rbenv: {
73+
user_installs: [{
74+
# Target global ruby setup when not setting a user
75+
user: "vagrant",
76+
rubies: ["2.2.1"],
77+
global: "2.2.1",
78+
gems: {
79+
"2.2.1" => [
80+
{ "name" => "bundler" },
81+
{ "name" => "rake" }
82+
]
83+
}
84+
}]
85+
},
86+
postgresql: {
87+
password: {
88+
postgres: ENV['POSTGRES_PWORD']
89+
},
90+
pg_hba: [
91+
{ type: 'local', db: 'all', user: 'all', addr: nil, method: 'trust' },
92+
{ type: 'local', db: 'all', user: 'postgres', addr: nil, method: 'trust' },
93+
{ type: 'host', db: 'all', user: 'all', addr: '127.0.0.1/32', method: 'trust' }
94+
]
95+
}
96+
}
97+
end
98+
end

site-cookbooks/.gitkeep

Whitespace-only changes.

0 commit comments

Comments
 (0)