Discourse plugin development symlink not working in vagrant / virtualbox


#1

Try to set up discourse development environment on a Mac OS following the official step-by-step. However, I encountered the following problem.

Problem: symlink created in host (Mac) is broken in guest OS (vagrant / virtualbox)

On official discourse Beginner’s Guide to Creating Discourse Plugins Part 4: Git Setup:

Creating a symlink

Because you followed our developer guide14 you should have a copy of discourse checked out on your computer somewhere. I checked mine out to ~/code/discourse but again you could have put it anywhere and this should still work if you adjust the following code accordingly:

cd ~/code/discourse/plugins ln -s ~/code/discourse-plugin-test .

The above code created a symbolic link5 between your discourse code and your plugin folder. Restart your rails server and you should find your plugin is working!

The beauty of this setup is you can just check your plugin into github and not worry about the discourse codebase it lives inside. Your changes will be isolated to the plugin itself. If you need to edit discourse’s code you still can, but git will track the changes separately!

I recommend using one editor window for your plugin codebase and one for Discourse itself. It is easier when you think of them as two different things.

While the symlink was successfully created in Mac, when I ran the following commands
vagrant up vagrant ssh cd /vagrant/plugins ls

The symlink is broken as shown by red text highlighted in black in the Mac terminal. As a result, the plugin is not showing up when I navigate to http://localhost:4000/admin/plugins In other words, the vagrant / virtualbox guest OS is not able to link the folder in the host Mac OS.

Solution: edit vagrantfile to set up synced folder

The temporary solution I use since I was not able to find any existing solution online: add the following line directly under config.vm.synced_folder ".", "/vagrant", id: "vagrant-root"

config.vm.synced_folder "../discourse-plugin-test", "/vagrant/plugins/discourse-plugin-test", id: "discourse-plugin-test"

“…/discourse-plugin-test” is the relative path to the actual plugin folder on Mac OS while “/vagrant/plugins/discourse-plugin-test” is the path I want to map / symbolic link in the Guest OS.

This temporary solution is not ideal as vagrantfile is located in the discourse git repo on Mac which means that whenever the repo is updated / synced to the GitHub latest version the edited vagrantfile will be overwritten by the official vagrantfile

If you have a better solution please share below. Thanks.