Skip to content

Commit 527c30f

Browse files
authored
Devops tweaks in Vagrantfile and package.json (#43)
Make the following tweaks to the build system files (mostly `Vagrantfile`): - Forward port 9229 from the VM. This allows attaching a debugger to the Node server. - Add a corresponding `serve-debug` script, to run the server with debugging enabled. - Disable the redundant `/vagrant` sharefolder; we already share the relevant contents via `/cplayground`. - Run the provisioner which loads the cplayground kernel module every boot. This makes the development VM resilient against `vagrant halt` / `vagrant up`. It looks like the Node debugger has potential for [live reloading](https://www.jetbrains.com/help/webstorm/running-and-debugging-node-js.html#nodemon), which might be nice. (I have not investigated.) Disclaimer: I'm currently having issues attaching to the Node instance with this tweak. I think it's a me problem as I'm pretty sure I've used a config very like this successfully before, but it's probably worth testing.
1 parent 297a466 commit 527c30f

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

Vagrantfile

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@ Vagrant.configure("2") do |config|
1010
config.vm.box = "hashicorp/bionic64"
1111

1212
# Forward host port 3000 to guest port 3000. That way, if you navigate to
13-
# localhost:3000, it will load cplayground from the vm.
13+
# localhost:3000, it will load cplayground from the vm. Also forward the nodejs debug port.
1414
config.vm.network "forwarded_port", guest: 3000, host: 3000, host_ip: "127.0.0.1"
15+
config.vm.network "forwarded_port", guest: 9229, host: 9229, host_ip: "127.0.0.1"
1516

1617
# Mount ./ from the host (i.e. the cplayground directory) to /cplayground in
1718
# the vm
1819
config.vm.synced_folder "./", "/cplayground"
20+
config.vm.synced_folder "./", "/vagrant", disabled: true
1921

2022
# Provider-specific configuration so you can fine-tune various
2123
# backing providers for Vagrant. These expose provider-specific options.
@@ -93,8 +95,8 @@ Vagrant.configure("2") do |config|
9395
sudo -EHu vagrant ./build-all.sh
9496
SHELL
9597

96-
# Finish up with vagrant-specific vm prep
97-
config.vm.provision "shell", inline: <<-SHELL
98+
# Load cplayground kernel module - do this every boot
99+
config.vm.provision "shell", run: 'always', inline: <<-SHELL
98100
# Mount the kernel module
99101
echo -e "\e[96m""Mounting kernel module...""\e[0m"
100102
if lsmod | grep -q 'cplayground'; then
@@ -104,7 +106,10 @@ Vagrant.configure("2") do |config|
104106
cd /cplayground/src/server/kernel-mod
105107
sudo insmod cplayground.ko "file_uid=$(id -u vagrant)" "file_gid=$(id -g vagrant)"
106108
)
109+
SHELL
107110

111+
# Finish up with vagrant-specific vm prep
112+
config.vm.provision "shell", inline: <<-SHELL
108113
# Virtualbox shared folders don't support unix domain sockets (which we use
109114
# to communicate with gdb in the Docker containers). As a hack, we put the
110115
# data folder in the parent directory so that it's not in the shared

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@
4545
"build-client": "webpack",
4646
"build": "tsc && webpack",
4747
"watch-client": "webpack --watch",
48-
"serve": "tsc && node ./dist/server/index.js"
48+
"serve": "tsc && node ./dist/server/index.js",
49+
"serve-debug": "tsc && node --inspect ./dist/server/index.js"
4950
},
5051
"devDependencies": {
5152
"@svgr/webpack": "^5.3.0",

0 commit comments

Comments
 (0)