Skip to content

Commit

Permalink
Make nip.io usage resilient against lookup failures (#6885)
Browse files Browse the repository at this point in the history
nip.io's "magic" DNS names are not always resolvable, or resolvable in every setup.
This change first tries to resolve the "magic" nip.io address and falls back to the pre-#6856 behavior if the pre-check fails.
  • Loading branch information
snazy authored May 24, 2023
1 parent 23074c6 commit 9b0f079
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@
package org.projectnessie.minio;

import com.google.common.base.Preconditions;
import java.net.InetAddress;
import java.net.URI;
import java.net.UnknownHostException;
import java.time.Duration;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import org.apache.hadoop.conf.Configuration;
import org.junit.jupiter.api.extension.ExtensionContext.Store.CloseableResource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.output.Slf4jLogConsumer;
Expand All @@ -37,6 +40,8 @@
final class MinioContainer extends GenericContainer<MinioContainer>
implements MinioAccess, CloseableResource {

private static final Logger LOGGER = LoggerFactory.getLogger(MinioContainer.class);

private static final int DEFAULT_PORT = 9000;
private static final String DEFAULT_IMAGE = "quay.io/minio/minio";
private static final String DEFAULT_TAG = "latest";
Expand All @@ -47,8 +52,28 @@ final class MinioContainer extends GenericContainer<MinioContainer>

private static final String DEFAULT_STORAGE_DIRECTORY = "/data";
private static final String HEALTH_ENDPOINT = "/minio/health/ready";
private static final String MINIO_DOMAIN_NAME;
private static final String MINIO_DOMAIN_NIP = "minio.127-0-0-1.nip.io";

static boolean canRunOnMacOs() {
return MINIO_DOMAIN_NAME.equals(MINIO_DOMAIN_NIP);
}

static {
String name;
try {
InetAddress.getByName(MINIO_DOMAIN_NIP);
name = MINIO_DOMAIN_NIP;
} catch (UnknownHostException e) {
LOGGER.warn(
"Could not resolve '{}', falling back to 'localhost'. "
+ "This usually happens when your router or DNS provider is unable to resolve the nip.io addresses.",
MINIO_DOMAIN_NIP);
name = "localhost";
}
MINIO_DOMAIN_NAME = name;
}

private final String accessKey;
private final String secretKey;
private final String bucket;
Expand All @@ -75,7 +100,7 @@ public MinioContainer(String image, String accessKey, String secretKey, String b
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
withEnv(MINIO_DOMAIN, MINIO_DOMAIN_NIP);
withEnv(MINIO_DOMAIN, MINIO_DOMAIN_NAME);
withCommand("server", DEFAULT_STORAGE_DIRECTORY);
setWaitStrategy(
new HttpWaitStrategy()
Expand Down Expand Up @@ -150,7 +175,7 @@ public URI s3BucketUri(String path) {
public void start() {
super.start();

this.hostPort = MINIO_DOMAIN_NIP + ":" + getMappedPort(DEFAULT_PORT);
this.hostPort = MINIO_DOMAIN_NAME + ":" + getMappedPort(DEFAULT_PORT);
this.s3endpoint = String.format("http://%s/", hostPort);
this.bucketBaseUri = URI.create(String.format("s3://%s/", bucket()));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext con
if (OS.current() == OS.LINUX) {
return enabled("Running on Linux");
}
if (OS.current() == OS.MAC && System.getenv("CI_MAC") == null) {
if (OS.current() == OS.MAC
&& System.getenv("CI_MAC") == null
&& MinioContainer.canRunOnMacOs()) {
// Disable tests on GitHub Actions
return enabled("Running on macOS locally");
}
Expand Down

0 comments on commit 9b0f079

Please sign in to comment.