use of com.google.cloud.tools.jib.api.Containerizer 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.Containerizer in project jib by GoogleContainerTools.
the class War method call.
@Override
public Integer call() {
commonCliOptions.validate();
SingleThreadedExecutor executor = new SingleThreadedExecutor();
ConsoleLogger logger = CliLogger.newLogger(commonCliOptions.getVerbosity(), commonCliOptions.getHttpTrace(), commonCliOptions.getConsoleOutput(), spec.commandLine().getOut(), spec.commandLine().getErr(), executor);
Future<Optional<String>> updateCheckFuture = Futures.immediateFuture(Optional.empty());
try {
JibCli.configureHttpLogging(commonCliOptions.getHttpTrace().toJulLevel());
GlobalConfig globalConfig = GlobalConfig.readConfig();
updateCheckFuture = JibCli.newUpdateChecker(globalConfig, commonCliOptions.getVerbosity(), logEvent -> logger.log(logEvent.getLevel(), logEvent.getMessage()));
if (!Files.exists(warFile)) {
logger.log(LogEvent.Level.ERROR, "The file path provided does not exist: " + warFile);
return 1;
}
if (Files.isDirectory(warFile)) {
logger.log(LogEvent.Level.ERROR, "The file path provided is for a directory. Please provide a path to a WAR: " + warFile);
return 1;
}
Path warFileParentDir = Verify.verifyNotNull(warFile.toAbsolutePath().getParent());
CacheDirectories cacheDirectories = CacheDirectories.from(commonCliOptions, warFileParentDir);
ArtifactProcessor processor = ArtifactProcessors.fromWar(warFile, cacheDirectories, this, commonContainerConfigCliOptions);
JibContainerBuilder containerBuilder = WarFiles.toJibContainerBuilder(processor, commonCliOptions, commonContainerConfigCliOptions, logger);
Containerizer containerizer = Containerizers.from(commonCliOptions, logger, cacheDirectories);
// Enable registry mirrors
Multimaps.asMap(globalConfig.getRegistryMirrors()).forEach(containerizer::addRegistryMirrors);
JibContainer jibContainer = containerBuilder.containerize(containerizer);
JibCli.writeImageJson(commonCliOptions.getImageJsonPath(), jibContainer);
} catch (InterruptedException ex) {
JibCli.logTerminatingException(logger, ex, commonCliOptions.isStacktrace());
Thread.currentThread().interrupt();
return 1;
} catch (Exception ex) {
JibCli.logTerminatingException(logger, ex, commonCliOptions.isStacktrace());
return 1;
} finally {
JibCli.finishUpdateChecker(logger, updateCheckFuture);
executor.shutDownAndAwaitTermination(Duration.ofSeconds(3));
}
return 0;
}
use of com.google.cloud.tools.jib.api.Containerizer in project jib by GoogleContainerTools.
the class PluginConfigurationProcessor method createJibBuildRunnerForTarImage.
/**
* Generate a runner for image builds to tar file.
*
* @param rawConfiguration the raw configuration from the plugin
* @param inferredAuthProvider the plugin specific auth provider
* @param projectProperties an plugin specific implementation of {@link ProjectProperties}
* @param globalConfig the Jib global config
* @param helpfulSuggestions a plugin specific instance of {@link HelpfulSuggestions}
* @return new {@link JibBuildRunner} to execute a build
* @throws InvalidImageReferenceException if the image reference is invalid
* @throws MainClassInferenceException if a main class could not be found
* @throws InvalidAppRootException if the specific path for application root is invalid
* @throws IOException if an error occurs creating the container builder
* @throws InvalidWorkingDirectoryException if the working directory specified for the build is
* invalid
* @throws InvalidPlatformException if there exists a {@link PlatformConfiguration} in the
* specified platforms list that is missing required fields or has invalid values
* @throws InvalidContainerVolumeException if a specific container volume is invalid
* @throws IncompatibleBaseImageJavaVersionException if the base image java version cannot support
* this build
* @throws NumberFormatException if a string to number conversion operation fails
* @throws InvalidContainerizingModeException if an invalid {@link ContainerizingMode} was
* specified
* @throws InvalidFilesModificationTimeException if configured modification time could not be
* parsed
* @throws InvalidCreationTimeException if configured creation time could not be parsed
* @throws JibPluginExtensionException if an error occurred while running plugin extensions
* @throws ExtraDirectoryNotFoundException if the extra directory specified for the build is not
* found
*/
public static JibBuildRunner createJibBuildRunnerForTarImage(RawConfiguration rawConfiguration, InferredAuthProvider inferredAuthProvider, ProjectProperties projectProperties, GlobalConfig globalConfig, HelpfulSuggestions helpfulSuggestions) throws InvalidImageReferenceException, MainClassInferenceException, InvalidAppRootException, IOException, InvalidWorkingDirectoryException, InvalidPlatformException, InvalidContainerVolumeException, IncompatibleBaseImageJavaVersionException, NumberFormatException, InvalidContainerizingModeException, InvalidFilesModificationTimeException, InvalidCreationTimeException, JibPluginExtensionException, ExtraDirectoryNotFoundException {
ImageReference targetImageReference = getGeneratedTargetDockerTag(rawConfiguration, projectProperties, helpfulSuggestions);
TarImage targetImage = TarImage.at(rawConfiguration.getTarOutputPath()).named(targetImageReference);
Containerizer containerizer = Containerizer.to(targetImage);
Multimaps.asMap(globalConfig.getRegistryMirrors()).forEach(containerizer::addRegistryMirrors);
JibContainerBuilder jibContainerBuilder = processCommonConfiguration(rawConfiguration, inferredAuthProvider, projectProperties, containerizer);
JibContainerBuilder updatedContainerBuilder = projectProperties.runPluginExtensions(rawConfiguration.getPluginExtensions(), jibContainerBuilder);
return JibBuildRunner.forBuildTar(updatedContainerBuilder, containerizer, projectProperties::log, helpfulSuggestions, rawConfiguration.getTarOutputPath()).writeImageDigest(rawConfiguration.getDigestOutputPath()).writeImageId(rawConfiguration.getImageIdOutputPath()).writeImageJson(rawConfiguration.getImageJsonOutputPath());
}
use of com.google.cloud.tools.jib.api.Containerizer in project jib by google.
the class PluginConfigurationProcessorTest method testPluginConfigurationProcessor_defaults.
@Test
public void testPluginConfigurationProcessor_defaults() throws InvalidImageReferenceException, IOException, MainClassInferenceException, InvalidAppRootException, InvalidWorkingDirectoryException, InvalidPlatformException, InvalidContainerVolumeException, IncompatibleBaseImageJavaVersionException, NumberFormatException, InvalidContainerizingModeException, InvalidFilesModificationTimeException, InvalidCreationTimeException, ExtraDirectoryNotFoundException {
ContainerBuildPlan buildPlan = processCommonConfiguration();
assertThat(buildPlan.getEntrypoint()).containsExactly("java", "-cp", "/app/resources:/app/classes:/app/libs/*", "java.lang.Object").inOrder();
verify(containerizer).setBaseImageLayersCache(Containerizer.DEFAULT_BASE_CACHE_DIRECTORY);
verify(containerizer).setApplicationLayersCache(appCacheDirectory);
ArgumentMatcher<LogEvent> isLogWarn = logEvent -> logEvent.getLevel() == LogEvent.Level.WARN;
verify(logger, never()).accept(argThat(isLogWarn));
}
use of com.google.cloud.tools.jib.api.Containerizer in project jib by google.
the class Containerizers method from.
/**
* Create a Containerizer from a command line specification.
*
* @param commonCliOptions common cli options
* @param logger a logger to inject into the build
* @param cacheDirectories the location of the relevant caches for this build
* @return a populated Containerizer
* @throws InvalidImageReferenceException if the image reference could not be parsed
* @throws FileNotFoundException if a credential helper file is not found
*/
public static Containerizer from(CommonCliOptions commonCliOptions, ConsoleLogger logger, CacheDirectories cacheDirectories) throws InvalidImageReferenceException, FileNotFoundException {
Containerizer containerizer = create(commonCliOptions, logger);
applyHandlers(containerizer, logger);
applyConfiguration(containerizer, commonCliOptions, cacheDirectories);
return containerizer;
}
Aggregations