Skip to content

Add CustomContainer exposing settings through the class#238

Closed
vikahl wants to merge 5 commits into
testcontainers:mainfrom
vikahl:new-generic-container
Closed

Add CustomContainer exposing settings through the class#238
vikahl wants to merge 5 commits into
testcontainers:mainfrom
vikahl:new-generic-container

Conversation

@vikahl

@vikahl vikahl commented Aug 25, 2022

Copy link
Copy Markdown

Add a CustomContainer exposing the settings through the class.

Close #236

@vikahl vikahl changed the title Add pyenv file to gitignore Add CustomContainer exposing settings through the class Aug 25, 2022
@vikahl vikahl marked this pull request as ready for review August 25, 2022 13:34
@tillahoffmann

Copy link
Copy Markdown
Contributor

Great, thank you! Slight misunderstanding: I was thinking that we could add this functionality to existing containers rather than create a new one. What do you think?

@vikahl

vikahl commented Aug 25, 2022

Copy link
Copy Markdown
Author

Great, thank you! Slight misunderstanding: I was thinking that we could add this functionality to existing containers rather than create a new one. What do you think?

I don't there is any current class (except for the deprecated TestContainer, but probably best to not touch it) that allows specifying the image name. I build the service image prior to tests so I have e.g., my-service:version1 as an image and want to manually specify that.

@tillahoffmann

Copy link
Copy Markdown
Contributor

The image name can be specified for DockerContainer here.

class DockerContainer(object):
def __init__(self, image, docker_client_kw: dict = None, **kwargs):

@vikahl

vikahl commented Aug 25, 2022

Copy link
Copy Markdown
Author

The image name can be specified for DockerContainer here.

class DockerContainer(object):
def __init__(self, image, docker_client_kw: dict = None, **kwargs):

True, you have a point there.

Just to clarify, do you suggest extending the __init__ method of DockerContainer or all the db-containers?

I think the DockerContainer approach would be convenient and won't require a new class. I can test the approach tomorrow and see if it would impact existing implementations.

@tillahoffmann

Copy link
Copy Markdown
Contributor

Just to clarify, do you suggest extending the init method of DockerContainer or all the db-containers?

I was thinking all the containers as they all inherit from DockerContainer. That would give us a consistent interface across the whole library.

@vikahl

vikahl commented Mar 16, 2023

Copy link
Copy Markdown
Author

Just to clarify, do you suggest extending the init method of DockerContainer or all the db-containers?

I was thinking all the containers as they all inherit from DockerContainer. That would give us a consistent interface across the whole library.

Ah, good thought. Sorry for not picking up on this but I'll update the PR.

@vikahl vikahl force-pushed the new-generic-container branch from 6e3291a to 8622477 Compare March 22, 2023 19:56
@vikahl

vikahl commented Mar 22, 2023

Copy link
Copy Markdown
Author

@tillahoffmann updated the PR to instead set these in the core container's __init__. Do you think this looks reasonable?

If so, I'll make sure these changes are covered by tests as well.

@gaby

gaby commented Jun 8, 2023

Copy link
Copy Markdown

Ping @tillahoffmann this is another great PR

@tillahoffmann tillahoffmann left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, I left a few small comments. If you could add tests, that'd be great! 🙏

Comment thread core/testcontainers/core/container.py Outdated
Comment thread core/testcontainers/core/container.py Outdated
@vikahl

vikahl commented Jun 9, 2023

Copy link
Copy Markdown
Author

Will take a look and add tests and do the updates when I am back at a computer (might take a few weeks)

@vikahl vikahl force-pushed the new-generic-container branch from ac8b58f to 2c4eb3b Compare June 27, 2023 14:39
vikahl added 2 commits June 27, 2023 19:13
Add test that tests that attributes can be set through the __init__
function and later read through class attr.

This test does not test that the attributes has an actual effect, in the
future it might be of interest to test the integration to the docker
container and ensure that class attributes are propagated properly.
@vikahl

