6
6
7
7
8
8
class MinioContainer (DockerContainer ):
9
+ """
10
+ The example below spins up an Minio container and creates a new bucket in it.
11
+ Furthermore, it demonstrates how an object is written to this bucket and then subsequently retrieved.
12
+ The method :code:`get_client` can be used to create a client for the Minio Python API.
13
+ The method :code:`get_config` can be used to retrieve the endpoint, access key
14
+ and secret key of the container.
15
+
16
+ Example
17
+ -------
18
+ .. doctest::
19
+
20
+ >>> from testcontainers.minio import MinioContainer
21
+
22
+ >>> with MinioContainer() as minio:
23
+ ... client = minio.get_client()
24
+ ... client.make_bucket("test")
25
+ ... test_content = b"Hello World"
26
+ ... client.put_object(
27
+ ... "test",
28
+ ... "testfile.txt",
29
+ ... io.BytesIO(test_content),
30
+ ... length=len(test_content),
31
+ ... )
32
+ ... retrieved_content = client.get_object("test", "testfile.txt").data
33
+ """
34
+
9
35
def __init__ (
10
36
self ,
11
37
image = "minio/minio:RELEASE.2022-12-02T19-19-22Z" ,
@@ -14,6 +40,14 @@ def __init__(
14
40
secret_key = "minioadmin" ,
15
41
** kwargs ,
16
42
):
43
+ """
44
+ Args:
45
+ image (str, optional): The Docker image to use for the Minio container.
46
+ Defaults to "minio/minio:RELEASE.2022-12-02T19-19-22Z".
47
+ port_to_expose (int, optional): The port to expose on the container. Defaults to 9000.
48
+ access_key (str, optional): The access key for client connections. Defaults to "minioadmin".
49
+ secret_key (str, optional): The secret key for client connections. Defaults to "minioadmin".
50
+ """
17
51
super (MinioContainer , self ).__init__ (image , ** kwargs )
18
52
self .port_to_expose = port_to_expose
19
53
self .access_key = access_key
@@ -42,7 +76,8 @@ def get_client(self, **kwargs) -> Minio:
42
76
)
43
77
44
78
def get_config (self ) -> dict :
45
- """Returns the configuration of the Minio container.
79
+ """This method returns the configuration of the Minio container,
80
+ including the endpoint, access key, and secret key.
46
81
47
82
Returns:
48
83
dict: {`endpoint`: str, `access_key`: str, `secret_key`: str}
@@ -57,11 +92,15 @@ def get_config(self) -> dict:
57
92
58
93
@wait_container_is_ready (ConnectionError )
59
94
def _healthcheck (self ):
95
+ """This is an internal method used to check if the Minio container
96
+ is healthy and ready to receive requests."""
60
97
url = f"http://{ self .get_config ()['endpoint' ]} /minio/health/live"
61
98
response : Response = get (url )
62
99
response .raise_for_status ()
63
100
64
101
def start (self ):
102
+ """This method starts the Minio container and runs the healthcheck
103
+ to verify that the container is ready to use."""
65
104
super ().start ()
66
105
self ._healthcheck ()
67
106
return self
0 commit comments