use of com.google.cloud.tools.jib.api.InvalidImageReferenceException 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.InvalidImageReferenceException in project fabric8-maven-plugin by fabric8io.
the class JibServiceUtil method jibPush.
/**
* @param imageConfiguration ImageConfiguration
* @param project MavenProject
* @param registryConfig RegistryService.RegistryConfig
* @param outputDirectory Target Output Directory
* @param log Logger
* @throws MojoExecutionException
*/
public static void jibPush(ImageConfiguration imageConfiguration, MavenProject project, RegistryService.RegistryConfig registryConfig, String outputDirectory, Logger log) throws MojoExecutionException {
BuildImageConfiguration buildImageConfiguration = imageConfiguration.getBuildConfiguration();
String outputDir = prepareAbsoluteOutputDirPath(EMPTY_STRING, project, outputDirectory).getAbsolutePath();
String imageName = imageNameFromImageConfiguration(imageConfiguration);
try {
String imageTarName = ImageReference.parse(imageName).toString().concat(TAR_POSTFIX);
TarImage baseImage = TarImage.at(Paths.get(outputDir, imageTarName));
String configuredRegistry = EnvUtil.firstRegistryOf((new ImageName(imageConfiguration.getName())).getRegistry(), imageConfiguration.getRegistry(), registryConfig.getRegistry());
Credential pushCredential = getRegistryCredentials(configuredRegistry, registryConfig);
final List<String> tags = buildImageConfiguration.getTags();
for (String tag : appendOriginalImageNameTagIfApplicable(tags, imageName)) {
final String targetImage = new ImageName(imageConfiguration.getName(), tag).getFullName();
pushImage(baseImage, targetImage, pushCredential, log);
}
} catch (InvalidImageReferenceException | IllegalStateException e) {
log.error("Exception occurred while pushing the image: %s", imageConfiguration.getName());
throw new MojoExecutionException(e.getMessage(), e);
} catch (InterruptedException e) {
log.error("Thread interrupted", e);
Thread.currentThread().interrupt();
}
}
use of com.google.cloud.tools.jib.api.InvalidImageReferenceException 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.InvalidImageReferenceException in project quarkus by quarkusio.
the class JibProcessor method createContainerBuilderFromLegacyJar.
private JibContainerBuilder createContainerBuilderFromLegacyJar(String baseJvmImage, JibConfig jibConfig, ContainerImageConfig containerImageConfig, JarBuildItem sourceJarBuildItem, OutputTargetBuildItem outputTargetBuildItem, MainClassBuildItem mainClassBuildItem, List<ContainerImageLabelBuildItem> containerImageLabels) {
try {
// not ideal since this has been previously zipped - we would like to just reuse it
Path classesDir = outputTargetBuildItem.getOutputDirectory().resolve("jib");
ZipUtils.unzip(sourceJarBuildItem.getPath(), classesDir);
JavaContainerBuilder javaContainerBuilder = JavaContainerBuilder.from(toRegistryImage(ImageReference.parse(baseJvmImage), jibConfig.baseRegistryUsername, jibConfig.baseRegistryPassword)).addResources(classesDir, IS_CLASS_PREDICATE.negate()).addClasses(classesDir, IS_CLASS_PREDICATE);
// when there is no custom entry point, we just set everything up for a regular java run
if (!jibConfig.jvmEntrypoint.isPresent()) {
javaContainerBuilder.addJvmFlags(determineEffectiveJvmArguments(jibConfig, Optional.empty())).setMainClass(mainClassBuildItem.getClassName());
}
if (sourceJarBuildItem.getLibraryDir() != null) {
try (Stream<Path> dependenciesPaths = Files.list(sourceJarBuildItem.getLibraryDir())) {
javaContainerBuilder.addDependencies(dependenciesPaths.filter(p -> Files.isRegularFile(p) && p.getFileName().toString().endsWith(".jar")).sorted(Comparator.comparing(Path::getFileName)).collect(Collectors.toList()));
}
}
JibContainerBuilder jibContainerBuilder = javaContainerBuilder.toContainerBuilder().setEnvironment(getEnvironmentVariables(jibConfig)).setLabels(allLabels(jibConfig, containerImageConfig, containerImageLabels));
if (jibConfig.useCurrentTimestamp) {
jibContainerBuilder.setCreationTime(Instant.now());
}
if (jibConfig.jvmEntrypoint.isPresent()) {
jibContainerBuilder.setEntrypoint(jibConfig.jvmEntrypoint.get());
}
return jibContainerBuilder;
} catch (IOException e) {
throw new UncheckedIOException(e);
} catch (InvalidImageReferenceException e) {
throw new RuntimeException(e);
}
}
use of com.google.cloud.tools.jib.api.InvalidImageReferenceException in project jib by GoogleContainerTools.
the class BuildDockerMojo method execute.
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
checkJibVersion();
if (MojoCommon.shouldSkipJibExecution(this)) {
return;
}
Path dockerExecutable = getDockerClientExecutable();
boolean isDockerInstalled = dockerExecutable == null ? DockerClient.isDefaultDockerInstalled() : DockerClient.isDockerInstalled(dockerExecutable);
if (!isDockerInstalled) {
throw new MojoExecutionException(HelpfulSuggestions.forDockerNotInstalled(HELPFUL_SUGGESTIONS_PREFIX));
}
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.createJibBuildRunnerForDockerDaemonImage(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("");
}
}
Aggregations