-
Notifications
You must be signed in to change notification settings - Fork 132
/
Vagrantfile
103 lines (95 loc) · 3.83 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
# -*- mode: ruby -*-
# vi: set ft=ruby et:
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.network :forwarded_port, guest: 80, host: 8080 # HTTP
config.vm.synced_folder '.', '/vagrant', disabled: true
config.vm.synced_folder '.', '/home/vagrant/Tatoeba'
webserver_writable_dirs = [
'logs',
'tmp',
'exported_files',
'webroot/img/profiles_128',
'webroot/img/profiles_36',
'webroot/files/audio',
'webroot/files/audio_import',
]
for dir in webserver_writable_dirs
config.vm.synced_folder "./#{dir}", "/home/vagrant/Tatoeba/#{dir}",
group: 'www-data',
mount_options: ["dmode=775,fmode=664"]
end
config.vm.provider "virtualbox" do |v|
# Here you can adjust RAM allocated to the VM:
v.memory = 512 # in MB
# This one is when we build a new VM with "BUILD=1 vagrant up"
v.memory = 1024 if ENV['BUILD'] == '1'
end
if ENV['BUILD'] == '1'
config.vm.box = "debian/contrib-buster64"
config.vm.provision "install", :type => "ansible" do |ansible|
# ansible.verbose = "vvvv"
ansible.playbook = "ansible/vagrant.yml"
end
config.vm.provision "strip", :type => "shell", :path => "reduce_box_size.sh"
else
config.vm.box = "tatoeba/tatovm"
config.vm.box_version = "0.1.0"
config.vm.provision "install",
:type => "shell",
:privileged => false,
:path => "tools/codeinit.py",
:args => ["/home/vagrant/Tatoeba"]
config.vm.provision "db_backup",
:type => "shell",
:run => "never", # because this is executed from triggers
:inline => "mysqldump --all-databases | gzip > /home/vagrant/Tatoeba/databases.sql.gz"
config.vm.provision "db_restore",
:type => "shell",
:run => "never", # because this is executed from triggers
:inline => "zcat /home/vagrant/Tatoeba/databases.sql.gz | mysql"
config.trigger.before :destroy do |trigger|
trigger.ruby do |env,machine|
env.ui.warn("Warning: you are about to destroy the virtual machine.\n" +
"Your code is safe, but the database will be deleted.")
answer = env.ui.ask("Would you like to backup the database before destroying the machine? [n/Y] ")
answer = answer.strip.downcase
answer = "y" if answer.to_s.empty?
if answer != "n"
options = {}
options[:provision_types] = [ :db_backup ]
action = machine.action(:provision, options)
if action[:result] == false
env.ui.error("Backup failed, aborting. Make sure the virtual machine is running.")
abort
else
env.ui.info("Databases backuped into databases.sql.gz. Will be restored upon new machine creation.")
end
end
end
end
config.trigger.after :up do |trigger|
trigger.ruby do |env,machine|
path = File.join(env.cwd, "databases.sql.gz")
if File.exist?(path)
env.ui.warn("A database backup file was found: #{path}")
answer = env.ui.ask("Would you like to restore that backup into the virtual machine? [n/Y]: ")
answer = answer.strip.downcase
answer = "y" if answer.to_s.empty?
if answer != "n"
options = {}
options[:provision_types] = [ :db_restore ]
action = machine.action(:provision, options)
if action[:result] == false
env.ui.error("Restore failed!")
else
env.ui.info("Restore complete.")
env.ui.warn("Removing #{path}...")
File.unlink(path)
end
end
end
end
end
end
end