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

feat: reusable containers #1

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
a933873
feat: reusable containers
matthiasschaub Jul 2, 2024
f0e2bc7
docs: add documentation about reusable containers
matthiasschaub Jul 3, 2024
08e33ba
test: additional testcase for reusable containers
matthiasschaub Jul 3, 2024
d2a83bc
test: add newlines for better readability
matthiasschaub Jul 3, 2024
c781606
warn user if ryuk is disabled but with_reuse used
matthiasschaub Jul 3, 2024
dd429e7
docs: fix code highlighting
matthiasschaub Jul 3, 2024
e87e782
fix: use Union instead of | for type hint
matthiasschaub Jul 7, 2024
c656660
refactor: remove TODO comment
matthiasschaub Jul 8, 2024
efb1265
docs: update section on reusable containers
matthiasschaub Jul 8, 2024
d4445d6
feat(reuse): do not change contract of stop method
matthiasschaub Aug 2, 2024
1ea9ed1
feat(reuse): do not create Ryuk cleanup instance
matthiasschaub Aug 2, 2024
ea6fec7
refactor: move hash generation into if clause
matthiasschaub Aug 3, 2024
7c1e8e7
Merge remote-tracking branch 'origin/main' into reusable_containers
matthiasschaub Dec 30, 2024
78b137c
fix: milvus healthcheck: use correct requests errors (#759)
alexanderankin Jan 21, 2025
9317736
chore(main): release testcontainers 4.9.1 (#748)
github-actions[bot] Jan 21, 2025
3e783a8
fix(core): multiple container start invocations with custom labels (#…
neykov Feb 11, 2025
f0bb0f5
docs: Fixed typo in CONTRIBUTING.md (#767)
max-pfeiffer Feb 11, 2025
b1642e9
fix(keycloak): Fixed Keycloak testcontainer for latest version v26.1.…
max-pfeiffer Feb 11, 2025
2113561
Merge branch 'main' into reusable_containers
matthiasschaub Feb 12, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Merge remote-tracking branch 'origin/main' into reusable_containers
  • Loading branch information
matthiasschaub committed Dec 30, 2024
commit 7c1e8e7863f0c4cab9be55386ca61773991a2074
3 changes: 1 addition & 2 deletions core/testcontainers/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,7 @@ def tc_properties_testcontainers_reuse_enable(self) -> bool:
enabled = self.tc_properties.get("testcontainers.reuse.enable")
return enabled == "true"

@property
def timeout(self):
def timeout(self) -> int:
return self.max_tries * self.sleep_time


Expand Down
20 changes: 17 additions & 3 deletions core/testcontainers/core/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import hashlib
import logging
from platform import system
from os import PathLike
from socket import socket
from typing import TYPE_CHECKING, Optional, Union

Expand Down Expand Up @@ -109,6 +110,17 @@ def start(self) -> Self:
logger.info("Pulling image %s", self.image)
self._configure()

network_kwargs = (
{
"network": self._network.name,
"networking_config": {
self._network.name: EndpointConfig(version.__version__, aliases=self._network_aliases)
},
}
if self._network
else {}
)

if self._reuse and not c.tc_properties_testcontainers_reuse_enable:
logging.warning(
"Reuse was requested (`with_reuse`) but the environment does not "
Expand Down Expand Up @@ -138,15 +150,15 @@ def start(self) -> Self:
self._container = container
logger.info("Container is already running: %s", container.id)
else:
self._start(hash_)
self._start(network_kwargs, hash_)
else:
self._start()
self._start(network_kwargs)

if self._network:
self._network.connect(self._container.id, self._network_aliases)
return self

def _start(self, hash_=None):
def _start(self, network_kwargs, hash_=None):
docker_client = self.get_docker_client()
self._container = docker_client.run(
self.image,
Expand All @@ -157,10 +169,12 @@ def _start(self, hash_=None):
name=self._name,
volumes=self.volumes,
labels={"hash": hash_} if hash is not None else {},
**network_kwargs,
**self._kwargs,
)

logger.info("Container started: %s", self._container.short_id)
return self

def stop(self, force=True, delete_volume=True) -> None:
if self._container:
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.