-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31435 from cescoffier/devui-container-image
Implement the container image card
- Loading branch information
Showing
6 changed files
with
299 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
...n/java/io/quarkus/container/image/deployment/devconsole/ContainerImageDevUiProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package io.quarkus.container.image.deployment.devconsole; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.function.Function; | ||
|
||
import io.quarkus.bootstrap.BootstrapException; | ||
import io.quarkus.bootstrap.app.ArtifactResult; | ||
import io.quarkus.bootstrap.app.AugmentResult; | ||
import io.quarkus.bootstrap.app.CuratedApplication; | ||
import io.quarkus.bootstrap.app.QuarkusBootstrap; | ||
import io.quarkus.container.image.runtime.devui.ContainerBuilderJsonRpcService; | ||
import io.quarkus.container.spi.AvailableContainerImageExtensionBuildItem; | ||
import io.quarkus.deployment.IsDevelopment; | ||
import io.quarkus.deployment.annotations.BuildStep; | ||
import io.quarkus.dev.console.DevConsoleManager; | ||
import io.quarkus.dev.console.TempSystemProperties; | ||
import io.quarkus.devui.spi.JsonRPCProvidersBuildItem; | ||
import io.quarkus.devui.spi.page.CardPageBuildItem; | ||
import io.quarkus.devui.spi.page.Page; | ||
import io.vertx.core.json.JsonArray; | ||
|
||
public class ContainerImageDevUiProcessor { | ||
|
||
@BuildStep(onlyIf = IsDevelopment.class) | ||
CardPageBuildItem create(List<AvailableContainerImageExtensionBuildItem> extensions) { | ||
// Get the list of builders | ||
JsonArray array = extensions.stream().map(AvailableContainerImageExtensionBuildItem::getName).sorted() | ||
.collect(JsonArray::new, JsonArray::add, JsonArray::addAll); | ||
|
||
CardPageBuildItem card = new CardPageBuildItem("Container Image"); | ||
card.addBuildTimeData("builderTypes", array); | ||
card.addPage(Page.webComponentPageBuilder() | ||
.title("Build Container") | ||
.componentLink("qwc-container-image-build.js") | ||
.icon("font-awesome-solid:box")); | ||
return card; | ||
} | ||
|
||
@BuildStep(onlyIf = IsDevelopment.class) | ||
JsonRPCProvidersBuildItem createJsonRPCServiceForContainerBuild() { | ||
DevConsoleManager.register("container-image-build-action", build()); | ||
return new JsonRPCProvidersBuildItem("ContainerImage", ContainerBuilderJsonRpcService.class); | ||
} | ||
|
||
private Function<Map<String, String>, String> build() { | ||
return (map -> { | ||
QuarkusBootstrap existing = (QuarkusBootstrap) DevConsoleManager.getQuarkusBootstrap(); | ||
try (TempSystemProperties properties = new TempSystemProperties()) { | ||
properties.set("quarkus.container-image.build", "true"); | ||
for (Map.Entry<String, String> arg : map.entrySet()) { | ||
properties.set(arg.getKey(), arg.getValue()); | ||
} | ||
|
||
QuarkusBootstrap quarkusBootstrap = existing.clonedBuilder() | ||
.setMode(QuarkusBootstrap.Mode.PROD) | ||
.setIsolateDeployment(true).build(); | ||
try (CuratedApplication bootstrap = quarkusBootstrap.bootstrap()) { | ||
AugmentResult augmentResult = bootstrap | ||
.createAugmentor().createProductionApplication(); | ||
List<ArtifactResult> containerArtifactResults = augmentResult | ||
.resultsMatchingType((s) -> s.contains("container")); | ||
if (containerArtifactResults.size() >= 1) { | ||
return "Container image: " + containerArtifactResults.get(0).getMetadata().get("container-image") | ||
+ " created."; | ||
} else { | ||
return "Unknown error (image not created)"; | ||
} | ||
} catch (BootstrapException e) { | ||
return e.getMessage(); | ||
} | ||
} | ||
}); | ||
} | ||
} |
144 changes: 144 additions & 0 deletions
144
...r-image/deployment/src/main/resources/dev-ui/container-image/qwc-container-image-build.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
import {LitElement, html, css, render} from 'lit'; | ||
import {JsonRpc} from 'jsonrpc'; | ||
import '@vaadin/icon'; | ||
import '@vaadin/button'; | ||
import {until} from 'lit/directives/until.js'; | ||
import '@vaadin/grid'; | ||
import '@vaadin/grid/vaadin-grid-sort-column.js'; | ||
import {builderTypes} from 'container-image-data'; | ||
import '@vaadin/text-field'; | ||
import '@vaadin/text-area'; | ||
import '@vaadin/form-layout'; | ||
import '@vaadin/progress-bar'; | ||
import '@vaadin/checkbox'; | ||
import '@vaadin/select'; | ||
import '@vaadin/item'; | ||
import '@vaadin/list-box'; | ||
|
||
|
||
export class QwcContainerImageBuild extends LitElement { | ||
|
||
jsonRpc = new JsonRpc("ContainerImage"); | ||
|
||
static properties = { | ||
builders: {type: Array}, | ||
types: {type: Array}, | ||
selected_builder: {type: String}, | ||
selected_type: {type: String}, | ||
build_in_progress: {state: true, type: Boolean}, | ||
build_complete: {state: true, type: Boolean}, | ||
build_error: {state: true, type: Boolean}, | ||
result: {type: String} | ||
} | ||
|
||
static styles = css` | ||
.report { | ||
margin-top: 1em; | ||
width: 80%; | ||
} | ||
`; | ||
|
||
|
||
connectedCallback() { | ||
super.connectedCallback(); | ||
this.build_in_progress = false; | ||
this.build_complete = false; | ||
this.build_error = false; | ||
this.result = ""; | ||
|
||
this.builders = builderTypes.list; | ||
|
||
this.types = []; | ||
this.types.push({name: "Default", value: ""}); | ||
this.types.push({name: "Jar", value: "jar"}); | ||
this.types.push({name: "Mutable Jar", value: "mutable-jar"}); | ||
this.types.push({name: "Native", value: "native"}); | ||
} | ||
|
||
/** | ||
* Called when it needs to render the components | ||
* @returns {*} | ||
*/ | ||
render() { | ||
return html`${until(this._renderForm(), html`<span>Loading...</span>`)}`; | ||
} | ||
|
||
_renderForm() { | ||
const _builders = []; | ||
this.builders.map(item => _builders.push({'label': item, 'value': item})); | ||
const _defaultBuilder = _builders[0].label; | ||
|
||
const _types = []; | ||
this.types.map(item => _types.push({'label': item.name, 'value': item.value})); | ||
const _defaultType = "jar"; | ||
|
||
const _builderPicker = html` | ||
<vaadin-select | ||
label="Image Builder" | ||
.items="${_builders}" | ||
.value="${_defaultBuilder}" | ||
?disabled="${_builders.length === 1 || this.build_in_progress}" | ||
@value-changed="${e => this.selected_builder = e.target.value}" | ||
></vaadin-select>`; | ||
|
||
let progress; | ||
if (this.build_in_progress) { | ||
progress = html` | ||
<div class="report"> | ||
<div>Generating container images...</div> | ||
<vaadin-progress-bar indeterminate theme="contrast"></vaadin-progress-bar> | ||
</div>`; | ||
} else if (this.build_complete) { | ||
progress = html` | ||
<div class="report"> | ||
<div>${this.result}</div> | ||
<vaadin-progress-bar value="1" | ||
theme="${this.build_error} ? 'error' : 'success'"></vaadin-progress-bar> | ||
</div>`; | ||
} else { | ||
progress = html` | ||
<div class="report"></div>`; | ||
} | ||
|
||
return html` | ||
<p>Select the type of build (jar, native...) and the container image builder.</p> | ||
<vaadin-select | ||
label="Build Type" | ||
.items="${_types}" | ||
.value="${_defaultType}" | ||
?disabled="${this.build_in_progress}" | ||
@value-changed="${e => this.selected_type = e.target.value}" | ||
></vaadin-select> | ||
${_builderPicker} | ||
<vaadin-button @click="${this._build}" ?disabled="${this.build_in_progress}">Build Container</vaadin-button> | ||
${progress} | ||
`; | ||
} | ||
|
||
_build() { | ||
this.build_complete = false; | ||
this.build_in_progress = true; | ||
this.build_error = false; | ||
this.result = ""; | ||
this.jsonRpc.build({'type': this.selected_type, 'builder': this.selected_builder}) | ||
.onNext(jsonRpcResponse => { | ||
const msg = jsonRpcResponse.result; | ||
if (msg === "started") { | ||
this.build_complete = false; | ||
this.build_in_progress = true; | ||
this.build_error = false; | ||
} else if (msg.includes("created.")) { | ||
this.result = msg; | ||
this.build_complete = true; | ||
this.build_in_progress = false; | ||
} else { | ||
this.build_complete = true; | ||
this.build_in_progress = false; | ||
this.build_error = true; | ||
} | ||
}); | ||
} | ||
|
||
} | ||
|
||
customElements.define('qwc-container-image-build', QwcContainerImageBuild); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
...rc/main/java/io/quarkus/container/image/runtime/devui/ContainerBuilderJsonRpcService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package io.quarkus.container.image.runtime.devui; | ||
|
||
import java.util.Map; | ||
|
||
import io.quarkus.dev.console.DevConsoleManager; | ||
import io.smallrye.mutiny.Multi; | ||
import io.smallrye.mutiny.Uni; | ||
import io.smallrye.mutiny.infrastructure.Infrastructure; | ||
|
||
public class ContainerBuilderJsonRpcService { | ||
|
||
public Multi<String> build(String type, String builder) { | ||
Map<String, String> params = Map.of( | ||
"quarkus.container-image.builder", builder, | ||
"quarkus.build.package-type", type); | ||
|
||
// For now, the JSON RPC are called on the event loop, but the action is blocking, | ||
// So, work around this by invoking the action on a worker thread. | ||
Multi<String> build = Uni.createFrom().item(() -> DevConsoleManager | ||
.<String> invoke("container-image-build-action", params)) | ||
.runSubscriptionOn(Infrastructure.getDefaultExecutor()) // It's a blocking action. | ||
.toMulti(); | ||
|
||
return Multi.createBy().concatenating() | ||
.streams(Multi.createFrom().item("started"), build); | ||
|
||
} | ||
|
||
} |