use of com.google.cloud.tools.jib.plugins.extension.JibPluginExtensionException in project jib by GoogleContainerTools.
the class BuildDockerTask method buildDocker.
/**
* Task Action, builds an image to docker daemon.
*
* @throws IOException if an error occurs creating the jib runner
* @throws BuildStepsExecutionException if an error occurs while executing build steps
* @throws CacheDirectoryCreationException if a new cache directory could not be created
* @throws MainClassInferenceException if a main class could not be found
* @throws InvalidGlobalConfigException if the global config file is invalid
*/
@TaskAction
public void buildDocker() throws IOException, BuildStepsExecutionException, CacheDirectoryCreationException, MainClassInferenceException, InvalidGlobalConfigException {
Preconditions.checkNotNull(jibExtension);
// Check deprecated parameters
Path dockerExecutable = jibExtension.getDockerClient().getExecutablePath();
boolean isDockerInstalled = dockerExecutable == null ? DockerClient.isDefaultDockerInstalled() : DockerClient.isDockerInstalled(dockerExecutable);
if (!isDockerInstalled) {
throw new GradleException(HelpfulSuggestions.forDockerNotInstalled(HELPFUL_SUGGESTIONS_PREFIX));
}
TaskCommon.disableHttpLogging();
TempDirectoryProvider tempDirectoryProvider = new TempDirectoryProvider();
GradleProjectProperties projectProperties = GradleProjectProperties.getForProject(getProject(), getLogger(), tempDirectoryProvider, jibExtension.getConfigurationName().get());
GlobalConfig globalConfig = GlobalConfig.readConfig();
Future<Optional<String>> updateCheckFuture = TaskCommon.newUpdateChecker(projectProperties, globalConfig, getLogger());
try {
PluginConfigurationProcessor.createJibBuildRunnerForDockerDaemonImage(new GradleRawConfiguration(jibExtension), ignored -> java.util.Optional.empty(), projectProperties, globalConfig, new GradleHelpfulSuggestions(HELPFUL_SUGGESTIONS_PREFIX)).runBuild();
} catch (InvalidAppRootException ex) {
throw new GradleException("container.appRoot is not an absolute Unix-style path: " + ex.getInvalidPathValue(), ex);
} catch (InvalidContainerizingModeException ex) {
throw new GradleException("invalid value for containerizingMode: " + ex.getInvalidContainerizingMode(), ex);
} catch (InvalidWorkingDirectoryException ex) {
throw new GradleException("container.workingDirectory is not an absolute Unix-style path: " + ex.getInvalidPathValue(), ex);
} catch (InvalidPlatformException ex) {
throw new GradleException("from.platforms contains a platform configuration that is missing required values or has invalid values: " + ex.getMessage() + ": " + ex.getInvalidPlatform(), ex);
} catch (InvalidContainerVolumeException ex) {
throw new GradleException("container.volumes is not an absolute Unix-style path: " + ex.getInvalidVolume(), ex);
} catch (InvalidFilesModificationTimeException ex) {
throw new GradleException("container.filesModificationTime should be an ISO 8601 date-time (see " + "DateTimeFormatter.ISO_DATE_TIME) or special keyword \"EPOCH_PLUS_SECOND\": " + ex.getInvalidFilesModificationTime(), ex);
} catch (InvalidCreationTimeException ex) {
throw new GradleException("container.creationTime should be an ISO 8601 date-time (see " + "DateTimeFormatter.ISO_DATE_TIME) or a special keyword (\"EPOCH\", " + "\"USE_CURRENT_TIMESTAMP\"): " + ex.getInvalidCreationTime(), ex);
} catch (JibPluginExtensionException ex) {
String extensionName = ex.getExtensionClass().getName();
throw new GradleException("error running extension '" + extensionName + "': " + ex.getMessage(), ex);
} catch (IncompatibleBaseImageJavaVersionException ex) {
throw new GradleException(HelpfulSuggestions.forIncompatibleBaseImageJavaVersionForGradle(ex.getBaseImageMajorJavaVersion(), ex.getProjectMajorJavaVersion()), ex);
} catch (InvalidImageReferenceException ex) {
throw new GradleException(HelpfulSuggestions.forInvalidImageReference(ex.getInvalidReference()), ex);
} catch (ExtraDirectoryNotFoundException ex) {
throw new GradleException("extraDirectories.paths contain \"from\" directory that doesn't exist locally: " + ex.getPath(), ex);
} finally {
tempDirectoryProvider.close();
TaskCommon.finishUpdateChecker(projectProperties, updateCheckFuture);
projectProperties.waitForLoggingThread();
}
}
use of com.google.cloud.tools.jib.plugins.extension.JibPluginExtensionException in project jib by GoogleContainerTools.
the class MavenProjectPropertiesExtensionTest method testRunPluginExtensions_wrongExtraConfigType.
@Test
public void testRunPluginExtensions_wrongExtraConfigType() {
FooExtension extension = new FooExtension((buildPlan, properties, extraConfig, mavenData, logger) -> buildPlan);
loadedExtensions = Arrays.asList(extension);
ExtensionConfiguration extensionConfig = new BaseExtensionConfig<>(FooExtension.class.getName(), Collections.emptyMap(), "string <configuration>");
try {
mavenProjectProperties.runPluginExtensions(Arrays.asList(extensionConfig), containerBuilder);
Assert.fail();
} catch (JibPluginExtensionException ex) {
Assert.assertEquals(FooExtension.class, ex.getExtensionClass());
Assert.assertEquals("extension-specific <configuration> for FooExtension is not of type com.google.cloud" + ".tools.jib.maven.MavenProjectPropertiesExtensionTest$ExtensionDefinedFooConfig " + "but java.lang.String; specify the correct type with <pluginExtension>" + "<configuration implementation=\"com.google.cloud.tools.jib.maven." + "MavenProjectPropertiesExtensionTest$ExtensionDefinedFooConfig\">", ex.getMessage());
}
}
use of com.google.cloud.tools.jib.plugins.extension.JibPluginExtensionException in project jib-extensions by GoogleContainerTools.
the class JibLayerFilterExtensionTest method testExtendContainerBuildPlan_noGlobGiven.
@Test
public void testExtendContainerBuildPlan_noGlobGiven() {
ContainerBuildPlan buildPlan = ContainerBuildPlan.builder().build();
Configuration.Filter filter = mockFilter("", "doesn't matter");
when(config.getFilters()).thenReturn(Arrays.asList(filter));
try {
new JibLayerFilterExtension().extendContainerBuildPlan(buildPlan, null, Optional.of(config), null, logger);
fail();
} catch (JibPluginExtensionException ex) {
assertEquals(JibLayerFilterExtension.class, ex.getExtensionClass());
assertEquals("glob pattern not given in filter configuration", ex.getMessage());
}
}
use of com.google.cloud.tools.jib.plugins.extension.JibPluginExtensionException in project jib-extensions by GoogleContainerTools.
the class JibLayerFilterExtension method extendContainerBuildPlan.
@Override
public ContainerBuildPlan extendContainerBuildPlan(ContainerBuildPlan buildPlan, Map<String, String> properties, Optional<Configuration> config, MavenData mavenData, ExtensionLogger logger) throws JibPluginExtensionException {
logger.log(LogLevel.LIFECYCLE, "Running Jib Layer Filter Extension");
if (!config.isPresent()) {
logger.log(LogLevel.WARN, "Nothing configured for Jib Layer Filter Extension");
return buildPlan;
}
preparePathMatchersAndLayerBuilders(buildPlan, config.get());
ContainerBuildPlan.Builder newPlanBuilder = buildPlan.toBuilder();
newPlanBuilder.setLayers(Collections.emptyList());
@SuppressWarnings("unchecked") List<FileEntriesLayer> originalLayers = (List<FileEntriesLayer>) buildPlan.getLayers();
// Start filtering original layers.
for (FileEntriesLayer layer : originalLayers) {
List<FileEntry> filesToKeep = new ArrayList<>();
for (FileEntry entry : layer.getEntries()) {
Optional<String> finalLayerName = determineFinalLayerName(entry, layer.getName());
// Either keep, move, or delete this FileEntry.
if (finalLayerName.isPresent()) {
if (finalLayerName.get().equals(layer.getName())) {
filesToKeep.add(entry);
} else {
FileEntriesLayer.Builder targetLayerBuilder = Verify.verifyNotNull(newToLayers.get(finalLayerName.get()));
targetLayerBuilder.addEntry(entry);
}
}
}
if (!filesToKeep.isEmpty()) {
newPlanBuilder.addLayer(layer.toBuilder().setEntries(filesToKeep).build());
}
}
// Add newly created non-empty to-layers (if any).
newToLayers.values().stream().map(FileEntriesLayer.Builder::build).filter(layer -> !layer.getEntries().isEmpty()).forEach(newPlanBuilder::addLayer);
ContainerBuildPlan newPlan = newPlanBuilder.build();
return config.get().isCreateParentDependencyLayers() ? moveParentDepsToNewLayers(newPlan, mavenData, logger) : newPlan;
}
use of com.google.cloud.tools.jib.plugins.extension.JibPluginExtensionException in project jib-extensions by GoogleContainerTools.
the class JibLayerFilterExtensionTest method testExtendContainerBuildPlan_createParentLayers_noParent.
@Test
public void testExtendContainerBuildPlan_createParentLayers_noParent() {
ContainerBuildPlan buildPlan = ContainerBuildPlan.builder().build();
when(config.isCreateParentDependencyLayers()).thenReturn(true);
when(mavenProject.getParent()).thenReturn(null);
try {
JibLayerFilterExtension extension = new JibLayerFilterExtension();
extension.extendContainerBuildPlan(buildPlan, null, Optional.of(config), mavenData, logger);
fail();
} catch (JibPluginExtensionException ex) {
assertEquals(JibLayerFilterExtension.class, ex.getExtensionClass());
assertEquals("Try to get parent dependencies, but project has no parent.", ex.getMessage());
}
}
Aggregations