Skip to content

Copy contents into the container #240

@gossi

Description

@gossi

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:

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:

  1. Create container
  2. Start container (with cmd)
  3. 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:

  1. Create container
  2. Provide the files
  3. Start container (with cmd)

... and that is how it works. I think to implement it in elixir, it would go in here:

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions