Tuesday, February 9, 2021

Dev environment in GitHub (Not codespaces)

After scripting my dev machine setup, naturally, my next aim became scripting specific application environments. Below are some reasons

Why we need to script out per application environment?

  • Different applications require different SDK versions, prerequisites. Making sure all apps are using the same version is time-consuming. 
  • Setting up the environment for one app to run may make another app fail.

The obvious answer I came to is containerization. The next question is where to run the container. It is GitHub codespaces. But it requires an invitation or we would be in the queue. So the next place is my own machine.

Solution

Finally ended up following multiple blog posts mentioned in references and reached to get it working. First I made my Hugo based personal website containerized. Below is the link to 2 files that are required to containerize.

https://github.com/joymon/site-hugo/tree/master/.devcontainer

One easy thing now in VS Code is an extension called "Remote Development" that packs multiple extensions required to run dev containers.

Hot reload / live-reload issue when using WSL2 backed containers in Windows

The problem I faced with this is the hot reload/live-reload is not working by just following the tutorials. This seems a known issue. One of the answers I have seen is to keep the file also in the Linux system. Another workaround people are suggesting is to use WSL1. 2 more are there. One to increase "fs.inotify.max_user_watches" property and the last one to use polling instead of subscribing to events to do hot reload.

More details can be found in the official documentation below.

https://docs.docker.com/docker-for-windows/wsl/#best-practices

https://docs.microsoft.com/en-us/windows/wsl/compare-versions#performance-across-os-file-systems

I am yet to test all those workarounds.

References

https://www.freecodecamp.org/news/put-your-dev-env-in-github/
https://markmcgookin.com/2020/11/12/vscode-devcontainer-using-dotnet5-0-net-5/

No comments: