Allow to register shutdown hooks for containers terminated by Ryuk
Sometimes containers need to execute some shut down logic. In the code I can override a lifecycle method, something like containerIsStopping in Testcontainers-java for example and execute custom shutdown logic.
But if my containers are garbage collected by Ryuk, it's currently impossible (or very hard) to provide a shutdown logic.
I'd like to be able to register a shutdown hook for Ryuk, it can be as simple as enabling the behavior and Ryuk checking for a particular file path and running that file if exists before killing the container.
This will allow me:
- enable shutdown hooks in Ryuk
- copy the script with the shutdown logic into the container
- override the
containerIsStoppingwith calling the same file in the container
And my containers will clean up resources whether they are stopped by code or Ryuk.
Sometimes containers need to execute some shut down logic
Do you have examples?
But if my containers are garbage collected by Ryuk, it's currently impossible (or very hard) to provide a shutdown logic.
The idea is that Ryuk should kill containers, not gracefully stop them. Any graceful shutdown should be done explicitly in the tests. But maybe I am missing some valid use case?
@shelajev in tc-go there are PreTerminates and PostTerminate hooks, which are called in the Go test program. So if you are used to using ctr.Terminate(ctx) in your Go tests, then you benefit from using those hooks.
I agree with @bsideup here, as Ryuk is just the messenger 🤷
@shelajev I'm closing this as stale. You can still leverage the container lifecycle to execute those hooks. But please reopen if you still this as a valid use case.
Thanks!