-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVagrantfile
More file actions
79 lines (60 loc) · 2.52 KB
/
Copy pathVagrantfile
File metadata and controls
79 lines (60 loc) · 2.52 KB
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
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
# Debian 12 (Bookworm) — minimal, lightweight official box
config.vm.box = "debian/bookworm64"
config.vm.hostname = "base-rails"
# Shared folder: current project directory → /vagrant inside the VM
config.vm.synced_folder ".", "/vagrant", type: "virtualbox"
config.vm.provider "virtualbox" do |vb|
vb.name = "base-rails"
vb.memory = "1024"
vb.cpus = 2
# Headless — no GUI
vb.gui = false
end
# ── Port forwarding for ex03 Rails server ───────────────────────────────
config.vm.network "forwarded_port", guest: 3000, host: 3000
# ── Step 1: Ruby via rbenv ───────────────────────────────────────────────
config.vm.provision "shell", name: "ruby", privileged: false, inline: <<-SHELL
set -e
sudo hwclock --hctosys 2>/dev/null || true
echo "==> Updating package list..."
sudo apt-get update -qq
echo "==> Installing build dependencies..."
sudo apt-get install -y -qq \
git curl build-essential libssl-dev libreadline-dev \
zlib1g-dev libyaml-dev libffi-dev libsqlite3-dev sqlite3 tree \
libxml2-dev libxslt1-dev
# Install rbenv
if [ ! -d "$HOME/.rbenv" ]; then
echo "==> Installing rbenv..."
git clone --depth=1 https://github.com/rbenv/rbenv.git ~/.rbenv
git clone --depth=1 https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
fi
# Add rbenv to PATH in .bashrc
if ! grep -q 'rbenv' ~/.bashrc; then
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
fi
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
RUBY_VERSION="3.3.6"
if ! rbenv versions | grep -q "$RUBY_VERSION"; then
echo "==> Installing Ruby $RUBY_VERSION (this may take a few minutes)..."
rbenv install "$RUBY_VERSION"
fi
rbenv global "$RUBY_VERSION"
echo "==> Ruby $(ruby --version) ready."
# Bundler
gem install bundler --no-document -q
echo "==> Ruby provisioning complete. Project files are at /vagrant"
# install Ruby on Rails gem
if ! gem list rails | grep -q "^rails "; then
echo "==> Installing Rails gem..."
gem install rails --no-document
rbenv rehash # to update the gems
fi
echo "==> Rails $(rails --version) installed."
SHELL
end