-
-
Notifications
You must be signed in to change notification settings - Fork 73
/
Vagrantfile
137 lines (109 loc) · 3.4 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
# Handy commands:
# sudo systemctl status puma.socket puma.service
# A hot restart, puma.socket keeps listening:
# sudo systemctl restart puma.service
# Normal restart:
# sudo systemctl restart puma.socket puma.service
# https://www.freedesktop.org/software/systemd/man/systemd.service.html
# https://www.freedesktop.org/software/systemd/man/systemd.socket.html
# https://github.com/puma/puma/blob/master/docs/systemd.md
$env = <<SCRIPT
PATH=/home/vagrant/.rbenv/bin:/home/vagrant/.rbenv/versions/global/bin:/home/vagrant/.rbenv/versions/global/lib/ruby/gems/version/bin:$PATH
APP_ENV=production
LOGFILE=1
REDIS_URL=redis://localhost:6379/3
#TWITTER_ACCESS_TOKEN=
#GOOGLE_API_KEY=
#VIMEO_ACCESS_TOKEN=
#INSTAGRAM_SESSIONID=
#SOUNDCLOUD_CLIENT_ID=
#TWITCH_CLIENT_ID=
#TWITCHTOKEN_CLIENT_ID=
#IMGUR_CLIENT_ID=
#GOOGLE_VERIFICATION_TOKEN=googleXXXXXXXXXXXXXXXX.html
SCRIPT
$puma_service = <<SCRIPT
[Unit]
Description=Puma
After=network.target
Requires=puma.socket
[Service]
Type=simple
User=vagrant
WorkingDirectory=/vagrant/
EnvironmentFile=/home/vagrant/rssbox.env
ExecStart=/home/vagrant/.rbenv/versions/global/bin/puma -C config/puma.rb -p 3000
Restart=always
[Install]
WantedBy=multi-user.target
SCRIPT
$puma_socket = <<SCRIPT
[Unit]
Description=Puma Socket
[Socket]
ListenStream=0.0.0.0:3000
NoDelay=true
ReusePort=true
Backlog=1024
[Install]
WantedBy=sockets.target
SCRIPT
$root_provision = <<SCRIPT
export DEBIAN_FRONTEND=noninteractive
chmod -x /etc/cron.daily/apt-compat
chmod -x /etc/cron.weekly/update-notifier-common
apt-get update
apt-get install -y git curl build-essential redis-server jq
apt-get install -y libreadline-dev zlib1g-dev libxml2-dev libxslt1-dev libpq-dev libsqlite3-dev libssl-dev
cat > /etc/systemd/system/puma.service << 'EOF'
#{$puma_service}
EOF
cat > /etc/systemd/system/puma.socket << 'EOF'
#{$puma_socket}
EOF
systemctl daemon-reload
SCRIPT
$user_provision = <<SCRIPT
# install rbenv to /home/vagrant/.rbenv
RBENV_ROOT=/home/vagrant/.rbenv
PATH=$RBENV_ROOT/bin:$RBENV_ROOT/shims:$PATH
if [ -d "$RBENV_ROOT" ]; then
rbenv update
else
git clone https://github.com/rbenv/rbenv.git $RBENV_ROOT
git clone https://github.com/rbenv/ruby-build.git $RBENV_ROOT/plugins/ruby-build
git clone https://github.com/rkh/rbenv-update.git $RBENV_ROOT/plugins/rbenv-update
echo 'gem: --no-document' >> ~/.gemrc
fi
RUBY_VERSION=$(cat /vagrant/.ruby-version)
RUBY_MAJOR=${RUBY_VERSION%.*}.0
rbenv install $RUBY_VERSION
rbenv global $RUBY_VERSION
gem update --system
ln -sf /vagrant/.irbrc /home/vagrant/.irbrc
ln -sf $RUBY_VERSION /home/vagrant/.rbenv/versions/global
ln -sf $RUBY_MAJOR /home/vagrant/.rbenv/versions/global/lib/ruby/gems/version
cat > ~/rssbox.env << 'EOF'
#{$env}
EOF
cat >> ~/.bashrc << EOF
# Added by Vagrantfile
source ~/rssbox.env
EOF
source ~/rssbox.env
hash -r
cd /vagrant
bundle install --retry=3 --jobs=4
SCRIPT
Vagrant.configure("2") do |config|
config.vm.box = "debian/buster64"
config.vm.hostname = "rssbox"
config.vm.network "forwarded_port", guest: 3000, host: 3000
config.vm.provision "shell", inline: $root_provision
config.vm.provision "shell", inline: $user_provision, privileged: false
config.vm.provision "shell", inline: "systemctl start puma.socket puma.service", run: "always"
config.vm.post_up_message = <<EOF
Webserver should now be running at http://localhost:3000/
Please run 'vagrant ssh' and edit ~/rssbox.env, then run: sudo systemctl restart puma.service
EOF
end