Search in sources :

Example 1 with BaseImageInfoBuildItem

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));
    }
}
Also used : BaseImageInfoBuildItem(io.quarkus.container.spi.BaseImageInfoBuildItem) BuildStep(io.quarkus.deployment.annotations.BuildStep)

Example 2 with BaseImageInfoBuildItem

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));
    }
}
Also used : Arrays(java.util.Arrays) KubernetesClientBuildItem(io.quarkus.kubernetes.client.spi.KubernetesClientBuildItem) KubernetesEnvBuildItem(io.quarkus.kubernetes.spi.KubernetesEnvBuildItem) ContainerImageBuilderBuildItem(io.quarkus.container.spi.ContainerImageBuilderBuildItem) LogWatch(io.fabric8.kubernetes.client.dsl.LogWatch) BuildProducer(io.quarkus.deployment.annotations.BuildProducer) ArchiveRootBuildItem(io.quarkus.deployment.builditem.ArchiveRootBuildItem) ByteArrayInputStream(java.io.ByteArrayInputStream) Map(java.util.Map) Build(io.fabric8.openshift.api.model.Build) KubernetesCommandBuildItem(io.quarkus.kubernetes.spi.KubernetesCommandBuildItem) Path(java.nio.file.Path) IsNormalNotRemoteDev(io.quarkus.deployment.IsNormalNotRemoteDev) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException) NativeImageBuildItem(io.quarkus.deployment.pkg.builditem.NativeImageBuildItem) Predicate(java.util.function.Predicate) ContainerImagePushRequestBuildItem(io.quarkus.container.spi.ContainerImagePushRequestBuildItem) JarBuildItem(io.quarkus.deployment.pkg.builditem.JarBuildItem) Collection(java.util.Collection) ContainerImageConfig(io.quarkus.container.image.deployment.ContainerImageConfig) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Collectors(java.util.stream.Collectors) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) Executors(java.util.concurrent.Executors) PackageConfig(io.quarkus.deployment.pkg.PackageConfig) ContainerImageInfoBuildItem(io.quarkus.container.spi.ContainerImageInfoBuildItem) Config(io.fabric8.kubernetes.client.Config) List(java.util.List) Stream(java.util.stream.Stream) ResolvedDependency(io.quarkus.maven.dependency.ResolvedDependency) Optional(java.util.Optional) Secret(io.fabric8.kubernetes.api.model.Secret) AvailableContainerImageExtensionBuildItem(io.quarkus.container.spi.AvailableContainerImageExtensionBuildItem) Logger(org.jboss.logging.Logger) KubernetesClientErrorHandler(io.quarkus.kubernetes.client.deployment.KubernetesClientErrorHandler) CurateOutcomeBuildItem(io.quarkus.deployment.pkg.builditem.CurateOutcomeBuildItem) CompiledJavaVersionBuildItem(io.quarkus.deployment.pkg.builditem.CompiledJavaVersionBuildItem) StandardCopyOption(java.nio.file.StandardCopyOption) ArrayList(java.util.ArrayList) ImageUtil(io.quarkus.container.image.deployment.util.ImageUtil) BuildStep(io.quarkus.deployment.annotations.BuildStep) BaseImageInfoBuildItem(io.quarkus.container.spi.BaseImageInfoBuildItem) ImageStream(io.fabric8.openshift.api.model.ImageStream) KubernetesList(io.fabric8.kubernetes.api.model.KubernetesList) ContainerImageBuildRequestBuildItem(io.quarkus.container.spi.ContainerImageBuildRequestBuildItem) Files(java.nio.file.Files) Executor(java.util.concurrent.Executor) ArtifactResultBuildItem(io.quarkus.deployment.pkg.builditem.ArtifactResultBuildItem) IOException(java.io.IOException) Serialization(io.dekorate.utils.Serialization) OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) InputStreamReader(java.io.InputStreamReader) NativeBuild(io.quarkus.deployment.pkg.steps.NativeBuild) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) Clients(io.dekorate.utils.Clients) BuildConfig(io.fabric8.openshift.api.model.BuildConfig) OutputTargetBuildItem(io.quarkus.deployment.pkg.builditem.OutputTargetBuildItem) Closeable(java.io.Closeable) GeneratedFileSystemResourceBuildItem(io.quarkus.deployment.builditem.GeneratedFileSystemResourceBuildItem) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) BufferedReader(java.io.BufferedReader) Collections(java.util.Collections) BaseImageInfoBuildItem(io.quarkus.container.spi.BaseImageInfoBuildItem) ResolvedDependency(io.quarkus.maven.dependency.ResolvedDependency) ArrayList(java.util.ArrayList) BuildStep(io.quarkus.deployment.annotations.BuildStep)

Example 3 with BaseImageInfoBuildItem

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));
        }
    }
}
Also used : BaseImageInfoBuildItem(io.quarkus.container.spi.BaseImageInfoBuildItem) ArrayList(java.util.ArrayList) BuildStep(io.quarkus.deployment.annotations.BuildStep)

Example 4 with BaseImageInfoBuildItem

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));
        }
    }
}
Also used : BaseImageInfoBuildItem(io.quarkus.container.spi.BaseImageInfoBuildItem) BuildStep(io.quarkus.deployment.annotations.BuildStep)

Aggregations

BaseImageInfoBuildItem (io.quarkus.container.spi.BaseImageInfoBuildItem)4 BuildStep (io.quarkus.deployment.annotations.BuildStep)4 Clients (io.dekorate.utils.Clients)1 Serialization (io.dekorate.utils.Serialization)1 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)1 KubernetesList (io.fabric8.kubernetes.api.model.KubernetesList)1 Secret (io.fabric8.kubernetes.api.model.Secret)1 Config (io.fabric8.kubernetes.client.Config)1 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)1 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)1 LogWatch (io.fabric8.kubernetes.client.dsl.LogWatch)1 Build (io.fabric8.openshift.api.model.Build)1 BuildConfig (io.fabric8.openshift.api.model.BuildConfig)1 ImageStream (io.fabric8.openshift.api.model.ImageStream)1 OpenShiftClient (io.fabric8.openshift.client.OpenShiftClient)1 ContainerImageConfig (io.quarkus.container.image.deployment.ContainerImageConfig)1 ImageUtil (io.quarkus.container.image.deployment.util.ImageUtil)1 AvailableContainerImageExtensionBuildItem (io.quarkus.container.spi.AvailableContainerImageExtensionBuildItem)1 ContainerImageBuildRequestBuildItem (io.quarkus.container.spi.ContainerImageBuildRequestBuildItem)1 ContainerImageBuilderBuildItem (io.quarkus.container.spi.ContainerImageBuilderBuildItem)1