forked from ctweney/bifrost
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Vagrantfile
59 lines (45 loc) · 1.6 KB
/
Vagrantfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# Commands required to setup working docker enviro, link
# containers etc.
$setup = <<SCRIPT
# Stop and remove any existing containers
docker stop $(docker ps -a -q)
docker rm $(docker ps -a -q)
# Build containers from Dockerfiles
docker build -t postgres /app/docker/postgres
docker build -t rails /app
# Run and link the containers
docker run -d --name postgres -e POSTGRESQL_USER=docker -e POSTGRESQL_PASS=docker postgres:latest
docker run -e "RAILS_ENV=$1" -d -p 3000:3000 -v /app:/app --link postgres:db --name rails rails:latest
SCRIPT
# Commands required to ensure correct docker containers
# are started when the vm is rebooted.
$start = <<SCRIPT
docker start postgres
docker start rails
SCRIPT
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure("2") do |config|
# Setup resource requirements
config.vm.provider "virtualbox" do |v|
v.memory = 2048
v.cpus = 2
end
# need a private network for NFS shares to work
config.vm.network "private_network", ip: "192.168.50.4"
# Rails Server Port Forwarding
config.vm.network "forwarded_port", guest: 3000, host: 3000
# Ubuntu
config.vm.box = "ubuntu/trusty64"
# Install latest docker
config.vm.provision "docker"
# Must use NFS for this otherwise rails
# performance will be awful
config.vm.synced_folder ".", "/app", type: "nfs"
# Setup the containers when the VM is first
# created
RAILS_ENV = ENV['RAILS_ENV'] || "production"
config.vm.provision "shell", inline: $setup, args: RAILS_ENV
# Make sure the correct containers are running
# every time we start the VM.
config.vm.provision "shell", run: "always", inline: $start
end