Go & Gradle examples of hot reloading a binary #1244
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a research/discussion branch. Do not merge!
A prospective user messaged us on Slack looking for a workflow that would allow him to re-build Java/Gradle executables on code change, then hot reload them into a running container. He'd like to first deploy this container using Helm.
These are two examples on how to do that. One in Java, as requested, and one in Go. The Helm part is still to be done.
Some details:
code
exec module, where the source code is, and acontainer
container module, that gets hot-reloaded with the new binary whenevercode
changes.code
, there's amyscript.sh
script, which is called by theexec
type on code change. This script adds a timestamp to the source code indicating the exact moment when it was called, then builds a binary/artifact, and copies it to the container module.entr
re-runs it.About the Go version:
go mod vendor
.myscript.sh
being called, and the binary being executed (after that it listens on 8080 and does nothing). This is usually 1–4 seconds on my machine. It's worth noting that some large dependencies were added to the binary to simulate a real workload.About the Java version:
myscript.sh
was called, not the total between that and being executed like the Go version does.entr
would reload it once, and do nothing on any subsequent changes.cat
on bash). There's probably something Java-specific that I'm unaware of. As is, it works fine.Files worth looking:
garden.yml
sDockerfile
s inside thecontainer
modulesmyscript.sh
files in thecode
modulescode/main.go
for the Go one, andcode/src/main/java/hello/*.java
for Java.IMHO this could serve as a starting point for the Go module type, or for a plugin that does the general "build an artifact then hot reload it."
As @eysi09 mentioned, another solution is to simply have a
preSync
task onhotReload
. That is fine, but sometimes we'll want to have more fine-grained control—e.g. to automatically do the vendoring and whatnot with Go modules—as opposed to a generic type.So as plugins become a thing users write as opposed to just the core team, something like these examples would be a good template to have.
I'm looking for:
.garden/
, as outlined in Usability concerns with exec module #1243.