cortesi / modd

A flexible developer tool that runs processes and responds to filesystem changes
MIT License
2.8k stars 128 forks source link

Question: Best practices for go module with multiple running cmds #98

Open flowchartsman opened 3 years ago

flowchartsman commented 3 years ago

About to start playing around with this project for development in containers with a project structured like so:

go.mod
go.sum
projectshared.go
sharedlib/
    sharedlib.go
cmd/
    cmd1/
        main.go
        anothercmd1file.go
    cmd2/
        main.go
        maybeanothercmd2file.go

I would like to just run both commands with daemon directives inside a shared container. If any of the shared code changes, I'd like to rebuild them both, but I'd only like to rebuild cmd1 if one of its files have changed and likewise for cmd2

Would I need to have blocks for each of them like the following (assuming I also wish to skip *_test.go files?

**/*.go !**/*_test.go !cmd/cmd2/**/*.go {
    indir: ./cmd/cmd1
    prep: go build
    daemon +sigterm: cmd1
}

**/*.go !**/*_test.go !cmd/cmd1/**/*.go {
    indir: ./cmd/cmd2
    prep: go build
    daemon +sigterm: cmd2
}

Would this work, or is there a better way? Perhaps by excluding cmd from the base container and then explicitly mounting the relevant command in each image.

flowchartsman commented 3 years ago

If I'm reading this right, another option that occurs is just rebuilding and terminating the daemon if root files are changed.

**/*.go !**/*_test.go !cmd/** {
    prep: //build cmd1
    prep: //build cmd2, etc
    prep: killall cmd1 cmd2
}

cmd/cmd1/**/*.go {
    prep: //build cmd1
    daemon +sigterm: cmd1
}

//and similarly for cmd2