Vagrant + Virtualbox + nginx serves outdated files
Summary
Permission errors when running ./scripts/build-assets and nginx serving cached static files in Vagrant setup.
Steps to reproduce
Install the foodsharing dev environment with the vagrant setup.
What is the current bug behavior?
When running ./scripts/build-assets in the vagrant environment, permission errors come up for file_put_contents. After setting the permissions of all files and folders to 777, this error ceases, but nginx still serves old versions of static files, for example CHANGELOG.md
What is the expected correct behavior?
Any changes made to the files should be reflected in the served website on the dev environment immediately.
Possible fixes
The permissions error is easy to get rid of by setting the permission of the vagrant mounted shared folder to 777. Since these permissions are not propagated to the host system (macOS) where git is run, these permission settings have no impact on anything but the local dev server running in virtualbox. The files on the vagrant host keep their original permissions and git does not push any permission changes.
For the permissions issue replacing
config.vm.synced_folder ".", "/vagrant", owner: "www-data"
in the Vagrantfile with
config.vm.synced_folder ".", "/vagrant", owner: "www-data", :mount_options => ["dmode=777","fmode=777"]
is a possible fix, although 777 is bad practice, it works and in this case I don't see any security issues that would prohibit this solution.
However, even after fixing any permission problems, the nginx server still serves outdated css files that have since been changed by build-assets. The changes are reflected in both macOS and virtualbox environments, so it seems nginx is caching them somewhere in memory. This is even true for static files like CHANGELOG.md
This is actually a known bug of running nginx in virtualbox and the fix for this that is proposed is setting sendfile off in the development environment. Since nginx is running in a docker image I could not try this solution, but found another workaround that involves running
watch -n 1 'sync; sudo sh -c "/bin/echo 3 > /proc/sys/vm/drop_caches"'
inside the vagrant environment, optionally in a screen session. This workaround works for me and should also work for anyone else running the vagrant setup.