use of com.google.cloud.tools.jib.api.RegistryImage in project fabric8-maven-plugin by fabric8io.
the class JibServiceUtil method pushImage.
/**
* @param baseImage Base TarImage from where the image will be built.
* @param targetImageName Full name of the target Image to be pushed to the registry
* @param credential
* @param logger
*/
private static void pushImage(TarImage baseImage, String targetImageName, Credential credential, Logger logger) throws InterruptedException {
final ExecutorService jibBuildExecutor = Executors.newCachedThreadPool();
try {
RegistryImage targetImage = RegistryImage.named(targetImageName);
if (credential != null && !credential.getUsername().isEmpty() && !credential.getPassword().isEmpty()) {
targetImage.addCredential(credential.getUsername(), credential.getPassword());
}
Jib.from(baseImage).containerize(Containerizer.to(targetImage).setExecutorService(jibBuildExecutor).addEventHandler(LogEvent.class, log(logger)).addEventHandler(TimerEvent.class, new TimerEventHandler(logger::debug)).addEventHandler(ProgressEvent.class, new ProgressEventHandler(logUpdate())));
logUpdateFinished();
} catch (RegistryException | CacheDirectoryCreationException | InvalidImageReferenceException | IOException | ExecutionException e) {
logger.error("Exception occurred while pushing the image: %s", targetImageName);
throw new IllegalStateException(e.getMessage(), e);
} catch (InterruptedException ex) {
logger.error("Thread interrupted", ex);
throw ex;
} finally {
jibBuildExecutor.shutdown();
jibBuildExecutor.awaitTermination(JIB_EXECUTOR_SHUTDOWN_TIMEOUT_SECONDS, TimeUnit.SECONDS);
}
}
use of com.google.cloud.tools.jib.api.RegistryImage in project jib by GoogleContainerTools.
the class Containerizers method create.
private static Containerizer create(CommonCliOptions commonCliOptions, ConsoleLogger logger) throws InvalidImageReferenceException, FileNotFoundException {
String imageSpec = commonCliOptions.getTargetImage();
if (imageSpec.startsWith(DOCKER_DAEMON_IMAGE_PREFIX)) {
// TODO: allow setting docker env and docker executable (along with path/env)
return Containerizer.to(DockerDaemonImage.named(imageSpec.replaceFirst(DOCKER_DAEMON_IMAGE_PREFIX, "")));
}
if (imageSpec.startsWith(TAR_IMAGE_PREFIX)) {
return Containerizer.to(TarImage.at(Paths.get(imageSpec.replaceFirst(TAR_IMAGE_PREFIX, ""))).named(commonCliOptions.getName()));
}
ImageReference imageReference = ImageReference.parse(imageSpec.replaceFirst(REGISTRY_IMAGE_PREFIX, ""));
RegistryImage registryImage = RegistryImage.named(imageReference);
DefaultCredentialRetrievers defaultCredentialRetrievers = DefaultCredentialRetrievers.init(CredentialRetrieverFactory.forImage(imageReference, logEvent -> logger.log(logEvent.getLevel(), logEvent.getMessage())));
Credentials.getToCredentialRetrievers(commonCliOptions, defaultCredentialRetrievers).forEach(registryImage::addCredentialRetriever);
return Containerizer.to(registryImage);
}
use of com.google.cloud.tools.jib.api.RegistryImage in project quarkus by quarkusio.
the class JibProcessor method toRegistryImage.
private RegistryImage toRegistryImage(ImageReference imageReference, Optional<String> username, Optional<String> password) {
CredentialRetrieverFactory credentialRetrieverFactory = CredentialRetrieverFactory.forImage(imageReference, log::info);
RegistryImage registryImage = RegistryImage.named(imageReference);
if (username.isPresent() && password.isPresent()) {
registryImage.addCredential(username.get(), password.get());
} else {
registryImage.addCredentialRetriever(credentialRetrieverFactory.wellKnownCredentialHelpers());
registryImage.addCredentialRetriever(credentialRetrieverFactory.dockerConfig());
}
return registryImage;
}
use of com.google.cloud.tools.jib.api.RegistryImage in project geronimo-arthur by apache.
the class ImageMojo method createContainer.
@Override
protected Containerizer createContainer() throws InvalidImageReferenceException {
final ImageReference reference = ImageReference.parse(to);
final RegistryImage image = RegistryImage.named(reference);
registerCredentials(reference, image);
return Containerizer.to(image);
}
use of com.google.cloud.tools.jib.api.RegistryImage in project jib by google.
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);
}
Aggregations