Search in sources :

Example 1 with NativeImageBuildItem

use of io.quarkus.deployment.pkg.builditem.NativeImageBuildItem 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);
}
Also used : BuildResult(io.quarkus.builder.BuildResult) JarBuildItem(io.quarkus.deployment.pkg.builditem.JarBuildItem) QuarkusClassLoader(io.quarkus.bootstrap.classloading.QuarkusClassLoader) ArtifactResultBuildItem(io.quarkus.deployment.pkg.builditem.ArtifactResultBuildItem) BuildSystemTargetBuildItem(io.quarkus.deployment.pkg.builditem.BuildSystemTargetBuildItem) AugmentResult(io.quarkus.bootstrap.app.AugmentResult) NativeImageBuildItem(io.quarkus.deployment.pkg.builditem.NativeImageBuildItem) ArtifactResult(io.quarkus.bootstrap.app.ArtifactResult)

Example 2 with NativeImageBuildItem

use of io.quarkus.deployment.pkg.builditem.NativeImageBuildItem in project quarkus by quarkusio.

the class S2iProcessor method s2iBuildFromNative.

@BuildStep(onlyIf = { IsNormalNotRemoteDev.class, S2iBuild.class, NativeBuild.class })
public void s2iBuildFromNative(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, NativeImageBuildItem nativeImage) {
    if (containerImageConfig.isBuildExplicitlyDisabled()) {
        return;
    }
    if (!containerImageConfig.isBuildExplicitlyEnabled() && !containerImageConfig.isPushExplicitlyEnabled() && !buildRequest.isPresent() && !pushRequest.isPresent()) {
        return;
    }
    String namespace = Optional.ofNullable(kubernetesClient.getClient().getNamespace()).orElse("default");
    LOG.info("Performing s2i binary build with native image on server: " + kubernetesClient.getClient().getMasterUrl() + " in namespace:" + namespace + ".");
    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;
    }
    createContainerImage(kubernetesClient, openshiftYml.get(), s2iConfig, out.getOutputDirectory(), nativeImage.getPath());
    artifactResultProducer.produce(new ArtifactResultBuildItem(null, "native-container", Collections.emptyMap()));
    containerImageBuilder.produce(new ContainerImageBuilderBuildItem(S2I));
}
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) ContainerImageBuilderBuildItem(io.quarkus.container.spi.ContainerImageBuilderBuildItem) ArtifactResultBuildItem(io.quarkus.deployment.pkg.builditem.ArtifactResultBuildItem) GeneratedFileSystemResourceBuildItem(io.quarkus.deployment.builditem.GeneratedFileSystemResourceBuildItem) BuildStep(io.quarkus.deployment.annotations.BuildStep)

Example 3 with NativeImageBuildItem

use of io.quarkus.deployment.pkg.builditem.NativeImageBuildItem in project quarkus by quarkusio.

the class OpenshiftProcessor method openshiftBuildFromNative.

@BuildStep(onlyIf = { IsNormalNotRemoteDev.class, OpenshiftBuild.class, NativeBuild.class })
public void openshiftBuildFromNative(OpenshiftConfig openshiftConfig, 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, NativeImageBuildItem nativeImage) {
    OpenshiftConfig config = mergeConfig(openshiftConfig, s2iConfig);
    if (containerImageConfig.isBuildExplicitlyDisabled()) {
        return;
    }
    if (!containerImageConfig.isBuildExplicitlyEnabled() && !containerImageConfig.isPushExplicitlyEnabled() && !buildRequest.isPresent() && !pushRequest.isPresent()) {
        return;
    }
    String namespace = Optional.ofNullable(kubernetesClient.getClient().getNamespace()).orElse("default");
    LOG.info("Starting (in-cluster) container image build for jar using: " + config.buildStrategy + " on server: " + kubernetesClient.getClient().getMasterUrl() + " in namespace:" + namespace + ".");
    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 openshift build process will be taking place");
        return;
    }
    // The contextRoot is where inside the tarball we will add the jars. A null value means everything will be added under '/' while "target" means everything will be added under '/target'.
    // For docker kind of builds where we use instructions like: `COPY target/*.jar /deployments` it using '/target' is a requirement.
    // For s2i kind of builds where jars are expected directly in the '/' we have to use null.
    String contextRoot = config.buildStrategy == BuildStrategy.DOCKER ? "target" : null;
    createContainerImage(kubernetesClient, openshiftYml.get(), config, contextRoot, out.getOutputDirectory(), nativeImage.getPath());
    artifactResultProducer.produce(new ArtifactResultBuildItem(null, "native-container", Collections.emptyMap()));
    containerImageBuilder.produce(new ContainerImageBuilderBuildItem(OPENSHIFT));
}
Also used : Arrays(java.util.Arrays) KubernetesClientBuildItem(io.quarkus.kubernetes.client.spi.KubernetesClientBuildItem) KubernetesEnvBuildItem(io.quarkus.kubernetes.spi.KubernetesEnvBuildItem) Packaging(io.dekorate.utils.Packaging) 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) OpenshiftUtils.mergeConfig(io.quarkus.container.image.openshift.deployment.OpenshiftUtils.mergeConfig) DEFAULT_FAST_JAR_DIRECTORY_NAME(io.quarkus.deployment.pkg.steps.JarResultBuildStep.DEFAULT_FAST_JAR_DIRECTORY_NAME) 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) PathsUtil.findMainSourcesRoot(io.quarkus.container.util.PathsUtil.findMainSourcesRoot) Collection(java.util.Collection) ContainerImageConfig(io.quarkus.container.image.deployment.ContainerImageConfig) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) DecoratorBuildItem(io.quarkus.kubernetes.spi.DecoratorBuildItem) Reader(java.io.Reader) Collectors(java.util.stream.Collectors) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) 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) 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) 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) GeneratedFileSystemResourceBuildItem(io.quarkus.deployment.builditem.GeneratedFileSystemResourceBuildItem) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) BufferedReader(java.io.BufferedReader) Collections(java.util.Collections) ContainerImageBuilderBuildItem(io.quarkus.container.spi.ContainerImageBuilderBuildItem) ArtifactResultBuildItem(io.quarkus.deployment.pkg.builditem.ArtifactResultBuildItem) GeneratedFileSystemResourceBuildItem(io.quarkus.deployment.builditem.GeneratedFileSystemResourceBuildItem) BuildStep(io.quarkus.deployment.annotations.BuildStep)

Aggregations

ArtifactResultBuildItem (io.quarkus.deployment.pkg.builditem.ArtifactResultBuildItem)3 JarBuildItem (io.quarkus.deployment.pkg.builditem.JarBuildItem)3 NativeImageBuildItem (io.quarkus.deployment.pkg.builditem.NativeImageBuildItem)3 Clients (io.dekorate.utils.Clients)2 Serialization (io.dekorate.utils.Serialization)2 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)2 KubernetesList (io.fabric8.kubernetes.api.model.KubernetesList)2 Secret (io.fabric8.kubernetes.api.model.Secret)2 Config (io.fabric8.kubernetes.client.Config)2 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)2 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)2 LogWatch (io.fabric8.kubernetes.client.dsl.LogWatch)2 Build (io.fabric8.openshift.api.model.Build)2 BuildConfig (io.fabric8.openshift.api.model.BuildConfig)2 ImageStream (io.fabric8.openshift.api.model.ImageStream)2 OpenShiftClient (io.fabric8.openshift.client.OpenShiftClient)2 ContainerImageConfig (io.quarkus.container.image.deployment.ContainerImageConfig)2 ImageUtil (io.quarkus.container.image.deployment.util.ImageUtil)2 AvailableContainerImageExtensionBuildItem (io.quarkus.container.spi.AvailableContainerImageExtensionBuildItem)2 BaseImageInfoBuildItem (io.quarkus.container.spi.BaseImageInfoBuildItem)2