-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathVagrantfile
170 lines (149 loc) · 5.34 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# -*- mode: ruby -*-
# vi: set ft=ruby :
require 'getoptlong'
#var definition
current_dir=File.dirname(File.expand_path(__FILE__))
alreadyUpdated='false'
docker_provider='false'
LENTIL_PORT="3001"
SFM_PORT="8001"
WEBCONFIG_PORT="8081"
#env check
if ENV['VAGRANT_PLUGINS_UPDATED']=='true'
alreadyUpdated = 'true'
end
if !ENV['DOCKER_HOST'].nil?
docker_provider = 'true'
end
if !ENV['LENTIL_PORT'].nil?
LENTIL_PORT = ENV['LENTIL_PORT']
end
if !ENV['SFM_PORT'].nil?
SFM_PORT = ENV['SFM_PORT']
end
if !ENV['WEBCONFIG_PORT'].nil?
WEBCONFIG_PORT = ENV['WEBCONFIG_PORT']
end
# Verify and install required plugins
required_plugins = "vagrant-host-shell vagrant-exec vagrant-vbguest"
if alreadyUpdated != 'true' && (ARGV[0] == "up" || ARGV[0] == "provision")
system "vagrant plugin install #{required_plugins}"
system "vagrant plugin update #{required_plugins}"
ENV['VAGRANT_PLUGINS_UPDATED'] = 'true'
ENV['VAGRANT_NO_PARALLEL']='true'
# Restart vagrant after plugin updates
exec "vagrant #{ARGV.join(' ')}"
end
Vagrant.configure(2) do |config|
# Host platform detection
if RUBY_PLATFORM["darwin"]
hostOS="OSX"
#TimeZone=`sudo systemsetup -gettimezone|cut -d':' -f2| tr -d '[[:space:]]'`
##res=`vagrant plugin install vagrant-timezone`
elsif RUBY_PLATFORM["linux"]
hostOS="Linux"
#TimeZone=`cat /etc/timezone| tr -d '[[:space:]]'`
#res=`vagrant plugin install vagrant-timezone`
else
hostOS="Windows"
#TimeZone=`tzutil /g`
end
## Setting timezone
#print TimeZone
#if Vagrant.has_plugin?("vagrant-timezone")
#config.timezone.value = TimeZone
#end
if docker_provider == 'false'
config.vm.box = "phusion/ubuntu-14.04-amd64"
# port forwarding configuration
# 8001 -> for sfm
# 3001 -> for lentil
# 8081 -> for the web configuration tool
config.vm.network "forwarded_port", guest: 8000, host: 8001, auto_correct: false
config.vm.network "forwarded_port", guest: 8080, host: 8081, auto_correct: false
config.vm.network "forwarded_port", guest: 3000, host: 3001, auto_correct: false
# Allocate RAM to VM
# Parallels image
config.vm.provider "parallels" do |p, override|
override.vm.box = "parallels/ubuntu-14.04"
#p.memory = "2048"
end
# Update package list
config.vm.provision "update", type: "shell" do |s|
s.inline = "apt-get update"
end
# docker based provisioning for lentil and sfm
# Just pull the images from Docker Hub
config.vm.provision "docker"
config.vm.provision :shell, :inline => "sudo start docker || true", run: "always"
# Shell based provisioning to bring up containers using docker compose
config.vm.provision "init", type: "shell" do |s|
s.inline = "cd /vagrant && chmod u+x init.sh && ./init.sh"
end
# TODO: Upgrade procedure
#config.vm.provision "upgrade", type: "shell" do |s|
#s.inline = "cd /vagrant && chmod u+x upgrade.sh && ./upgrade.sh"
#end
elsif docker_provider == 'true'
h = Hash[*File.read('sfm/sfm_config.txt').split(/[= \n]+/)]
config.vm.define "combinedb" do |db|
db.vm.provider "docker" do |d|
d.name = "combinedb"
d.image = "ncsulibrariesdli/combine_pg:latest"
d.pull = true
d.env = {
"POSTGRES_PASSWORD" => "gherD42#dl5"
}
end
end
config.vm.define "lentil" do |app|
app.vm.provider "docker" do |d|
d.name = "lentilapp"
d.image = "ncsulibrariesdli/combine_lentil:latest"
d.pull = true
d.link "combinedb:mydb"
d.ports = ["#{LENTIL_PORT}:3000"]
d.volumes = ["#{current_dir}/lentil:/src/lentil","#{current_dir}/archive/lentil-store:/lentil-store"]
end
end
config.vm.define "sfm" do |app|
app.vm.provider "docker" do |d|
d.name = "sfmapp"
d.image = "gwul/sfm_app:latest"
d.pull = true
d.link "combinedb:db"
d.ports = ["#{SFM_PORT}:80"]
d.env = {
"SFM_TWITTER_DEFAULT_USERNAME" => h['SFM_TWITTER_DEFAULT_USERNAME'],
"SFM_TWITTER_CONSUMER_KEY" => h['SFM_TWITTER_CONSUMER_KEY'],
"SFM_TWITTER_CONSUMER_SECRET" => h['SFM_TWITTER_CONSUMER_SECRET']
}
d.volumes = ["#{current_dir}/sfm:/src/sfm","#{current_dir}/archive/sfm-store:/var/sfm"]
end
end
config.vm.define "web" do |web|
web.vm.provider "docker" do |d|
d.name = "webconfig"
d.image = "ncsulibrariesdli/combine_webconfig:latest"
d.pull = true
d.ports = ["#{WEBCONFIG_PORT}:8080"]
d.env = {
"DOCKER_HOST" => ENV['DOCKER_HOST']
}
d.volumes = ["#{current_dir}/lentil:/src/lentil","#{current_dir}/sfm:/src/sfm","#{current_dir}/web-configuration-tool:/src/web-configuration-tool","#{current_dir}/config_updates:/src/config_updates"]
end
end
end
# Host provisioning to spawn config tool
if Vagrant.has_plugin?("vagrant-host-shell")
config.vm.provision "configuration", type: "host_shell" do |host_shell|
if hostOS == 'OSX'
host_shell.inline = 'open http://localhost:8081'
elsif hostOS == 'Linux'
host_shell.inline = 'xdg-open "http://localhost:8081"'
elsif hostOS == 'Windows'
host_shell.inline = 'start "link" "http://localhost:8081"'
end
end
end
end #config end