use of com.google.cloud.tools.jib.api.InvalidImageReferenceException in project jib by google.
the class BuildTarTask method buildTar.
/**
* Task Action, builds an image to tar file.
*
* @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 buildTar() throws BuildStepsExecutionException, IOException, CacheDirectoryCreationException, MainClassInferenceException, InvalidGlobalConfigException {
// Asserts required @Input parameters are not null.
Preconditions.checkNotNull(jibExtension);
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.createJibBuildRunnerForTarImage(new GradleRawConfiguration(jibExtension), ignored -> 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.api.InvalidImageReferenceException in project docker-maven-plugin by fabric8io.
the class JibServiceUtil method pushImage.
private static void pushImage(TarImage baseImage, String targetImageName, Credential credential, Logger logger) throws InterruptedException {
final ExecutorService jibBuildExecutor = Executors.newCachedThreadPool();
try {
submitPushToJib(baseImage, getRegistryImage(targetImageName, credential), jibBuildExecutor, logger);
} catch (RegistryException | CacheDirectoryCreationException | InvalidImageReferenceException | IOException | ExecutionException e) {
logger.error("Exception occurred while pushing the image: %s, %s", targetImageName, e.getMessage());
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.InvalidImageReferenceException in project fabric8-maven-plugin by fabric8io.
the class JibServiceUtil method containerFromImageConfiguration.
static JibContainerBuilder containerFromImageConfiguration(ImageConfiguration imageConfiguration) throws InvalidImageReferenceException {
final Optional<BuildImageConfiguration> bic = Optional.ofNullable(Objects.requireNonNull(imageConfiguration).getBuildConfiguration());
final JibContainerBuilder containerBuilder = Jib.from(getBaseImage(imageConfiguration)).setFormat(ImageFormat.OCI);
bic.map(BuildImageConfiguration::getEntryPoint).map(Arguments::asStrings).ifPresent(containerBuilder::setEntrypoint);
bic.map(BuildImageConfiguration::getEnv).ifPresent(containerBuilder::setEnvironment);
bic.map(BuildImageConfiguration::getPorts).map(List::stream).map(s -> s.map(Integer::parseInt).map(Port::tcp)).map(s -> s.collect(Collectors.toSet())).ifPresent(containerBuilder::setExposedPorts);
bic.map(BuildImageConfiguration::getLabels).map(Map::entrySet).ifPresent(labels -> labels.forEach(l -> containerBuilder.addLabel(l.getKey(), l.getValue())));
bic.map(BuildImageConfiguration::getCmd).map(Arguments::asStrings).ifPresent(containerBuilder::setProgramArguments);
bic.map(BuildImageConfiguration::getUser).ifPresent(containerBuilder::setUser);
bic.map(BuildImageConfiguration::getVolumes).map(List::stream).map(s -> s.map(AbsoluteUnixPath::get)).map(s -> s.collect(Collectors.toSet())).ifPresent(containerBuilder::setVolumes);
bic.map(BuildImageConfiguration::getWorkdir).filter(((Predicate<String>) String::isEmpty).negate()).map(AbsoluteUnixPath::get).ifPresent(containerBuilder::setWorkingDirectory);
return containerBuilder;
}
use of com.google.cloud.tools.jib.api.InvalidImageReferenceException in project jib by google.
the class PluginConfigurationProcessorTest method testEntrypoint_extraClasspathNonWarPackaging.
@Test
public void testEntrypoint_extraClasspathNonWarPackaging() throws IOException, InvalidImageReferenceException, MainClassInferenceException, InvalidAppRootException, InvalidWorkingDirectoryException, InvalidPlatformException, InvalidContainerVolumeException, IncompatibleBaseImageJavaVersionException, NumberFormatException, InvalidContainerizingModeException, InvalidFilesModificationTimeException, InvalidCreationTimeException, ExtraDirectoryNotFoundException {
when(rawConfiguration.getExtraClasspath()).thenReturn(Collections.singletonList("/foo"));
when(projectProperties.isWarProject()).thenReturn(false);
ContainerBuildPlan buildPlan = processCommonConfiguration();
assertThat(buildPlan.getEntrypoint()).containsExactly("java", "-cp", "/foo:/app/resources:/app/classes:/app/libs/*", "java.lang.Object").inOrder();
ArgumentMatcher<LogEvent> isLogWarn = logEvent -> logEvent.getLevel() == LogEvent.Level.WARN;
verify(logger, never()).accept(argThat(isLogWarn));
}
use of com.google.cloud.tools.jib.api.InvalidImageReferenceException in project jib by google.
the class PluginConfigurationProcessorTest method testPluginConfigurationProcessor_extraDirectory.
@Test
public void testPluginConfigurationProcessor_extraDirectory() throws URISyntaxException, InvalidContainerVolumeException, MainClassInferenceException, InvalidAppRootException, IOException, IncompatibleBaseImageJavaVersionException, InvalidWorkingDirectoryException, InvalidPlatformException, InvalidImageReferenceException, NumberFormatException, InvalidContainerizingModeException, InvalidFilesModificationTimeException, InvalidCreationTimeException, ExtraDirectoryNotFoundException {
Path extraDirectory = Paths.get(Resources.getResource("core/layer").toURI());
Mockito.<List<?>>when(rawConfiguration.getExtraDirectories()).thenReturn(Arrays.asList(new TestExtraDirectoriesConfiguration(extraDirectory)));
when(rawConfiguration.getExtraDirectoryPermissions()).thenReturn(ImmutableMap.of("/target/dir/foo", FilePermissions.fromOctalString("123")));
ContainerBuildPlan buildPlan = processCommonConfiguration();
List<FileEntry> extraFiles = getLayerEntries(buildPlan, "extra files");
assertThat(extraFiles).comparingElementsUsing(SOURCE_FILE_OF).containsExactly(extraDirectory.resolve("a"), extraDirectory.resolve("a/b"), extraDirectory.resolve("a/b/bar"), extraDirectory.resolve("c"), extraDirectory.resolve("c/cat"), extraDirectory.resolve("foo"));
assertThat(extraFiles).comparingElementsUsing(EXTRACTION_PATH_OF).containsExactly("/target/dir/a", "/target/dir/a/b", "/target/dir/a/b/bar", "/target/dir/c", "/target/dir/c/cat", "/target/dir/foo");
Optional<FileEntry> fooEntry = extraFiles.stream().filter(layerEntry -> layerEntry.getExtractionPath().equals(AbsoluteUnixPath.get("/target/dir/foo"))).findFirst();
assertThat(fooEntry).isPresent();
assertThat(fooEntry.get().getPermissions().toOctalString()).isEqualTo("123");
}
Aggregations