| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
|
I'm interested in this feature. But I see progress has been dropped. Is there a reason? |
Sorry, something went wrong.
The build is failing due to cython/cython#4568 I created #376 to fix it, but it hasn't been approved yet. |
Sorry, something went wrong.
|
Hey @mloesch, thanks for providing this PR for the feature. I see you decided to allow specifying a name for the Network. In Testcontainers for Java, we made the design decision to only generate networks with random names, to avoid the potential for naming conflicts with existing networks. This is a general design approach of Testcontainers and it should be fine for the Testcontainers use cases. Would you like to adapt the implementation accordingly? See https://github.com/testcontainers/testcontainers-java/blob/1a3b23385f9a595576246a4c7f5dc54d244dd69d/core/src/main/java/org/testcontainers/containers/Network.java for the Java implementation. |
Sorry, something went wrong.
Sorry, something went wrong.
There was a problem hiding this comment.
Thanks @mloesch, that change for the random id looks good. I did another pass and compared it with the implementation in tc-java (which I consider our reference implementation) and had some more suggestions.
I am still getting up to speed with the internals of tc-python, so we can discuss whether my suggestions make sense in this context.
Sorry, something went wrong.
|
|
||
| def test_containers_can_communicate_over_network(): | ||
| with Network() as network: | ||
| with DockerContainer("nginx:alpine-slim").with_name( |
There was a problem hiding this comment.
Instead of using with_name (which can lead to naming conflicts when parallelizing tests or accidentally reusing names), can we add an API with_network_aliases(string[]), similar to tc-java, that uses Docker's --network-alias mechanism?
Sorry, something went wrong.
Sorry, something went wrong.
| def test_containers_can_communicate_over_network(): | ||
| with Network() as network: | ||
| with DockerContainer("nginx:alpine-slim").with_name( | ||
| "alpine1").with_kwargs(network=network.name) as alpine1: |
There was a problem hiding this comment.
Does it make sense to use with_kwargs here and not have an explicit API with_network(Network)?
Sorry, something went wrong.
There was a problem hiding this comment.
👍 added in e4d9c19
Sorry, something went wrong.
|
@kiview is there anything else required for this PR to be merged? :) |
Sorry, something went wrong.
There was a problem hiding this comment.
I went through your PR now and have some final remarks that should be addressed before we are ready to merge. Very good work so far, this is feature is awesome! 🚀
Sorry, something went wrong.
| self._command = None | ||
| self._name = None | ||
| self._network: Optional[Network] = None | ||
| self._network_aliases: Optional[list] = None |
There was a problem hiding this comment.
Could you further specify the list to list[str]?
Sorry, something went wrong.
There was a problem hiding this comment.
fixed in cac19d3
Sorry, something went wrong.
| self.ports[port] = None | ||
| return self | ||
|
|
||
| def with_network(self, network: Network) -> "DockerContainer": |
There was a problem hiding this comment.
Latest version of this file has return type Self from typing_extensions for these methods. Could you sync it with main and update the signature to use Self?
Sorry, something went wrong.
There was a problem hiding this comment.
fixed in 1c8ebdc
Sorry, something went wrong.
| Network context manager for programmatically connecting containers. | ||
| """ | ||
|
|
||
| def __init__(self, docker_client_kw: Optional[dict] = None, **kwargs) -> None: |
There was a problem hiding this comment.
From an API users' point of view, it is not really clear what the kwargs arguments are meant for. Could you update the signature to be def __init__(self, docker_client_kw: Optional[dict] = None, docker_network_kw: Optional[dict] = None) -> None:?
Sorry, something went wrong.
There was a problem hiding this comment.
fixed in b392ca6
Sorry, something went wrong.
| def __exit__(self, exc_type, exc_val, exc_tb) -> None: | ||
| self.remove() | ||
|
|
||
| def __del__(self) -> None: |
There was a problem hiding this comment.
We've had some bad experiences with external resource cleanup through the __del__ method, so we have decided to move away from this. Having the context manager and the remove method provides sufficient means to cleanup the resource. __del__ hook can be removed 👍
Sorry, something went wrong.
There was a problem hiding this comment.
fixed in 8c8b6e2
Sorry, something went wrong.
| from testcontainers.core.docker_client import DockerClient | ||
| from testcontainers.core.network import Network | ||
|
|
||
| NGINX_ALPINE_SLIM_IMAGE = "nginx:alpine-slim" |
There was a problem hiding this comment.
Can you pin this dpenendency to a specific, versioned tag? We are currently working on making our tests more reproducible, and specific version tags for images used in tests are a part of this.
Sorry, something went wrong.
There was a problem hiding this comment.
fixed in 9db1080
Sorry, something went wrong.
…estcontainers#529) Changed pre-commit config. Some files became re-formatted.
…#366) Add support for a Vault container.
…ners#532) see testcontainers#531: I am using testcontainers within a library that provides some pytest-fixtures. In order for this to work I have change some settings. As I can not guarantee that that my lib is imported before testcontainers I need to monkeypatch the settings. This is much easier if I only need to monkeypatch the config file and not all modules that use configurations. I would argue that for a potential library as this, this is a better design. Also one can easier see that the given UPERCASE variable is not a constant but rather a setting. Co-authored-by: Carli* Freudenberg <carli.freudenberg@energymeteo.de>
🤖 I have created a release *beep* *boop* --- ## [4.3.2](testcontainers/testcontainers-python@testcontainers-v4.3.1...testcontainers-v4.3.2) (2024-04-08) ### Bug Fixes * **core:** Improve typing for common container usage scenarios ([testcontainers#523](testcontainers#523)) ([d5b8553](testcontainers@d5b8553)) * **core:** make config editable to avoid monkeypatching.1 ([testcontainers#532](testcontainers#532)) ([3be6da3](testcontainers@3be6da3)) * **vault:** add support for HashiCorp Vault container ([testcontainers#366](testcontainers#366)) ([1326278](testcontainers@1326278)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
|
Thank you for this @mloesch! 🙌 Really appreciate your contribution, this will benefit a lot of users 💯 |
Sorry, something went wrong.
🤖 I have created a release *beep* *boop* --- ## [4.4.0](testcontainers-v4.3.3...testcontainers-v4.4.0) (2024-04-17) ### Features * **labels:** Add common testcontainers labels ([#519](#519)) ([e04b7ac](e04b7ac)) * **network:** Add network context manager ([#367](#367)) ([11964de](11964de)) ### Bug Fixes * **core:** [#486](#486) for colima delay for port avail for connect ([#543](#543)) ([90bb780](90bb780)) * **core:** add TESTCONTAINERS_HOST_OVERRIDE as alternative to TC_HOST ([#384](#384)) ([8073874](8073874)) * **dependencies:** remove usage of `sqlalchemy` in DB extras. Add default wait timeout for `wait_for_logs` ([#525](#525)) ([fefb9d0](fefb9d0)) * tests for Kafka container running on ARM64 CPU ([#536](#536)) ([29b5179](29b5179)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
| Back | FazBrowse Home | New Git URL |
This PR adds a Network helper class that allows to create networks and connect containers programmatically.
The networks are context-managed resources like containers created via DockerContainer.
Please also see tests for a usage example :)