This repository has been archived by the owner on Mar 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 283
/
Vagrantfile
93 lines (74 loc) · 2.47 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
# -*- mode: ruby -*-
# vi: set ft=ruby :
VAGRANTFILE_API_VERSION = "2"
$setup = <<SCRIPT
cd ~/
set -ex
# install prerequisites
apt-get update -qq
debconf-set-selections <<< 'mysql-server mysql-server/root_password password vagrant'
debconf-set-selections <<< 'mysql-server mysql-server/root_password_again password vagrant'
apt-get install -q -y build-essential curl libcurl4-openssl-dev git mysql-server libmysqlclient-dev libgmp3-dev libaprutil1-dev libapr1-dev imagemagick libreadline6-dev ruby-dev libssl-dev
# node 8.x
curl -sL https://deb.nodesource.com/setup_8.x | bash -
apt-get install -y nodejs
npm install -g yarn
# ruby gems
gem update --system
gem install bundler
# setup db
mysql -u root -pvagrant -e "grant all on onebody_dev.* to onebody@localhost identified by 'onebody';"
mysql -u root -pvagrant -e "grant all on onebody_test.* to onebody@localhost identified by 'onebody';"
cd /vagrant
bundle install
service=$(cat <<SERVICE
[Unit]
Description=Thin HTTP Server
After=network.target
[Service]
Type=simple
WorkingDirectory=/vagrant
ExecStart=/usr/local/bin/bundle exec thin start
Restart=always
User=vagrant
[Install]
WantedBy=multi-user.target vagrant.mount
SERVICE
)
echo "$service" > /etc/systemd/system/thin.service
systemctl enable thin.service
systemctl start thin.service
user=$(cat <<USER
set -ex
# setup db config
cd /vagrant
if [[ ! -e config/database.yml ]]; then
cp config/database.yml{.mysql-example,}
fi
# install javascript dependencies
yarn
# setup config and migrate db
if [[ ! -e config/secrets.yml ]]; then
secret=\\$(rake -s secret)
sed -e"s/SOMETHING_RANDOM_HERE/\\$secret/g" config/secrets.yml.example > config/secrets.yml
fi
\\rake db:create
\\rake db:migrate db:seed
USER
)
su - vagrant -c "$user"
SCRIPT
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "ubuntu/bionic64"
config.vm.network "forwarded_port", guest: 3000, host: 3000, auto_correct: true
config.ssh.forward_agent = true
config.vm.provision :shell, inline: $setup
config.vm.provision :shell, run: :always,
inline: 'for i in 1 2 3 4 5; do echo "Trying to start Thin server..." && systemctl restart thin && echo "Thin started on port 3000" && break || sleep 4; done'
config.vm.provider :virtualbox do |vb|
vb.customize ["modifyvm", :id, "--memory", "2048"]
end
# apply local customizations
custom_file = File.expand_path("../Vagrantfile.local", __FILE__)
eval(File.read(custom_file)) if File.exists?(custom_file)
end