Skip to content

Adding MinIO module#7440

Merged
eddumelendez merged 8 commits into
testcontainers:mainfrom
frozenwizard:minio
Sep 6, 2023
Merged

Adding MinIO module#7440
eddumelendez merged 8 commits into
testcontainers:mainfrom
frozenwizard:minio

Conversation

@frozenwizard

Copy link
Copy Markdown
Contributor

This adds the MinIO container.

@frozenwizard frozenwizard requested a review from a team August 25, 2023 17:18

@eddumelendez eddumelendez left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for your contribution. We will talk about the module tomorrow. I just left some suggestions for general review. No changes should be applied until further notice.

Comment thread modules/minio/src/main/java/org/testcontainers/containers/MinIOContainer.java Outdated
Comment thread modules/minio/src/main/java/org/testcontainers/containers/MinIOContainer.java Outdated
Comment thread modules/minio/src/main/java/org/testcontainers/containers/MinIOContainer.java Outdated
@eddumelendez

Copy link
Copy Markdown
Member

@frozenwizard Please, proceed making the changes. We discussed this Today and we will be hosting the module. Thanks again!

@eddumelendez eddumelendez added this to the next milestone Aug 31, 2023
@eddumelendez

Copy link
Copy Markdown
Member

@frozenwizard I forgot to ask but can you some docs, please?

@eddumelendez eddumelendez left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Add additional test switching another credentials and verify those were set in the container

Comment on lines +20 to +44
MinIOContainer container = new MinIOContainer("minio/minio:latest");
container.start();

MinioClient minioClient = MinioClient
.builder()
.endpoint(container.getS3URL())
.credentials(container.getUserName(), container.getPassword())
.build();

minioClient.makeBucket(MakeBucketArgs.builder().bucket("test-bucket").region("us-west-2").build());

BucketExistsArgs existsArgs = BucketExistsArgs.builder().bucket("test-bucket").build();

assertThat(minioClient.bucketExists(existsArgs)).isTrue();

URL file = this.getClass().getResource("/object_to_upload.txt");
assertThat(file).isNotNull();
ObjectWriteResponse upload = minioClient.uploadObject(
UploadObjectArgs.builder().bucket("test-bucket").object("my-objectname").filename(file.getPath()).build()
);

StatObjectResponse objectStat = minioClient.statObject(
StatObjectArgs.builder().bucket("test-bucket").object("my-objectname").build()
);

assertThat(objectStat.object()).isEqualTo("my-objectname");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

replace latest with a specific version

Suggested change
MinIOContainer container = new MinIOContainer("minio/minio:latest");
container.start();
MinioClient minioClient = MinioClient
.builder()
.endpoint(container.getS3URL())
.credentials(container.getUserName(), container.getPassword())
.build();
minioClient.makeBucket(MakeBucketArgs.builder().bucket("test-bucket").region("us-west-2").build());
BucketExistsArgs existsArgs = BucketExistsArgs.builder().bucket("test-bucket").build();
assertThat(minioClient.bucketExists(existsArgs)).isTrue();
URL file = this.getClass().getResource("/object_to_upload.txt");
assertThat(file).isNotNull();
ObjectWriteResponse upload = minioClient.uploadObject(
UploadObjectArgs.builder().bucket("test-bucket").object("my-objectname").filename(file.getPath()).build()
);
StatObjectResponse objectStat = minioClient.statObject(
StatObjectArgs.builder().bucket("test-bucket").object("my-objectname").build()
);
assertThat(objectStat.object()).isEqualTo("my-objectname");
try(MinIOContainer container = new MinIOContainer("minio/minio:latest")) {
container.start();
MinioClient minioClient = MinioClient
.builder()
.endpoint(container.getS3URL())
.credentials(container.getUserName(), container.getPassword())
.build();
minioClient.makeBucket(MakeBucketArgs.builder().bucket("test-bucket").region("us-west-2").build());
BucketExistsArgs existsArgs = BucketExistsArgs.builder().bucket("test-bucket").build();
assertThat(minioClient.bucketExists(existsArgs)).isTrue();
URL file = this.getClass().getResource("/object_to_upload.txt");
assertThat(file).isNotNull();
ObjectWriteResponse upload = minioClient.uploadObject(
UploadObjectArgs.builder().bucket("test-bucket").object("my-objectname").filename(file.getPath()).build()
);
StatObjectResponse objectStat = minioClient.statObject(
StatObjectArgs.builder().bucket("test-bucket").object("my-objectname").build()
);
assertThat(objectStat.object()).isEqualTo("my-objectname");
}

* <p>
* Exposed ports: 9000,9001
*/
@Slf4j

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
@Slf4j

* Constructs a MinIO container from the dockerImageName
* @param dockerImageName the full image name to use
*/
public MinIOContainer(@NonNull final String dockerImageName) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
public MinIOContainer(@NonNull final String dockerImageName) {
public MinIOContainer(final String dockerImageName) {


URL file = this.getClass().getResource("/object_to_upload.txt");
assertThat(file).isNotNull();
ObjectWriteResponse upload = minioClient.uploadObject(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

upload is not being used

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

In general if an upload fails it throws an exception. If we get the upload object back then it was a success. I can make it more clear with a comment or remove the variable.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

removing the variable would be fine

@frozenwizard

Copy link
Copy Markdown
Contributor Author

@frozenwizard I forgot to ask but can you some docs, please?

Sure where would they go?

@eddumelendez

Copy link
Copy Markdown
Member

docs can be added here and then update the mkdocs.yml in the root directory

Comment thread docs/modules/minio.md Outdated
Comment thread docs/modules/minio.md Outdated
Comment thread docs/modules/minio.md Outdated
@eddumelendez eddumelendez merged commit ba9e3cc into testcontainers:main Sep 6, 2023
@eddumelendez

Copy link
Copy Markdown
Member

Thanks for your contribution, @frozenwizard ! I've made some changes to keep aligned with the image. Module will be release as part of the next release.

@frozenwizard frozenwizard deleted the minio branch September 8, 2023 02:12
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.

2 participants