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

Supply compose file context to callbacks #54

Open
LtChae opened this issue Aug 3, 2022 · 2 comments
Open

Supply compose file context to callbacks #54

LtChae opened this issue Aug 3, 2022 · 2 comments
Labels
enhancement New feature or request

Comments

@LtChae
Copy link
Contributor

LtChae commented Aug 3, 2022

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.

divo/lib/divo.ex

Lines 30 to 40 in 9fccc40

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)
Enum.each(post_docker_run, & &1.())
app = Mix.Project.config() |> Keyword.get(:app)
if auto_start, do: Application.ensure_all_started(app)
end

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
@LtChae LtChae added the enhancement New feature or request label Aug 3, 2022
@jdenen
Copy link
Contributor

jdenen commented Aug 3, 2022

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)

@LtChae
Copy link
Contributor Author

LtChae commented Aug 4, 2022

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.

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

No branches or pull requests

2 participants