use of com.google.cloud.tools.jib.api.DockerDaemonImage in project jib by GoogleContainerTools.
the class PluginConfigurationProcessor method getJavaContainerBuilderWithBaseImage.
/**
* Returns a {@link JavaContainerBuilder} with the correctly parsed base image configuration.
*
* @param rawConfiguration contains the base image configuration
* @param projectProperties used for providing additional information
* @param inferredAuthProvider provides inferred auths for registry images
* @return a new {@link JavaContainerBuilder} with the configured base image
* @throws IncompatibleBaseImageJavaVersionException when the Java version in the base image is
* incompatible with the Java version of the application to be containerized
* @throws InvalidImageReferenceException if the base image configuration can't be parsed
* @throws FileNotFoundException if a credential helper can't be found
*/
@VisibleForTesting
static JavaContainerBuilder getJavaContainerBuilderWithBaseImage(RawConfiguration rawConfiguration, ProjectProperties projectProperties, InferredAuthProvider inferredAuthProvider) throws IncompatibleBaseImageJavaVersionException, InvalidImageReferenceException, FileNotFoundException {
// Use image configuration as-is if it's a local base image
Optional<String> image = rawConfiguration.getFromImage();
String baseImageConfig = image.isPresent() ? image.get() : getDefaultBaseImage(projectProperties);
if (baseImageConfig.startsWith(Jib.TAR_IMAGE_PREFIX)) {
return JavaContainerBuilder.from(baseImageConfig);
}
// Verify Java version is compatible
List<String> splits = Splitter.on("://").splitToList(baseImageConfig);
String prefixRemoved = splits.get(splits.size() - 1);
int javaVersion = projectProperties.getMajorJavaVersion();
if (isKnownJava8Image(prefixRemoved) && javaVersion > 8) {
throw new IncompatibleBaseImageJavaVersionException(8, javaVersion);
}
if (isKnownJava11Image(prefixRemoved) && javaVersion > 11) {
throw new IncompatibleBaseImageJavaVersionException(11, javaVersion);
}
if (isKnownJava17Image(prefixRemoved) && javaVersion > 17) {
throw new IncompatibleBaseImageJavaVersionException(17, javaVersion);
}
ImageReference baseImageReference = ImageReference.parse(prefixRemoved);
if (baseImageConfig.startsWith(Jib.DOCKER_DAEMON_IMAGE_PREFIX)) {
DockerDaemonImage dockerDaemonImage = DockerDaemonImage.named(baseImageReference).setDockerEnvironment(rawConfiguration.getDockerEnvironment());
Optional<Path> dockerExecutable = rawConfiguration.getDockerExecutable();
if (dockerExecutable.isPresent()) {
dockerDaemonImage.setDockerExecutable(dockerExecutable.get());
}
return JavaContainerBuilder.from(dockerDaemonImage);
}
RegistryImage baseImage = RegistryImage.named(baseImageReference);
configureCredentialRetrievers(rawConfiguration, projectProperties, baseImage, baseImageReference, PropertyNames.FROM_AUTH_USERNAME, PropertyNames.FROM_AUTH_PASSWORD, rawConfiguration.getFromAuth(), inferredAuthProvider, rawConfiguration.getFromCredHelper());
return JavaContainerBuilder.from(baseImage);
}
use of com.google.cloud.tools.jib.api.DockerDaemonImage in project quarkus by quarkusio.
the class JibProcessor method createContainerizer.
private Containerizer createContainerizer(ContainerImageConfig containerImageConfig, JibConfig jibConfig, ContainerImageInfoBuildItem containerImage, boolean pushRequested) {
Containerizer containerizer;
ImageReference imageReference = ImageReference.of(containerImage.getRegistry().orElse(null), containerImage.getRepository(), containerImage.getTag());
if (pushRequested || containerImageConfig.isPushExplicitlyEnabled()) {
if (!containerImageConfig.registry.isPresent()) {
log.info("No container image registry was set, so 'docker.io' will be used");
}
RegistryImage registryImage = toRegistryImage(imageReference, containerImageConfig.username, containerImageConfig.password);
containerizer = Containerizer.to(registryImage);
} else {
DockerDaemonImage dockerDaemonImage = DockerDaemonImage.named(imageReference);
Optional<String> dockerConfigExecutableName = ConfigProvider.getConfig().getOptionalValue("quarkus.docker.executable-name", String.class);
Optional<String> jibConfigExecutableName = jibConfig.dockerExecutableName;
if (jibConfigExecutableName.isPresent()) {
dockerDaemonImage.setDockerExecutable(Paths.get(jibConfigExecutableName.get()));
} else if (dockerConfigExecutableName.isPresent()) {
dockerDaemonImage.setDockerExecutable(Paths.get(dockerConfigExecutableName.get()));
} else {
// detect the container runtime instead of falling back to 'docker' as the default
ContainerRuntimeUtil.ContainerRuntime detectedContainerRuntime = ContainerRuntimeUtil.detectContainerRuntime();
log.infof("Using %s to run the native image builder", detectedContainerRuntime.getExecutableName());
dockerDaemonImage.setDockerExecutable(Paths.get(detectedContainerRuntime.getExecutableName()));
}
containerizer = Containerizer.to(dockerDaemonImage);
}
containerizer.setToolName("Quarkus");
containerizer.setToolVersion(Version.getVersion());
containerizer.addEventHandler(LogEvent.class, (e) -> {
if (!e.getMessage().isEmpty()) {
log.log(toJBossLoggingLevel(e.getLevel()), e.getMessage());
}
});
containerizer.setAllowInsecureRegistries(containerImageConfig.insecure);
containerizer.setAlwaysCacheBaseImage(jibConfig.alwaysCacheBaseImage);
containerizer.setOfflineMode(jibConfig.offlineMode);
return containerizer;
}
Aggregations