forked from dappur/framework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Vagrantfile
71 lines (62 loc) · 1.73 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
# -*- mode: ruby -*-
# vi: set ft=ruby :
require 'securerandom'
# Globals
httpPort = 8181
mysqlPort = 8306
rootPass = "rootpass"
# Check if settings json file exists or create
if not File.file?('settings.json')
IO.copy_stream('settings.json.dist', 'settings.json')
end
# Get Settings & Environment
settings = JSON.parse(File.read('settings.json'))
env = settings['environment']
# Update environment db port
settings['db'][env]['port'] = mysqlPort
if settings['cron']['token'].empty?
settings['cron']['token'] = SecureRandom.uuid.split('-').join
end
if settings['deployment']['deploy_token'].empty?
settings['deployment']['deploy_token'] = SecureRandom.uuid.split('-').join
end
File.open("settings.json","w") do |f|
f.write(JSON.pretty_generate settings)
end
# Get Database From settings.json
database = settings['db'][env]
dbName = database['database']
dbUser = database['username']
dbPass = database['password']
Vagrant.configure("2") do |config|
# ubuntu 18.04
config.vm.box = "bento/ubuntu-18.04"
# forward http port
config.vm.network "forwarded_port",
guest: httpPort,
host: httpPort
# forward mysql port
config.vm.network "forwarded_port",
guest: mysqlPort,
host: mysqlPort
# provision
config.vm.provision "shell",
path: "storage/vagrant/provision.sh",
privileged: false,
args: [
httpPort,
rootPass,
dbName,
dbUser,
dbPass,
mysqlPort,
]
# migrate push command
config.push.define "migrate", strategy: "local-exec" do |push|
push.script = "storage/vagrant/push.migrate.sh"
end
# rollback push command
config.push.define "rollback", strategy: "local-exec" do |push|
push.script = "storage/vagrant/push.rollback.sh"
end
end