Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
flowchartsman opened this issue Mar 26, 2021 · 1 comment
Open

Comments

@flowchartsman
Copy link

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
Copy link
Author

flowchartsman commented Mar 26, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant