Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read indexServerAddress from Docker's /info #5347

Merged
merged 5 commits into from
May 14, 2022
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 @@ -199,7 +199,7 @@ public void close() {
};
log.info("Docker host IP address is {}", strategy.getDockerHostIpAddress());

Info dockerInfo = client.infoCmd().exec();
Info dockerInfo = strategy.getInfo();
Version version = client.versionCmd().exec();
activeApiVersion = version.getApiVersion();
activeExecutionDriver = dockerInfo.getExecutionDriver();
Expand Down Expand Up @@ -434,4 +434,9 @@ public String getActiveExecutionDriver() {
public boolean isUsing(Class<? extends DockerClientProviderStrategy> providerStrategyClass) {
return strategy != null && providerStrategyClass.isAssignableFrom(this.strategy.getClass());
}

@UnstableAPI
public Info getInfo() {
return getOrInitializeStrategy().getInfo();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ public abstract class DockerClientProviderStrategy {

private String dockerHostIpAddress;

@Getter
private Info info;

private final RateLimiter PING_RATE_LIMITER = RateLimiterBuilder.newBuilder()
.withRate(10, TimeUnit.SECONDS)
.withConstantThroughput()
Expand Down Expand Up @@ -249,7 +252,7 @@ private static boolean tryOutStrategy(List<String> configurationFailures, Docker
return false;
}

Info info = strategy.getDockerClient().infoCmd().exec();
strategy.info = strategy.getDockerClient().infoCmd().exec();
log.info("Found Docker environment with {}", strategy.getDescription());
log.debug(
"Transport type: '{}', Docker host: '{}'",
Expand All @@ -258,7 +261,7 @@ private static boolean tryOutStrategy(List<String> configurationFailures, Docker
);

log.debug("Checking Docker OS type for {}", strategy.getDescription());
String osType = info.getOsType();
String osType = strategy.getInfo().getOsType();
if (StringUtils.isBlank(osType)) {
log.warn("Could not determine Docker OS type");
} else if (!osType.equals("linux")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.SystemUtils;
import org.slf4j.Logger;
import org.testcontainers.DockerClientFactory;
import org.zeroturnaround.exec.InvalidResultException;
import org.zeroturnaround.exec.ProcessExecutor;

Expand All @@ -32,7 +33,7 @@
public class RegistryAuthLocator {

private static final Logger log = getLogger(RegistryAuthLocator.class);
private static final String DEFAULT_REGISTRY_NAME = "index.docker.io";
private static final String DEFAULT_REGISTRY_NAME = "https://index.docker.io/v1/";
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();

private static RegistryAuthLocator instance;
Expand Down Expand Up @@ -282,7 +283,14 @@ private String getCredentialProgramName(String credHelper) {
}

private String effectiveRegistryName(DockerImageName dockerImageName) {
return StringUtils.defaultIfEmpty(dockerImageName.getRegistry(), DEFAULT_REGISTRY_NAME);
final String registry = dockerImageName.getRegistry();
if (!StringUtils.isEmpty(registry)) {
return registry;
}
return StringUtils.defaultString(
DockerClientFactory.instance().getInfo().getIndexServerAddress(),
DEFAULT_REGISTRY_NAME
);
}

private String getGenericCredentialsNotFoundMsg(String credentialHelperName) {
Expand Down