in tools/container-spec-helper/src/main/java/org/apache/polaris/containerspec/ContainerSpecHelper.java [96:157]
public DockerImageName dockerImageName(String explicitImageName) {
if (explicitImageName != null) {
return DockerImageName.parse(explicitImageName);
}
String dockerfile = format("Dockerfile-%s-version", name());
URL resource = containerClass().getResource(dockerfile);
Objects.requireNonNull(resource, dockerfile + " not found");
String systemPropPrefix1 = "it.polaris.container." + name() + ".";
String systemPropPrefix2 = "polaris.testing." + name() + ".";
String envPrefix = name().toUpperCase(Locale.ROOT).replaceAll("-", "_") + "_DOCKER_";
String explicitImage = System.getProperty(systemPropPrefix1 + "image");
if (explicitImage == null) {
explicitImage = System.getProperty(systemPropPrefix2 + "image");
}
if (explicitImage == null) {
explicitImage = System.getenv(envPrefix + "IMAGE");
}
String explicitTag = System.getProperty(systemPropPrefix1 + "tag");
if (explicitTag == null) {
explicitTag = System.getProperty(systemPropPrefix2 + "tag");
}
if (explicitTag == null) {
explicitTag = System.getenv(envPrefix + "TAG");
}
if (explicitImage != null && explicitTag != null) {
return DockerImageName.parse(explicitImage + ':' + explicitTag);
}
try (InputStream in = resource.openConnection().getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(in, UTF_8))) {
String fullImageName = null;
String ln;
while ((ln = reader.readLine()) != null) {
ln = ln.trim();
if (ln.startsWith("FROM ")) {
fullImageName = ln.substring(5).trim();
break;
}
}
if (fullImageName == null) {
throw new IllegalStateException(
"Dockerfile " + dockerfile + " does not contain a line starting with 'FROM '");
}
if (explicitImage != null || explicitTag != null) {
throw new IllegalArgumentException(
"Must specify either BOTH, image name AND tag via system properties or environment or omit and leave it to the default "
+ fullImageName
+ " from "
+ dockerfile);
}
return DockerImageName.parse(fullImageName);
} catch (Exception e) {
throw new RuntimeException("Failed to extract tag from " + resource, e);
}
}