Reputation: 33
I have the Docker container with Golang and Mongo. I want to make telegram bot, and I want to auto recompile/rerun my go application when I change source code. I tried to use mitranim/gow but it didn't work.
What I need to use for auto rerun my go application after change source code? I need anything seems nodemon for nodejs, but for go
Here my docker-compose and dockerfile configs.
My host machine is win10
Upvotes: 2
Views: 830
Reputation: 4731
Most file monitoring tools on Linux use as their preferred mechanism inotify. The tool you mentioned mitranim/gow seems to fall into the same category.
The issue is that a change to the filesystem in Windows does not cause the Linux guest to publish the event. This is kind of expected because Windows doesn't "know" a watch has been set, and therefore cannot notify the Linux container when a file has changed. It is a common problem for virtualized environments or other cross-platform / over-the-network file system sharing solutions.
There is similar issue you might want to have a look to: Inotify on shared drives does not work
A possible solution to the problem is to use polling. nodemon
has a legacyWatch
flag and can run any command when a file changes:
In some networked environments (such as a container running nodemon reading across a mounted drive), you will need to use the legacyWatch: true which enables Chokidar's polling.
Example:
nodemon --legacy-watch <working-dir> -e go --exec "go run main.go"
Or use nodemon
in combination with other monitoring tools by having nodemon
touching a file when it detects a file change (kind of a hack):
nodemon --legacy-watch <working-dir> -e go --exec "touch main.go"
Upvotes: 1