use of io.quarkus.deployment.builditem.GeneratedFileSystemResourceBuildItem 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.deployment.builditem.GeneratedFileSystemResourceBuildItem in project quarkus by quarkusio.
the class S2iProcessor method createContainerImage.
public static void createContainerImage(KubernetesClientBuildItem kubernetesClient, GeneratedFileSystemResourceBuildItem openshiftManifests, S2iConfig s2iConfig, Path output, Path... additional) {
File tar;
try {
File original = PackageUtil.packageFile(output, additional);
// Let's rename the archive and give it a more descriptive name, as it may appear in the logs.
tar = Files.createTempFile("quarkus-", "-s2i").toFile();
Files.move(original.toPath(), tar.toPath(), StandardCopyOption.REPLACE_EXISTING);
} catch (Exception e) {
throw new RuntimeException("Error creating the s2i binary build archive.", e);
}
Config config = kubernetesClient.getClient().getConfiguration();
// Let's disable http2 as it causes issues with duplicate build triggers.
config.setHttp2Disable(true);
try (KubernetesClient client = Clients.fromConfig(config)) {
OpenShiftClient openShiftClient = client.adapt(OpenShiftClient.class);
KubernetesList kubernetesList = Serialization.unmarshalAsList(new ByteArrayInputStream(openshiftManifests.getData()));
List<HasMetadata> buildResources = kubernetesList.getItems().stream().filter(i -> i instanceof BuildConfig || i instanceof ImageStream || i instanceof Secret).collect(Collectors.toList());
applyS2iResources(openShiftClient, buildResources);
s2iBuild(openShiftClient, buildResources, tar, s2iConfig);
}
}
use of io.quarkus.deployment.builditem.GeneratedFileSystemResourceBuildItem in project quarkus by quarkusio.
the class OpenshiftProcessor method createContainerImage.
public static void createContainerImage(KubernetesClientBuildItem kubernetesClient, GeneratedFileSystemResourceBuildItem openshiftManifests, OpenshiftConfig openshiftConfig, String base, Path output, Path... additional) {
File tar;
try {
File original = Packaging.packageFile(output, base, additional);
// Let's rename the archive and give it a more descriptive name, as it may appear in the logs.
tar = Files.createTempFile("quarkus-", "-openshift").toFile();
Files.move(original.toPath(), tar.toPath(), StandardCopyOption.REPLACE_EXISTING);
} catch (Exception e) {
throw new RuntimeException("Error creating the openshift binary build archive.", e);
}
Config config = kubernetesClient.getClient().getConfiguration();
// Let's disable http2 as it causes issues with duplicate build triggers.
config.setHttp2Disable(true);
try (KubernetesClient client = Clients.fromConfig(config)) {
OpenShiftClient openShiftClient = toOpenshiftClient(client);
KubernetesList kubernetesList = Serialization.unmarshalAsList(new ByteArrayInputStream(openshiftManifests.getData()));
List<HasMetadata> buildResources = kubernetesList.getItems().stream().filter(i -> i instanceof BuildConfig || i instanceof ImageStream || i instanceof Secret).collect(Collectors.toList());
applyOpenshiftResources(openShiftClient, buildResources);
openshiftBuild(openShiftClient, buildResources, tar, openshiftConfig);
}
}
use of io.quarkus.deployment.builditem.GeneratedFileSystemResourceBuildItem in project quarkus-openshift-test-suite by quarkus-qe.
the class AppMetadataCollector method collectAppMetadata.
@BuildStep
public void collectAppMetadata(ContainerImageInfoBuildItem containerImage, HttpRootPathBuildItem httpRoot, Optional<KubernetesHealthLivenessPathBuildItem> liveness, Optional<KubernetesHealthReadinessPathBuildItem> readiness, BuildProducer<GeneratedFileSystemResourceBuildItem> output) {
String image = containerImage.getImage();
int lastSlash = image.lastIndexOf('/');
int lastColon = image.lastIndexOf(':');
String appName = image.substring(lastSlash + 1, lastColon);
// paths to Kubernetes probes are already httpRoot-adjusted
String knownEndpoint;
if (readiness.isPresent()) {
knownEndpoint = readiness.get().getPath();
} else if (liveness.isPresent()) {
knownEndpoint = liveness.get().getPath();
} else {
// TODO ?
knownEndpoint = httpRoot.resolvePath("/");
}
String deploymentTarget = ConfigProvider.getConfig().getOptionalValue("quarkus.kubernetes.deployment-target", String.class).orElse("");
AppMetadata result = new AppMetadata(appName, httpRoot.getRootPath(), knownEndpoint, deploymentTarget);
output.produce(new GeneratedFileSystemResourceBuildItem("app-metadata.properties", result.toString().getBytes(StandardCharsets.UTF_8)));
}
use of io.quarkus.deployment.builditem.GeneratedFileSystemResourceBuildItem in project quarkus-operator-sdk by quarkiverse.
the class ManifestsProcessor method generateCSV.
@BuildStep
void generateCSV(CSVGenerationConfiguration configuration, OutputTargetBuildItem outputTarget, CSVMetadataBuildItem csvMetadata, BuildProducer<GeneratedCSVBuildItem> doneGeneratingCSV, GeneratedCRDInfoBuildItem generatedCustomResourcesDefinitions, List<GeneratedKubernetesResourceBuildItem> generatedKubernetesManifests, BuildProducer<GeneratedFileSystemResourceBuildItem> generatedCSVs) {
if (configuration.generateCSV.orElse(false)) {
try {
final var outputDir = outputTarget.getOutputDirectory().resolve(MANIFESTS);
final var serviceAccounts = new LinkedList<ServiceAccount>();
final var clusterRoleBindings = new LinkedList<ClusterRoleBinding>();
final var clusterRoles = new LinkedList<ClusterRole>();
final var roleBindings = new LinkedList<RoleBinding>();
final var roles = new LinkedList<Role>();
final var deployments = new LinkedList<Deployment>();
generatedKubernetesManifests.stream().filter(bi -> bi.getName().equals("kubernetes.yml")).findAny().ifPresent(bi -> {
final var resources = Serialization.unmarshalAsList(new ByteArrayInputStream(bi.getContent()));
resources.getItems().forEach(r -> {
if (r instanceof ServiceAccount) {
serviceAccounts.add((ServiceAccount) r);
return;
}
if (r instanceof ClusterRoleBinding) {
clusterRoleBindings.add((ClusterRoleBinding) r);
return;
}
if (r instanceof ClusterRole) {
clusterRoles.add((ClusterRole) r);
return;
}
if (r instanceof RoleBinding) {
roleBindings.add((RoleBinding) r);
return;
}
if (r instanceof Role) {
roles.add((Role) r);
return;
}
if (r instanceof Deployment) {
deployments.add((Deployment) r);
return;
}
});
});
final var generated = ManifestsGenerator.prepareGeneration(csvMetadata.getAugmentedCustomResourceInfos(), csvMetadata.getCSVMetadata());
generated.forEach(manifestBuilder -> {
final var fileName = manifestBuilder.getFileName();
try {
generatedCSVs.produce(new GeneratedFileSystemResourceBuildItem(Path.of(MANIFESTS, fileName).toString(), manifestBuilder.getYAMLData(serviceAccounts, clusterRoleBindings, clusterRoles, roleBindings, roles, deployments)));
log.infov("Generating CSV for {0} controller -> {1}", manifestBuilder.getControllerName(), outputDir.resolve(fileName));
} catch (IOException e) {
log.errorv("Cannot generate CSV for {0}: {1}", manifestBuilder.getControllerName(), e.getMessage());
}
});
// copy custom resources to the manifests folder
generatedCustomResourcesDefinitions.getCRDGenerationInfo().getCrds().values().stream().flatMap(crds -> crds.values().stream()).forEach(crd -> {
try {
FileUtils.copyFileToDirectory(new File(crd.getFilePath()), outputDir.toFile());
} catch (IOException e) {
throw new RuntimeException(e);
}
});
doneGeneratingCSV.produce(new GeneratedCSVBuildItem());
} catch (Exception e) {
log.infov(e, "Couldn't generate CSV:");
}
}
}
Aggregations