Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,8 @@
/** Optional, use this bucket instead of a random one. */
String bucket() default DEFAULT;

/** Optional, use this region. */
String region() default DEFAULT;

String DEFAULT = "minio_default_value__";
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import java.net.URI;
import java.util.Map;
import java.util.Optional;
import software.amazon.awssdk.core.sync.RequestBody;
import software.amazon.awssdk.services.s3.S3Client;

Expand All @@ -43,6 +44,8 @@ public interface MinioAccess {

String bucket();

Optional<String> region();

/** HTTP protocol endpoint. */
String s3endpoint();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.Optional;
import org.apache.polaris.containerspec.ContainerSpecHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -122,15 +123,16 @@ private static String validateBucketHost(String bucketName) {
private String hostPort;
private String s3endpoint;
private S3Client s3;
private String region;
private Optional<String> region;

@SuppressWarnings("unused")
public MinioContainer() {
this(null, null, null, null);
this(null, null, null, null, null);
}

@SuppressWarnings("resource")
public MinioContainer(String image, String accessKey, String secretKey, String bucket) {
public MinioContainer(
String image, String accessKey, String secretKey, String bucket, String region) {
super(
ContainerSpecHelper.containerSpecHelper("minio", MinioContainer.class)
.dockerImageName(image));
Expand All @@ -143,6 +145,7 @@ public MinioContainer(String image, String accessKey, String secretKey, String b
bucket != null
? validateBucketHost(bucket)
: (FIXED_BUCKET_NAME != null ? FIXED_BUCKET_NAME : randomString("bucket"));
this.region = Optional.ofNullable(region);
withEnv(MINIO_ACCESS_KEY, this.accessKey);
withEnv(MINIO_SECRET_KEY, this.secretKey);
// S3 SDK encodes bucket names in host names - need to tell Minio which domain to use
Expand All @@ -156,7 +159,7 @@ public MinioContainer(String image, String accessKey, String secretKey, String b
}

public MinioContainer withRegion(String region) {
this.region = region;
this.region = Optional.of(region);
return this;
}

Expand Down Expand Up @@ -185,6 +188,11 @@ public String bucket() {
return bucket;
}

@Override
public Optional<String> region() {
return region;
}

@Override
public String s3endpoint() {
Preconditions.checkState(s3endpoint != null, "Container not yet started");
Expand All @@ -204,6 +212,7 @@ public Map<String, String> icebergProperties() {
props.put("s3.secret-access-key", secretKey());
props.put("s3.endpoint", s3endpoint());
props.put("http-client.type", "urlconnection");
region().ifPresent(r -> props.put("client.region", r));
return props;
}

Expand Down Expand Up @@ -259,12 +268,7 @@ private S3Client createS3Client() {
return S3Client.builder()
.httpClientBuilder(UrlConnectionHttpClient.builder())
.applyMutation(builder -> builder.endpointOverride(URI.create(s3endpoint())))
.applyMutation(
builder -> {
if (region != null) {
builder.region(Region.of(region));
}
})
.applyMutation(builder -> region.ifPresent(r -> builder.region(Region.of(r))))
// .serviceConfiguration(s3Configuration(s3PathStyleAccess, s3UseArnRegionEnabled))
// credentialsProvider(s3AccessKeyId, s3SecretAccessKey, s3SessionToken)
.credentialsProvider(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,9 @@ private MinioAccess createContainer(Minio minio) {
String accessKey = nonDefault(minio.accessKey());
String secretKey = nonDefault(minio.secretKey());
String bucket = nonDefault(minio.bucket());
String region = nonDefault(minio.region());
MinioContainer container =
new MinioContainer(null, accessKey, secretKey, bucket).withStartupAttempts(5);
new MinioContainer(null, accessKey, secretKey, bucket, region).withStartupAttempts(5);
container.start();
return container;
}
Expand Down