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

Allow configuration on container if it should be automatically cleaned up #850

Open
cbrevik opened this issue Oct 25, 2024 · 2 comments
Open
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@cbrevik
Copy link
Contributor

cbrevik commented Oct 25, 2024

In reference to #849 (comment) I'd like to be able to override the default behaviour where a container is cleaned up when it is stopped.

What I suggest is adding a new function on GenericContainer:

  • withRemoveWhenStopped(removeWhenStopped: boolean)

So the default behaviour is still that the container is removed when you call container.stop(). But to override you can explicitly configure it with .withRemoveWhenStopped(false) when creating the container. It should probably still be possible to override the configured value by options container.stop({ remove: true }).

It also made sense to me that you'd to be able to configure withAutoRemove(autoRemove: boolean), so if the container is stopped in other ways than via the testcontainers-node API it is also cleaned up.

I've taken a stab at adding both withRemoveWhenStopped and withAutoRemove here (including tests): main...cbrevik:testcontainers-node:support-configured-auto-remove

@cristianrgreco
Copy link
Collaborator

@cbrevik Could you add some info why the logic for adding withRemoveWhenStopped and withAutoRemove cannot just be put in the container.stop({ ... }). IMO having the same option in 2 places, with one overriding the other is confusing

@cristianrgreco cristianrgreco added the enhancement New feature or request label Nov 15, 2024
@cbrevik
Copy link
Contributor Author

cbrevik commented Nov 15, 2024

The main use case for me would be if I enable withReuse() on a container, I normally don't want it to be removed when stopped. So it made sense to me that I could configure that "in the same place" as I configure re-use.

In other words something like:

const container = await new PostgreSqlContainer()
    .withReuse()
    .withRemove(false)
    .start()

Or something like that. I normally "pass" the container somewhere else, and then I have to remember to call container.stop({ remove: false }) in the other module.

It's not a huge deal though, just made sense that it would be configureable somehow to me.

@cristianrgreco cristianrgreco added the good first issue Good for newcomers label Nov 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants