use of io.quarkus.container.spi.BaseImageInfoBuildItem in project quarkus by quarkusio.
the class S2iProcessor method s2iRequirementsNative.
@BuildStep(onlyIf = { IsNormalNotRemoteDev.class, S2iBuild.class, NativeBuild.class })
public void s2iRequirementsNative(S2iConfig s2iConfig, CurateOutcomeBuildItem curateOutcomeBuildItem, OutputTargetBuildItem out, PackageConfig packageConfig, NativeImageBuildItem nativeImage, BuildProducer<KubernetesEnvBuildItem> envProducer, BuildProducer<BaseImageInfoBuildItem> builderImageProducer, BuildProducer<KubernetesCommandBuildItem> commandProducer) {
boolean usingDefaultBuilder = ImageUtil.getRepository(S2iConfig.DEFAULT_BASE_NATIVE_IMAGE).equals(ImageUtil.getRepository(s2iConfig.baseNativeImage));
String outputNativeBinaryFileName = nativeImage.getPath().getFileName().toString();
String nativeBinaryFileName = null;
// To make things easier for the user, we need to handle it.
if (usingDefaultBuilder && !s2iConfig.nativeBinaryFileName.isPresent()) {
nativeBinaryFileName = S2iConfig.DEFAULT_NATIVE_TARGET_FILENAME;
} else {
nativeBinaryFileName = s2iConfig.nativeBinaryFileName.orElse(outputNativeBinaryFileName);
}
String pathToNativeBinary = concatUnixPaths(s2iConfig.nativeBinaryDirectory, nativeBinaryFileName);
builderImageProducer.produce(new BaseImageInfoBuildItem(s2iConfig.baseNativeImage));
Optional<S2iBaseNativeImage> baseImage = S2iBaseNativeImage.findMatching(s2iConfig.baseNativeImage);
List<String> nativeArguments = s2iConfig.nativeArguments.orElse(Collections.emptyList());
baseImage.ifPresent(b -> {
envProducer.produce(KubernetesEnvBuildItem.createSimpleVar(b.getHomeDirEnvVar(), s2iConfig.nativeBinaryDirectory, OPENSHIFT));
envProducer.produce(KubernetesEnvBuildItem.createSimpleVar(b.getOptsEnvVar(), String.join(" ", nativeArguments), OPENSHIFT));
});
if (!baseImage.isPresent()) {
commandProducer.produce(KubernetesCommandBuildItem.commandWithArgs(pathToNativeBinary, nativeArguments));
}
}
use of io.quarkus.container.spi.BaseImageInfoBuildItem 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.container.spi.BaseImageInfoBuildItem in project quarkus by quarkusio.
the class OpenshiftProcessor method openshiftRequirementsJvm.
@BuildStep(onlyIf = { IsNormalNotRemoteDev.class, OpenshiftBuild.class }, onlyIfNot = NativeBuild.class)
public void openshiftRequirementsJvm(OpenshiftConfig openshiftConfig, S2iConfig s2iConfig, CurateOutcomeBuildItem curateOutcomeBuildItem, OutputTargetBuildItem out, PackageConfig packageConfig, JarBuildItem jarBuildItem, CompiledJavaVersionBuildItem compiledJavaVersion, BuildProducer<DecoratorBuildItem> decorator, BuildProducer<KubernetesEnvBuildItem> envProducer, BuildProducer<BaseImageInfoBuildItem> builderImageProducer, BuildProducer<KubernetesCommandBuildItem> commandProducer) {
OpenshiftConfig config = mergeConfig(openshiftConfig, s2iConfig);
String outputJarFileName = jarBuildItem.getPath().getFileName().toString();
String jarFileName = config.jarFileName.orElse(outputJarFileName);
String baseJvmImage = config.baseJvmImage.orElse(OpenshiftConfig.getDefaultJvmImage(compiledJavaVersion.getJavaVersion()));
builderImageProducer.produce(new BaseImageInfoBuildItem(baseJvmImage));
Optional<OpenshiftBaseJavaImage> baseImage = OpenshiftBaseJavaImage.findMatching(baseJvmImage);
if (config.buildStrategy == BuildStrategy.BINARY) {
// Jar directory priorities:
// 1. explictly specified by the user.
// 2. detected via OpenshiftBaseJavaImage
// 3. fallback value
String jarDirectory = config.jarDirectory.orElse(baseImage.map(i -> i.getJarDirectory()).orElse(config.FALLBACK_JAR_DIRECTORY));
String pathToJar = concatUnixPaths(jarDirectory, jarFileName);
// If the image is known, we can define env vars for classpath, jar, lib etc.
baseImage.ifPresent(b -> {
envProducer.produce(KubernetesEnvBuildItem.createSimpleVar(b.getJarEnvVar(), pathToJar, null));
envProducer.produce(KubernetesEnvBuildItem.createSimpleVar(b.getJvmOptionsEnvVar(), String.join(" ", config.getEffectiveJvmArguments()), null));
});
// In all other cases its the responsibility of the image to set those up correctly.
if (!baseImage.isPresent()) {
List<String> cmd = new ArrayList<>();
cmd.add("java");
cmd.addAll(config.getEffectiveJvmArguments());
cmd.addAll(Arrays.asList("-jar", pathToJar));
envProducer.produce(KubernetesEnvBuildItem.createSimpleVar("JAVA_APP_JAR", pathToJar, null));
commandProducer.produce(KubernetesCommandBuildItem.command(cmd));
}
}
}
use of io.quarkus.container.spi.BaseImageInfoBuildItem in project quarkus by quarkusio.
the class OpenshiftProcessor method openshiftRequirementsNative.
@BuildStep(onlyIf = { IsNormalNotRemoteDev.class, OpenshiftBuild.class, NativeBuild.class })
public void openshiftRequirementsNative(OpenshiftConfig openshiftConfig, S2iConfig s2iConfig, CurateOutcomeBuildItem curateOutcomeBuildItem, OutputTargetBuildItem out, PackageConfig packageConfig, NativeImageBuildItem nativeImage, BuildProducer<KubernetesEnvBuildItem> envProducer, BuildProducer<BaseImageInfoBuildItem> builderImageProducer, BuildProducer<KubernetesCommandBuildItem> commandProducer) {
OpenshiftConfig config = mergeConfig(openshiftConfig, s2iConfig);
boolean usingDefaultBuilder = ImageUtil.getRepository(OpenshiftConfig.DEFAULT_BASE_NATIVE_IMAGE).equals(ImageUtil.getRepository(config.baseNativeImage));
String outputNativeBinaryFileName = nativeImage.getPath().getFileName().toString();
String nativeBinaryFileName = null;
// To make things easier for the user, we need to handle it.
if (usingDefaultBuilder && !config.nativeBinaryFileName.isPresent()) {
nativeBinaryFileName = OpenshiftConfig.DEFAULT_NATIVE_TARGET_FILENAME;
} else {
nativeBinaryFileName = config.nativeBinaryFileName.orElse(outputNativeBinaryFileName);
}
if (config.buildStrategy == BuildStrategy.BINARY) {
builderImageProducer.produce(new BaseImageInfoBuildItem(config.baseNativeImage));
Optional<OpenshiftBaseNativeImage> baseImage = OpenshiftBaseNativeImage.findMatching(config.baseNativeImage);
// Native binary directory priorities:
// 1. explictly specified by the user.
// 2. detected via OpenshiftBaseNativeImage
// 3. fallback value
String nativeBinaryDirectory = config.nativeBinaryDirectory.orElse(baseImage.map(i -> i.getNativeBinaryDirectory()).orElse(config.FALLBAC_NATIVE_BINARY_DIRECTORY));
String pathToNativeBinary = concatUnixPaths(nativeBinaryDirectory, nativeBinaryFileName);
baseImage.ifPresent(b -> {
envProducer.produce(KubernetesEnvBuildItem.createSimpleVar(b.getHomeDirEnvVar(), nativeBinaryDirectory, OPENSHIFT));
envProducer.produce(KubernetesEnvBuildItem.createSimpleVar(b.getOptsEnvVar(), String.join(" ", config.nativeArguments), OPENSHIFT));
});
if (!baseImage.isPresent()) {
commandProducer.produce(KubernetesCommandBuildItem.commandWithArgs(pathToNativeBinary, config.nativeArguments));
}
}
}
Aggregations