/ Vagrantfile
Vagrantfile
1 # -*- mode: ruby -*- 2 # vi: set ft=ruby : 3 4 Vagrant.configure("2") do |config| 5 # The most common configuration options are documented and commented below. 6 # For a complete reference, please see the online documentation at 7 # https://docs.vagrantup.com. 8 9 config.vm.box = "radicle_garden/gardener" 10 config.vm.box_version = "0.3.0" 11 12 # Create a forwarded port mapping which allows access to a specific port 13 # within the machine from a port on the host machine. In the example below, 14 # accessing "localhost:8080" will access port 80 on the guest machine. 15 # NOTE: This will enable public access to the opened port 16 # config.vm.network "forwarded_port", guest: 80, host: 8080 17 18 # Create a forwarded port mapping which allows access to a specific port 19 # within the machine from a port on the host machine and only allow access 20 # via 127.0.0.1 to disable public access 21 config.vm.network "forwarded_port", guest: 80, host: 3080, host_ip: "127.0.0.1", auto_correct: true 22 for i in 57000...57010 23 config.vm.network :forwarded_port, guest: i, host: i, host_ip: "127.0.0.1", auto_correct: true 24 end 25 config.vm.network "forwarded_port", guest: 5173, host: 5173, host_ip: "127.0.0.1", auto_correct: true 26 config.vm.network "forwarded_port", guest: 5432, host: 55432, host_ip: "127.0.0.1", auto_correct: true 27 config.vm.network "forwarded_port", guest: 9091, host: 9091, host_ip: "127.0.0.1", auto_correct: true 28 29 # Create a private network, which allows host-only access to the machine 30 # using a specific IP. 31 config.vm.network "private_network", ip: "192.168.33.10" 32 33 # Create a public network, which generally matched to bridged network. 34 # Bridged networks make the machine appear as another physical device on 35 # your network. 36 # config.vm.network "public_network" 37 38 # Share an additional folder to the guest VM. The first argument is 39 # the path on the host to the actual folder. The second argument is 40 # the path on the guest to mount the folder. And the optional third 41 # argument is a set of non-required options. 42 # config.vm.synced_folder ".", "/home/local/gardener", owner: "local", group: "local" 43 44 # Sync the project folder, but we'll handle node_modules separately 45 # to ensure correct architecture (Linux) dependencies 46 config.vm.synced_folder ".", "/vagrant", mount_options: ["dmode=775,fmode=775"] 47 48 # Create a VM-local node_modules and bind mount it into /vagrant 49 # This ensures native dependencies are built for Linux, not macOS 50 config.vm.provision "shell", privileged: true, run: "always", inline: <<-SHELL 51 # Create VM-local node_modules directory 52 mkdir -p /home/vagrant/node_modules_cache/garden-ui 53 chown vagrant:vagrant /home/vagrant/node_modules_cache/garden-ui 54 55 # Create mount point in /vagrant (needs to be a real directory for bind mount) 56 mkdir -p /vagrant/node_modules 57 58 # Bind mount the VM-local directory over /vagrant/node_modules 59 if ! mountpoint -q /vagrant/node_modules; then 60 mount --bind /home/vagrant/node_modules_cache/garden-ui /vagrant/node_modules 61 echo "node_modules bind-mounted from /home/vagrant/node_modules_cache/garden-ui" 62 else 63 echo "node_modules already mounted" 64 fi 65 66 SHELL 67 68 config.vm.provision "shell", privileged: true, run: "once", inline: <<-SHELL 69 # Create custom MOTD script 70 cat > /etc/update-motd.d/99-vagrant-info <<'EOF' 71 #!/bin/sh 72 cat <<'MOTD' 73 ┌─────────────────────────────────────────────────────────────────┐ 74 │ Radicle Gardener · Dev Environment │ 75 ├─────────────────────────────────────────────────────────────────┤ 76 │ tmux: │ 77 │ svelte dev tmux attach -t sveltekit │ 78 │ │ 79 │ detach Ctrl+b d │ 80 │ help Ctrl+b ? │ 81 │ copy Ctrl+b [ (scroll / select) │ 82 │ paste Ctrl+b ] │ 83 │ exit copy q │ 84 │ sessions tmux ls │ 85 │ │ 86 │ caddy: │ 87 │ restart sudo systemctl restart caddy │ 88 │ logs journalctl -f -u caddy │ 89 │ │ 90 │ podman: │ 91 │ ps podman ps │ 92 │ all podman container list --all │ 93 │ start podman container start <ID> │ 94 │ stop podman container stop <ID> │ 95 │ logs podman container logs <ID> │ 96 │ │ 97 │ postgres: │ 98 │ connect psql postgres://garden:garden@localhost:5432/garden │ 99 │ users select * from public.user; │ 100 │ nodes select * from public.node; │ 101 │ list \dt tables \di indexes \dv views \ds seq │ 102 │ inspect \d <table> │ 103 └─────────────────────────────────────────────────────────────────┘ 104 105 MOTD 106 EOF 107 chmod +x /etc/update-motd.d/99-vagrant-info 108 SHELL 109 110 config.vm.provision "shell", privileged: false, run: "always", inline: <<-SHELL 111 cd /vagrant 112 pnpm install 113 pnpm db:migrate 114 # Start the dev server (log to file and tmux session) 115 tmux new-session -d -s "sveltekit" "pnpm dev 2>&1 | tee /vagrant/sveltekit.log" 116 SHELL 117 118 # Provider-specific configuration so you can fine-tune various 119 # backing providers for Vagrant. These expose provider-specific options. 120 # Example for VirtualBox: 121 # 122 config.vm.provider "virtualbox" do |vb| 123 # # Display the VirtualBox GUI when booting the machine 124 # vb.gui = true 125 # 126 # # Customize the amount of memory on the VM: 127 vb.memory = "8192" 128 vb.cpus = 6 129 end 130 131 # Post-up message 132 config.vm.post_up_message = <<-MSG 133 ┌──────────────────────────────────────────────┐ 134 │ Radicle Gardener · Dev Environment │ 135 ├────────────────────────────────────────────────┤ 136 │ VM IP: 192.168.33.10 │ 137 │ SSH: vagrant ssh │ 138 │ Logs: tail -f sveltekit.log │ 139 │ Dev Server: http://localhost:5173 (*) │ 140 │ Ports: (*) use `vagrant port` to verify │ 141 │ Clean: pnpm clean │ 142 └────────────────────────────────────────────────┘ 143 MSG 144 end