Skip to content

Allow .testcontainers.properties from classpath #3780

Description

@kodyrecords

I would be great if .testcontainers.properties would be detected simply from classpath.

With that, the reuse option could be simply applied to all test databases at once.

It's somewhat problematic that the global reuse has to be enabled from home directory.
Because if one of my team mates checks out the project, it should be entirely configured, without having to read the some docs and eventually notice that everyone has to add his own .testcontainers property in his home path for getting the same test performance.

Activity

  1. bsideup commented on Feb 9, 2021

    @bsideup
    Member

    Duplicate of many reports, see the last answer in #3707.

  2. kodyrecords commented on Feb 9, 2021

    @kodyrecords
    Author

    @bsideup how does your answer regarding TESTCONTAINERS_RYUK_DISABLED does have anything to do with my question about the .testcontainers.properties classpath file???

  3. bsideup commented on Feb 9, 2021

    @bsideup
    Member

    @membersound there are certain configuration options that are per environment, not per project.
    Enabling reuse per project would also enable it on CIs. Most probably not something that you want.

    See #1781 (comment)

  4. kodyrecords commented on Feb 9, 2021

    @kodyrecords
    Author

    Well then probably the docs are wrong, which state it is actually possible?

    https://www.testcontainers.org/features/configuration/

    1. testcontainers.properties on the classpath.
  5. bsideup commented on Feb 9, 2021

    @bsideup
    Member

    @membersound there is nothing wrong about it. Per-project configuration can be placed in testcontainers.properties file on classpath.

  6. kodyrecords commented on Feb 9, 2021

    @kodyrecords
    Author

    Well but if I put testcontainers.reuse.enable=true into /src/main/resources/testcontainers.properties and enable reuse with jdbc:tc:mariadb:10.5.8:///test?TC_REUSABLE=true, I just get a warning the that reuse will not be enabled because it is missing in ~/.testcontainer.properties.

    Doesn't that contradict it?

  7. bsideup commented on Feb 9, 2021

    @bsideup
    Member

    No, it does not, since testcontainers.reuse.enable is not a per-project configuration option, but per-environment.

  8. kodyrecords commented on Feb 9, 2021

    @kodyrecords
    Author

    Okay, is there any overview which properties are per-project, and which are per-env?

  9. bsideup commented on Feb 9, 2021

    @bsideup
    Member

    @membersound TestcontainersConfiguration is the most up-to-date source of information:

  10. kodyrecords commented on Feb 10, 2021

    @kodyrecords
    Author

    You could maybe think about adding that to the docs explicit to directly gather which vars could be used from classpath.
    I bet hardly anybody will look at the sourcecode in question...

  11. bsideup commented on Feb 10, 2021

    @bsideup
    Member

    @membersound the thing is, checks.disable and testcontainers.reuse.enable are two exceptions to the rule of "any var can be configured with the classpath file", as they are considered advanced optimization techniques (and reuse mode even being a preview feature, not a stable solution). When it comes to advanced stuff, some level of research is expected.

  12. frankiedrake commented on May 10, 2022

    @frankiedrake

    What about
    TestcontainersConfiguration.getInstance().updateUserConfig("testcontainers.reuse.enable", "true");?

  13. hector-meza commented on Jun 6, 2022

    @hector-meza

    What about TestcontainersConfiguration.getInstance().updateUserConfig("testcontainers.reuse.enable", "true");?

    Thank you so much. My team was ready to discontinue the use of TestContainers in favor of "old-school" compose files due to this issue and the configuration you provided helped me make it work.

  14. frankiedrake commented on Jun 7, 2022

    @frankiedrake

    What about TestcontainersConfiguration.getInstance().updateUserConfig("testcontainers.reuse.enable", "true");?

    Thank you so much. My team was ready to discontinue the use of TestContainers in favor of "old-school" compose files due to this issue and the configuration you provided helped me make it work.

    I'm happy this workaround is useful for you!

  15. luispollo commented on Aug 21, 2023

    @luispollo

    I understand the motivations for closing this and other linked issues, but I just wanted to add that, in our case, we actually want to enable container reuse both in local builds and in CI (our use case is to run DB migrations and some codegen that depends on those migrations in the same container), but as you might expect I don't (nor should I) have access to modifying that user-level file in the CI server, and so I'm stuck.

    Personally, I think that it'd be great to give people the option to choose how they set this up. If they want to set it up at the project level, even if discouraged for the common case, why prevent them from doing so? Also, it's not like enabling reuse has an immediate effect since you still need to explicitly turn it on when launching test containers (e.g. via the TC_REUSABLE=true JDBC URL flag), so I don't quite understand the concern.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions