use of io.quarkus.container.spi.ContainerImageBuildRequestBuildItem 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));
}
use of io.quarkus.container.spi.ContainerImageBuildRequestBuildItem 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));
}
use of io.quarkus.container.spi.ContainerImageBuildRequestBuildItem in project quarkus by quarkusio.
the class KubernetesDeployerPrerequisite method prepare.
@BuildStep(onlyIf = IsNormalNotRemoteDev.class)
public void prepare(ContainerImageInfoBuildItem containerImage, Optional<SelectedKubernetesDeploymentTargetBuildItem> selectedDeploymentTarget, Optional<FallbackContainerImageRegistryBuildItem> fallbackRegistry, BuildProducer<ContainerImageBuildRequestBuildItem> buildRequestProducer, BuildProducer<ContainerImagePushRequestBuildItem> pushRequestProducer) {
// the Kubernetes resources from being generated
if (!KubernetesDeploy.INSTANCE.checkSilently() || !selectedDeploymentTarget.isPresent()) {
return;
}
// Let's communicate to the container-image plugin that we need an image build and an image push.
buildRequestProducer.produce(new ContainerImageBuildRequestBuildItem());
// When a registry is present, we want to push the image
// However we need to make sure we don't push to the registry when deploying to Minikube
// since all updates are meant to find the image from the docker daemon
boolean registryIsPresent = containerImage.getRegistry().isPresent() || fallbackRegistry.isPresent();
if (registryIsPresent && !selectedDeploymentTarget.get().getEntry().getName().equals(Constants.MINIKUBE)) {
pushRequestProducer.produce(new ContainerImagePushRequestBuildItem());
}
}
use of io.quarkus.container.spi.ContainerImageBuildRequestBuildItem in project quarkus by quarkusio.
the class OpenshiftProcessor method openshiftBuildFromJar.
@BuildStep(onlyIf = { IsNormalNotRemoteDev.class, OpenshiftBuild.class }, onlyIfNot = NativeBuild.class)
public void openshiftBuildFromJar(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, // used to ensure that the jar has been built
JarBuildItem jar) {
OpenshiftConfig config = mergeConfig(openshiftConfig, s2iConfig);
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 openshift build process will be taking place");
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 + ".");
// 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 outputDirName = out.getOutputDirectory().getFileName().toString();
String contextRoot = getContextRoot(outputDirName, packageConfig.isFastJar(), config.buildStrategy);
if (packageConfig.isFastJar()) {
createContainerImage(kubernetesClient, openshiftYml.get(), config, contextRoot, jar.getPath().getParent(), jar.getPath().getParent());
} else if (jar.getLibraryDir() != null) {
// When using uber-jar the libraryDir is going to be null, potentially causing NPE.
createContainerImage(kubernetesClient, openshiftYml.get(), config, contextRoot, jar.getPath().getParent(), jar.getPath(), jar.getLibraryDir());
} else {
createContainerImage(kubernetesClient, openshiftYml.get(), config, contextRoot, jar.getPath().getParent(), jar.getPath());
}
artifactResultProducer.produce(new ArtifactResultBuildItem(null, "jar-container", Collections.emptyMap()));
containerImageBuilder.produce(new ContainerImageBuilderBuildItem(OPENSHIFT));
}
use of io.quarkus.container.spi.ContainerImageBuildRequestBuildItem 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));
}
Aggregations