vikahl commented Jun 27, 2023

Copy link
Copy Markdown
Author

@tillahoffmann please take a look at the tests.

I added test that tests that attributes can be set through the init function and later read through class attr.

The test does not test that the attributes has an actual effect, in the future it might be of interest to test the integration to the docker container and ensure that class attributes are propagated properly. However, I for the changes in this PR I think the current is good enough.

@vikahl vikahl requested a review from tillahoffmann October 8, 2023 18:46
@rhoban13

rhoban13 commented Apr 2, 2025

Copy link
Copy Markdown
Contributor

This PR seems to have stalled, but is a really good idea. What do we need to do to get it over the finish line?

self.env = {}
self.ports = {}
self.volumes = {}
def __init__(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we do the same with network and network_aliases? I suspect we need to rebase this PR in order to pickup these attributes.

@vikahl

vikahl commented Apr 2, 2025

Copy link
Copy Markdown
Author

This PR seems to have stalled, but is a really good idea. What do we need to do to get it over the finish line?

It's been a while, but it's still a feature I would like to have (now I use a CustomContainer in my code base that does this).
The package code has changed a bit, but I will take a look at either rebase/merge the changes or just redo them on an updated master.

@rhoban13

Copy link
Copy Markdown
Contributor

This PR seems to have stalled, but is a really good idea. What do we need to do to get it over the finish line?

It's been a while, but it's still a feature I would like to have (now I use a CustomContainer in my code base that does this). The package code has changed a bit, but I will take a look at either rebase/merge the changes or just redo them on an updated master.

Let me know if I can help - I can attempt a rebase and PR your branch or honestly your idea of just resubmitting might be just as easy.

@Tranquility2

Tranquility2 commented Apr 11, 2025

Copy link
Copy Markdown
Contributor

Hi @vikahl and @rhoban13, we had this talk or similar notion/idea on #559, we ended up with https://github.com/testcontainers/testcontainers-python/blob/main/modules/generic/testcontainers/generic/server.py which emphasis the notion to do custom stuff as a module (outside of core).
We also added the ability to utilize custom images as part of this track.
This can be improved of course (but in the module context) so hopefully it works for your use case and if not we can think how to extend it :)

@rhoban13

Copy link
Copy Markdown
Contributor

I might suggest resubmitting this PR separately as the original intent sounds just like the ServerContainer which @Tranquility2 linked above. The current state of this PR is simply making the initializer of DockerContainer accept it's private members as kwargs.

@rhoban13

rhoban13 commented May 6, 2025

Copy link
Copy Markdown
Contributor

I resubmitted as the above PR on an updated branch in hopes of getting it landed. I'm not sure who I need to reach out to to kick off the validations and get a review.

@alexanderankin

Copy link
Copy Markdown
Member

prefer #809 but will leave both open until i have time to review + merge

@vikahl

vikahl commented May 6, 2025

Copy link
Copy Markdown
Author

@rhoban13 thank you. I never got around to do it so happy that you did.

I'm leaving this PR open to be closed by the repo maintainers but #809 is a better/newer implementation of the idea behind this PR.

@vikahl vikahl closed this May 28, 2025
alexanderankin added a commit that referenced this pull request May 29, 2025
…args (#809)

Re submitting what is the end result of the iterations in
#238
submitted originally by @vikhal.

Simply enabling the initializer of `DockerContainer` to accept its
private members as kwargs.

---------

Co-authored-by: David Ankin <daveankin@gmail.com>
terry-docker added a commit to terry-docker/testcontainers-python that referenced this pull request Jun 17, 2025
…args (testcontainers#809)

Re submitting what is the end result of the iterations in
testcontainers#238
submitted originally by @vikhal.

Simply enabling the initializer of `DockerContainer` to accept its
private members as kwargs.

---------

Co-authored-by: David Ankin <daveankin@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Provide generic DockerContainer with init attributes

6 participants