githubnemo / CompileDaemon

Very simple compile daemon for Go
BSD 2-Clause "Simplified" License
1.63k stars 155 forks source link

Additional arguments in build don't work #63

Closed bplociennik closed 3 years ago

bplociennik commented 3 years ago

I'm using CompileDeamon in my Dockerfile. I was using this command to only rebuild my app after changes: CMD swag init -d src && CompileDaemon --build="go build src/main.go" --command="./main" --color

but I wanted to add also hot reloading with swagger recompile like: CMD swag init -d src && CompileDaemon --build="swag init -d src && go build src/main.go" --command="./main" --color

and it not working correctly. When I run my docker-compose then this container starts rebuilding every second without any change in files. I discovered that the problem is with an additional flag added to swag init.

When I remove -d src then CompileDeamon is not rebuilding the app without a change in code (correct behavior), so I think it's something wrong with interpreting command arguments.

It's problematic for me because of the project structure and I have to specify a directory for swag to compile it correctly :)

PS. Thanks for your work, CompileDeamon is great :D

githubnemo commented 3 years ago

Firstly, I presume that swag generates .go files and these will stop/retrigger the build? You could try excluding the generated files from being watched using the --exclude flag.

Secondly, CompileDaemon does not launch a shell and only a shell is able to interpret the && directive. The correct way to call this would be to write a build.sh which contains the build commands that are necessary to build the software and that gets called by CompileDaemon:

 CMD swag init -d src && CompileDaemon --build="./build.sh" --command="./main" --color
#!/bin/sh
swag init -d src
go build src

Does this help?

bplociennik commented 3 years ago

it's working perfectly now :) I totally forgot that after rebuilding docs swag also generates a go file and it was a reason for this infinity loop.

CMD swag init --dir src && CompileDaemon --exclude-dir="docs" --build="./docker/build.sh" --command="./main" --color
#!/bin/sh
swag init -d src
go build src/main.go

thank you @githubnemo for your help with that :100: