Supply compose file context to callbacks
Currently, Divo supports callbacks during the setup block that allow for code to be executed between the environment starting and the app's individual applications starting up.
https://github.com/UrbanOS-Public/divo/blob/9fccc400dcc64142698061b3da2a67e7828829e3/lib/divo.ex#L30-L40
I would like to propose passing the compose file's context to each callback to allow them access to ports and volume mount points for setup calls.
def start(opts \\ []) do
auto_start = Keyword.get(opts, :auto_start, true)
post_docker_run = Keyword.get(opts, :post_docker_run, [])
Divo.Compose.run(opts)
context = Helper.fetch_config()
|> Helper.get_context()
Enum.each(post_docker_run, fn callback -> callback(context) end)
app = Mix.Project.config() |> Keyword.get(:app)
if auto_start, do: Application.ensure_all_started(app)
end
I'd suggest checking arity and passing the context based on that, so you don't break backwards compatibility. Also, it's just generally more flexible, which is always a win for a library IMO.
Enum.each(post_docker_run, fn
callback when is_function(callback, 1) -> callback.(context)
callback when is_function(callback, 0) -> callback.()
end)
Good call, thanks!
We ran into a need for this when cleaning and populating Minio's fake S3 buckets prior to a test. We're doing it with a slightly hacky init container and a shell script, and this seemed like a possible solution to keeping test setup in the tests themselves.