-
Notifications
You must be signed in to change notification settings - Fork 29
Description
In my port of a library into elixir, my reference implementations are written in node and rust (et al). Both use testcontainers. Now, there is two functions, that do not exist in elixir:
- Rust:
with_copy_to - Node:
withCopyContentToContainer()
This is semi-doable in elixir and in fact, the nginx container does it for testing:
| Docker.Api.put_file(container.container_id, conn, "/tmp", "foo.txt", "Hello foo bar") |
This was fine for me, to do it myself and not create a PR as an API is available... until I figured, there is a timing issue using it in after_build. I'm using it to create a file in combination with the with_cmd() to pass a parameter to point to that file and here is what happens:
- Create container
- Start container (with cmd)
- Run after build to provide the file
This crashes when starting the container with executing the cmd fails. It is expecting a file, that is about to be provided.
Checking the node and rust implementation, the order is different:
- Create container
- Provide the files
- Start container (with cmd)
... and that is how it works. I think to implement it in elixir, it would go in here:
testcontainers-elixir/lib/testcontainers.ex
Lines 368 to 377 in 644f5bd
| defp create_and_start_container(config, config_builder, state) do | |
| with :ok <- maybe_pull_image(config, state.conn), | |
| {:ok, id} <- Api.create_container(config, state.conn), | |
| :ok <- Api.start_container(id, state.conn), | |
| {:ok, container} <- Api.get_container(id, state.conn), | |
| :ok <- ContainerBuilder.after_start(config_builder, container, state.conn), | |
| :ok <- wait_for_container(container, config.wait_strategies || [], state.conn) do | |
| {:ok, container} | |
| end | |
| end |
between create_container and start_container.
Apparently, node has a couple of "provide files" API methods. I dunno, what the elixir variant would take.
Any suggestions for this?