use of com.google.cloud.tools.jib.api.InvalidImageReferenceException in project jib by google.
the class GradleProjectProperties method runPluginExtensions.
@Override
public JibContainerBuilder runPluginExtensions(List<? extends ExtensionConfiguration> extensionConfigs, JibContainerBuilder jibContainerBuilder) throws JibPluginExtensionException {
if (extensionConfigs.isEmpty()) {
log(LogEvent.debug("No Jib plugin extensions configured to load"));
return jibContainerBuilder;
}
List<JibGradlePluginExtension<?>> loadedExtensions = extensionLoader.get();
JibGradlePluginExtension<?> extension = null;
ContainerBuildPlan buildPlan = jibContainerBuilder.toContainerBuildPlan();
try {
for (ExtensionConfiguration config : extensionConfigs) {
extension = findConfiguredExtension(loadedExtensions, config);
log(LogEvent.lifecycle("Running extension: " + config.getExtensionClass()));
buildPlan = runPluginExtension(extension.getExtraConfigType(), extension, config, buildPlan);
// to validate image reference
ImageReference.parse(buildPlan.getBaseImage());
}
return jibContainerBuilder.applyContainerBuildPlan(buildPlan);
} catch (InvalidImageReferenceException ex) {
throw new JibPluginExtensionException(Verify.verifyNotNull(extension).getClass(), "invalid base image reference: " + buildPlan.getBaseImage(), ex);
}
}
use of com.google.cloud.tools.jib.api.InvalidImageReferenceException in project jib by google.
the class BuildImageMojoIntegrationTest method buildAndRun.
/**
* Builds with {@code jib:build} on a project at {@code projectRoot} pushing to {@code
* imageReference} and run the image after pulling it.
*/
private static String buildAndRun(Path projectRoot, String imageReference, String pomXml, boolean buildTwice) throws VerificationException, IOException, InterruptedException, DigestException {
build(projectRoot, imageReference, pomXml, buildTwice).verifyErrorFreeLog();
String output = pullAndRunBuiltImage(imageReference);
try {
// Test pulling/running using image digest
String digest = readDigestFile(projectRoot.resolve("target/jib-image.digest"));
String imageReferenceWithDigest = ImageReference.parse(imageReference).withQualifier(digest).toString();
assertThat(pullAndRunBuiltImage(imageReferenceWithDigest)).isEqualTo(output);
// Test running using image id
String id = readDigestFile(projectRoot.resolve("target/jib-image.id"));
assertThat(id).isNotEqualTo(digest);
assertThat(new Command("docker", "run", "--rm", id).run()).isEqualTo(output);
} catch (InvalidImageReferenceException ex) {
throw new AssertionError("error replacing tag with digest", ex);
}
return output;
}
use of com.google.cloud.tools.jib.api.InvalidImageReferenceException in project jib by google.
the class BuildTarMojo method execute.
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
checkJibVersion();
if (MojoCommon.shouldSkipJibExecution(this)) {
return;
}
MavenSettingsProxyProvider.activateHttpAndHttpsProxies(getSession().getSettings(), getSettingsDecrypter());
TempDirectoryProvider tempDirectoryProvider = new TempDirectoryProvider();
MavenProjectProperties projectProperties = MavenProjectProperties.getForProject(Preconditions.checkNotNull(descriptor), getProject(), getSession(), getLog(), tempDirectoryProvider, getInjectedPluginExtensions());
Future<Optional<String>> updateCheckFuture = Futures.immediateFuture(Optional.empty());
try {
GlobalConfig globalConfig = GlobalConfig.readConfig();
updateCheckFuture = MojoCommon.newUpdateChecker(projectProperties, globalConfig, getLog());
PluginConfigurationProcessor.createJibBuildRunnerForTarImage(new MavenRawConfiguration(this), new MavenSettingsServerCredentials(getSession().getSettings(), getSettingsDecrypter()), projectProperties, globalConfig, new MavenHelpfulSuggestions(HELPFUL_SUGGESTIONS_PREFIX)).runBuild();
} catch (InvalidAppRootException ex) {
throw new MojoExecutionException("<container><appRoot> is not an absolute Unix-style path: " + ex.getInvalidPathValue(), ex);
} catch (InvalidContainerizingModeException ex) {
throw new MojoExecutionException("invalid value for <containerizingMode>: " + ex.getInvalidContainerizingMode(), ex);
} catch (InvalidWorkingDirectoryException ex) {
throw new MojoExecutionException("<container><workingDirectory> is not an absolute Unix-style path: " + ex.getInvalidPathValue(), ex);
} catch (InvalidPlatformException ex) {
throw new MojoExecutionException("<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 MojoExecutionException("<container><volumes> is not an absolute Unix-style path: " + ex.getInvalidVolume(), ex);
} catch (InvalidFilesModificationTimeException ex) {
throw new MojoExecutionException("<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 MojoExecutionException("<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 MojoExecutionException("error running extension '" + extensionName + "': " + ex.getMessage(), ex);
} catch (IncompatibleBaseImageJavaVersionException ex) {
throw new MojoExecutionException(HelpfulSuggestions.forIncompatibleBaseImageJavaVersionForMaven(ex.getBaseImageMajorJavaVersion(), ex.getProjectMajorJavaVersion()), ex);
} catch (InvalidImageReferenceException ex) {
throw new MojoExecutionException(HelpfulSuggestions.forInvalidImageReference(ex.getInvalidReference()), ex);
} catch (IOException | CacheDirectoryCreationException | MainClassInferenceException | InvalidGlobalConfigException ex) {
throw new MojoExecutionException(ex.getMessage(), ex);
} catch (BuildStepsExecutionException ex) {
throw new MojoExecutionException(ex.getMessage(), ex.getCause());
} catch (ExtraDirectoryNotFoundException ex) {
throw new MojoExecutionException("<extraDirectories><paths> contain \"from\" directory that doesn't exist locally: " + ex.getPath(), ex);
} finally {
tempDirectoryProvider.close();
MojoCommon.finishUpdateChecker(projectProperties, updateCheckFuture);
projectProperties.waitForLoggingThread();
getLog().info("");
}
}
use of com.google.cloud.tools.jib.api.InvalidImageReferenceException in project jib by google.
the class MavenProjectProperties method runPluginExtensions.
@Override
public JibContainerBuilder runPluginExtensions(List<? extends ExtensionConfiguration> extensionConfigs, JibContainerBuilder jibContainerBuilder) throws JibPluginExtensionException {
if (extensionConfigs.isEmpty()) {
log(LogEvent.debug("No Jib plugin extensions configured to load"));
return jibContainerBuilder;
}
// Add the injected extensions at first to prefer them over the ones from JDK service
// loader.
// Extensions might support both approaches (injection and JDK service loader) at the same
// time for compatibility reasons.
List<JibMavenPluginExtension<?>> loadedExtensions = new ArrayList<>(injectedExtensions);
loadedExtensions.addAll(extensionLoader.get());
JibMavenPluginExtension<?> extension = null;
ContainerBuildPlan buildPlan = jibContainerBuilder.toContainerBuildPlan();
try {
for (ExtensionConfiguration config : extensionConfigs) {
extension = findConfiguredExtension(loadedExtensions, config);
log(LogEvent.lifecycle("Running extension: " + config.getExtensionClass()));
buildPlan = runPluginExtension(extension.getExtraConfigType(), extension, config, buildPlan);
// to validate image reference
ImageReference.parse(buildPlan.getBaseImage());
}
return jibContainerBuilder.applyContainerBuildPlan(buildPlan);
} catch (InvalidImageReferenceException ex) {
throw new JibPluginExtensionException(Verify.verifyNotNull(extension).getClass(), "invalid base image reference: " + buildPlan.getBaseImage(), ex);
}
}
use of com.google.cloud.tools.jib.api.InvalidImageReferenceException in project jib by google.
the class PluginConfigurationProcessor method getSkaffoldSyncMap.
/**
* Generate a skaffold syncmap JSON string for an image build configuration.
*
* @param rawConfiguration the raw configuration from the plugin
* @param projectProperties an plugin specific implementation of {@link ProjectProperties}
* @param excludes a set of paths to exclude, directories include in this list will be expanded
* @return new json string representation of the Sync Map
* @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 ExtraDirectoryNotFoundException if the extra directory specified for the build is not
* found
*/
public static String getSkaffoldSyncMap(RawConfiguration rawConfiguration, ProjectProperties projectProperties, Set<Path> excludes) throws IOException, InvalidCreationTimeException, InvalidImageReferenceException, IncompatibleBaseImageJavaVersionException, InvalidPlatformException, InvalidContainerVolumeException, MainClassInferenceException, InvalidAppRootException, InvalidWorkingDirectoryException, InvalidFilesModificationTimeException, InvalidContainerizingModeException, ExtraDirectoryNotFoundException {
JibContainerBuilder jibContainerBuilder = processCommonConfiguration(rawConfiguration, ignored -> Optional.empty(), projectProperties);
SkaffoldSyncMapTemplate syncMap = new SkaffoldSyncMapTemplate();
// since jib has already expanded out directories after processing everything, we just
// ignore directories and provide only files to watch
Set<Path> excludesExpanded = getAllFiles(excludes);
for (LayerObject layerObject : jibContainerBuilder.toContainerBuildPlan().getLayers()) {
Verify.verify(layerObject instanceof FileEntriesLayer, "layer types other than FileEntriesLayer not yet supported in build plan layers");
FileEntriesLayer layer = (FileEntriesLayer) layerObject;
if (CONST_LAYERS.contains(layer.getName())) {
continue;
}
if (GENERATED_LAYERS.contains(layer.getName())) {
layer.getEntries().stream().filter(layerEntry -> Files.isRegularFile(layerEntry.getSourceFile())).filter(layerEntry -> !excludesExpanded.contains(layerEntry.getSourceFile().toAbsolutePath())).forEach(syncMap::addGenerated);
} else {
// this is a direct layer
layer.getEntries().stream().filter(layerEntry -> Files.isRegularFile(layerEntry.getSourceFile())).filter(layerEntry -> !excludesExpanded.contains(layerEntry.getSourceFile().toAbsolutePath())).forEach(syncMap::addDirect);
}
}
return syncMap.getJsonString();
}
Aggregations