use of io.quarkus.deployment.pkg.builditem.JarBuildItem in project quarkus by quarkusio.
the class JarResultBuildStep method buildLegacyThinJar.
private JarBuildItem buildLegacyThinJar(CurateOutcomeBuildItem curateOutcomeBuildItem, OutputTargetBuildItem outputTargetBuildItem, TransformedClassesBuildItem transformedClasses, ApplicationArchivesBuildItem applicationArchivesBuildItem, PackageConfig packageConfig, ApplicationInfoBuildItem applicationInfo, List<GeneratedClassBuildItem> generatedClasses, List<GeneratedResourceBuildItem> generatedResources, MainClassBuildItem mainClassBuildItem, ClassLoadingConfig classLoadingConfig) throws Exception {
Path runnerJar = outputTargetBuildItem.getOutputDirectory().resolve(outputTargetBuildItem.getBaseName() + packageConfig.runnerSuffix + ".jar");
Path libDir = outputTargetBuildItem.getOutputDirectory().resolve("lib");
Files.deleteIfExists(runnerJar);
IoUtils.createOrEmptyDir(libDir);
try (FileSystem runnerZipFs = ZipUtils.newZip(runnerJar)) {
log.info("Building thin jar: " + runnerJar);
doLegacyThinJarGeneration(curateOutcomeBuildItem, outputTargetBuildItem, transformedClasses, applicationArchivesBuildItem, applicationInfo, packageConfig, generatedResources, libDir, generatedClasses, runnerZipFs, mainClassBuildItem, classLoadingConfig);
}
runnerJar.toFile().setReadable(true, false);
return new JarBuildItem(runnerJar, null, libDir, PackageConfig.LEGACY_JAR, suffixToClassifier(packageConfig.runnerSuffix));
}
use of io.quarkus.deployment.pkg.builditem.JarBuildItem in project quarkus by quarkusio.
the class AugmentActionImpl method createProductionApplication.
@Override
public AugmentResult createProductionApplication() {
if (launchMode != LaunchMode.NORMAL) {
throw new IllegalStateException("Can only create a production application when using NORMAL launch mode");
}
ClassLoader classLoader = curatedApplication.createDeploymentClassLoader();
BuildResult result = runAugment(true, Collections.emptySet(), null, classLoader, ArtifactResultBuildItem.class, DeploymentResultBuildItem.class);
writeDebugSourceFile(result);
JarBuildItem jarBuildItem = result.consumeOptional(JarBuildItem.class);
NativeImageBuildItem nativeImageBuildItem = result.consumeOptional(NativeImageBuildItem.class);
List<ArtifactResultBuildItem> artifactResultBuildItems = result.consumeMulti(ArtifactResultBuildItem.class);
BuildSystemTargetBuildItem buildSystemTargetBuildItem = result.consume(BuildSystemTargetBuildItem.class);
// this depends on the fact that the order in which we can obtain MultiBuildItems is the same as they are produced
// we want to write result of the final artifact created
ArtifactResultBuildItem lastResult = artifactResultBuildItems.get(artifactResultBuildItems.size() - 1);
writeArtifactResultMetadataFile(buildSystemTargetBuildItem, lastResult);
return new AugmentResult(artifactResultBuildItems.stream().map(a -> new ArtifactResult(a.getPath(), a.getType(), a.getMetadata())).collect(Collectors.toList()), jarBuildItem != null ? jarBuildItem.toJarResult() : null, nativeImageBuildItem != null ? nativeImageBuildItem.getPath() : null);
}
use of io.quarkus.deployment.pkg.builditem.JarBuildItem in project quarkus by quarkusio.
the class S2iProcessor method s2iRequirementsJvm.
@BuildStep(onlyIf = { IsNormalNotRemoteDev.class, S2iBuild.class }, onlyIfNot = NativeBuild.class)
public void s2iRequirementsJvm(S2iConfig s2iConfig, CurateOutcomeBuildItem curateOutcomeBuildItem, OutputTargetBuildItem out, PackageConfig packageConfig, JarBuildItem jarBuildItem, CompiledJavaVersionBuildItem compiledJavaVersion, BuildProducer<KubernetesEnvBuildItem> envProducer, BuildProducer<BaseImageInfoBuildItem> builderImageProducer, BuildProducer<KubernetesCommandBuildItem> commandProducer) {
final Collection<ResolvedDependency> appDeps = curateOutcomeBuildItem.getApplicationModel().getRuntimeDependencies();
String outputJarFileName = jarBuildItem.getPath().getFileName().toString();
String classpath = appDeps.stream().map(d -> d.getGroupId() + "." + d.getResolvedPaths().getSinglePath().getFileName()).map(s -> concatUnixPaths(s2iConfig.jarDirectory, "lib", s)).collect(Collectors.joining(":"));
String jarFileName = s2iConfig.jarFileName.orElse(outputJarFileName);
String jarDirectory = s2iConfig.jarDirectory;
String pathToJar = concatUnixPaths(jarDirectory, jarFileName);
String baseJvmImage = s2iConfig.baseJvmImage.orElse(S2iConfig.getDefaultJvmImage(compiledJavaVersion.getJavaVersion()));
builderImageProducer.produce(new BaseImageInfoBuildItem(baseJvmImage));
Optional<S2iBaseJavaImage> baseImage = S2iBaseJavaImage.findMatching(baseJvmImage);
baseImage.ifPresent(b -> {
envProducer.produce(KubernetesEnvBuildItem.createSimpleVar(b.getJarEnvVar(), pathToJar, OPENSHIFT));
envProducer.produce(KubernetesEnvBuildItem.createSimpleVar(b.getJarLibEnvVar(), concatUnixPaths(jarDirectory, "lib"), OPENSHIFT));
envProducer.produce(KubernetesEnvBuildItem.createSimpleVar(b.getClasspathEnvVar(), classpath, OPENSHIFT));
envProducer.produce(KubernetesEnvBuildItem.createSimpleVar(b.getJvmOptionsEnvVar(), String.join(" ", s2iConfig.getEffectiveJvmArguments()), OPENSHIFT));
});
if (!baseImage.isPresent()) {
List<String> cmd = new ArrayList<>();
cmd.add("java");
cmd.addAll(s2iConfig.getEffectiveJvmArguments());
cmd.addAll(Arrays.asList("-jar", pathToJar, "-cp", classpath));
commandProducer.produce(KubernetesCommandBuildItem.command(cmd));
}
}
use of io.quarkus.deployment.pkg.builditem.JarBuildItem 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 io.quarkus.deployment.pkg.builditem.JarBuildItem in project quarkus by quarkusio.
the class S2iProcessor method s2iBuildFromJar.
@BuildStep(onlyIf = { IsNormalNotRemoteDev.class, S2iBuild.class }, onlyIfNot = NativeBuild.class)
public void s2iBuildFromJar(S2iConfig s2iConfig, ContainerImageConfig containerImageConfig, KubernetesClientBuildItem kubernetesClient, ContainerImageInfoBuildItem containerImage, ArchiveRootBuildItem archiveRoot, OutputTargetBuildItem out, PackageConfig packageConfig, List<GeneratedFileSystemResourceBuildItem> generatedResources, Optional<ContainerImageBuildRequestBuildItem> buildRequest, Optional<ContainerImagePushRequestBuildItem> pushRequest, BuildProducer<ArtifactResultBuildItem> artifactResultProducer, BuildProducer<ContainerImageBuilderBuildItem> containerImageBuilder, // used to ensure that the jar has been built
JarBuildItem jar) {
if (containerImageConfig.isBuildExplicitlyDisabled()) {
return;
}
if (!containerImageConfig.isBuildExplicitlyEnabled() && !containerImageConfig.isPushExplicitlyEnabled() && !buildRequest.isPresent() && !pushRequest.isPresent()) {
return;
}
Optional<GeneratedFileSystemResourceBuildItem> openshiftYml = generatedResources.stream().filter(r -> r.getName().endsWith("kubernetes" + File.separator + "openshift.yml")).findFirst();
if (openshiftYml.isEmpty()) {
LOG.warn("No Openshift manifests were generated so no s2i process will be taking place");
return;
}
String namespace = Optional.ofNullable(kubernetesClient.getClient().getNamespace()).orElse("default");
LOG.info("Performing s2i binary build with jar on server: " + kubernetesClient.getClient().getMasterUrl() + " in namespace:" + namespace + ".");
createContainerImage(kubernetesClient, openshiftYml.get(), s2iConfig, out.getOutputDirectory(), jar.getPath(), out.getOutputDirectory().resolve("lib"));
artifactResultProducer.produce(new ArtifactResultBuildItem(null, "jar-container", Collections.emptyMap()));
containerImageBuilder.produce(new ContainerImageBuilderBuildItem(S2I));
}
Aggregations