Skip to content

Commit

Permalink
Add minio to the docker container
Browse files Browse the repository at this point in the history
  • Loading branch information
jmsmkn committed Dec 8, 2023
1 parent eb5a033 commit 484420f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 21 deletions.
13 changes: 10 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class Minio(NamedTuple):
output_bucket_name: str
container: Container
port: int
env: dict[str, str]


@contextmanager
Expand Down Expand Up @@ -62,15 +63,21 @@ def minio_container():
minio.reload() # required to get ports
port = minio.ports["9000/tcp"][0]["HostPort"]

mpatch.setenv("AWS_ACCESS_KEY_ID", "minioadmin")
mpatch.setenv("AWS_SECRET_ACCESS_KEY", "minioadmin")
mpatch.setenv("AWS_S3_ENDPOINT_URL", f"http://localhost:{port}")
minio_env = {
"AWS_ACCESS_KEY_ID": "minioadmin",
"AWS_SECRET_ACCESS_KEY": "minioadmin",
"AWS_S3_ENDPOINT_URL": f"http://localhost:{port}",
}

for key, value in minio_env.items():
mpatch.setenv(key, value)

yield Minio(
input_bucket_name=input_bucket_name,
output_bucket_name=output_bucket_name,
container=minio,
port=port,
env=minio_env,
)
finally:
mpatch.undo()
Expand Down
40 changes: 22 additions & 18 deletions tests/test_container_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import pytest

from tests import __version__
from tests.conftest import minio_container
from tests.utils import (
encode_b64j,
get_image_config,
Expand Down Expand Up @@ -70,21 +71,23 @@ def _container(*, base_image="hello-world:latest", host_port=8080, cmd=None):
)
pull_image(client=client, repo_tag=new_tag)

container = client.containers.run(
image=new_tag,
# For batch transforms, SageMaker runs the container as
# docker run image serve
command="serve",
# Containers must implement a web server that responds
# to invocations and ping requests on port 8080.
ports={8080: host_port},
auto_remove=True,
detach=True,
# You can't use the init initializer as your entry point
# in SageMaker containers because it gets confused by the
# train and serve arguments
init=False,
)
with minio_container() as minio:
container = client.containers.run(
image=new_tag,
# For batch transforms, SageMaker runs the container as
# docker run image serve
command="serve",
# Containers must implement a web server that responds
# to invocations and ping requests on port 8080.
ports={8080: host_port},
auto_remove=True,
detach=True,
# You can't use the init initializer as your entry point
# in SageMaker containers because it gets confused by the
# train and serve arguments
init=False,
environment=minio.env,
)

# Wait for startup
sleep(3)
Expand Down Expand Up @@ -134,15 +137,16 @@ def test_container_responds_to_execution_parameters():
@pytest.mark.skipif(
sys.platform != "linux", reason="does not run outside linux"
)
def test_invocations_endpoint():
def test_invocations_endpoint(minio):
# To receive inference requests, the container must have a web server
# listening on port 8080 and must accept POST requests to the
# /invocations endpoint.
pk = str(uuid4())
data = {
"pk": str(uuid4()),
"inputs": [],
"output_bucket_name": "test",
"output_prefix": "test",
"output_bucket_name": minio.output_bucket_name,
"output_prefix": f"test/{pk}",
}
response = httpx.post("http://localhost:8080/invocations", json=data)

Expand Down

0 comments on commit 484420f

Please sign in to comment.