testcontainers / testcontainers-elixir

Testcontainers is an Elixir library that supports ExUnit tests, providing lightweight, throwaway instances of common databases, Selenium web browsers, or anything else that can run in a Docker container.
MIT License
104 stars 17 forks source link

Error when executing postgis image #106

Closed joaodubas closed 2 months ago

joaodubas commented 3 months ago

I configured testcontainers on one of my projects that uses postgres with the postgis extension enabled. When I try to execute the tests, I receive this message:

23:10:57.225 [error] Task #PID<0.488.0> started from Testcontainers terminating
** (ArgumentError) Image postgis/postgis:16-3.4-alpine is not compatible with postgres
    (testcontainers 1.8.1) lib/container/postgres_container.ex:192: Testcontainers.ContainerBuilder.Testcontainers.PostgresContainer.build/1
    (testcontainers 1.8.1) lib/testcontainers.ex:226: Testcontainers.start_and_wait/2
    (testcontainers 1.8.1) lib/testcontainers.ex:132: anonymous fn/3 in Testcontainers.handle_call/3
    (elixir 1.16.3) lib/task/supervised.ex:101: Task.Supervised.invoke_mfa/2
    (elixir 1.16.3) lib/task/supervised.ex:36: Task.Supervised.reply/4
Function: #Function<1.102782053/0 in Testcontainers.handle_call/3>
    Args: []

As you can see, I'm using the image postgis/postgis on the tests. Howerver there is a validation that prevents executing images other than the official postgres.

In this case, what would be best solution:

  1. Open a PR, allowing alternative images to be run
  2. Implement my own container, based on Testcontainers.Postgrescontainer
jarlah commented 3 months ago

I don't think there is much difference, in basic usage, between the two. So if you make a PR that either

  1. Changes the validation of the postgres container to also include postgis (meh ...)
  2. Make a method that disables image validation by setting a boolean field, similar to the other methods that sets config fields (maybe a good solution)

Then I could look into it.

joaodubas commented 3 months ago

Thanks for the suggestions. I'm looking into the best approach to turn off the image validation with a control field.

joaodubas commented 2 months ago

Thanks for all the help. With the release of 1.8.3, I can execute the postgis database using the Testcontainers.PostgresContainer implementation. I adjusted my application.ex with:

    if Application.get_env(:testcontainers, :enabled, false) do
      {:ok, _container} =
        Testcontainers.Ecto.postgres_container(
          app: :foundation,
          image: "postgis/postgis:16-3.4-alpine",
          check_image: "postgis/postgis"
        )
    end