Skip to content

Commit

Permalink
Use native binary for WireViz (#1591)
Browse files Browse the repository at this point in the history
  • Loading branch information
ggrossetie committed Aug 21, 2023
1 parent 66a0bc3 commit 729318b
Show file tree
Hide file tree
Showing 26 changed files with 34 additions and 594 deletions.
16 changes: 5 additions & 11 deletions ci/tasks/update-versions.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,17 +126,6 @@ const diagramLibraryNames = [
]

try {
const wirevizRequirementsContent = await fs.readFile(ospath.join(rootDir, 'wireviz', 'requirements.txt'), 'utf8')
for (const line of wirevizRequirementsContent.split('\n')) {
const found = line.match(/^(?<name>[a-zA-Z]+)==(?<version>.*)$/)
if (found) {
const { name, version } = found.groups
if (diagramLibraryNames.includes(name)) {
diagramLibraryVersions[name] = version
}
}
}

addDiagramLibraryPackageVersion('bpmn', 'bpmn-js')
addDiagramLibraryPackageVersion('bytefield', 'bytefield-svg')
addDiagramLibraryPackageVersion('dbml', '@softwaretechnik/dbml-renderer')
Expand Down Expand Up @@ -209,6 +198,11 @@ try {
diagramLibraryVersions.nwdiag = version
diagramLibraryVersions.nwdiag = version
}
const wirevizVersionFound = line.match(/^ARG WIREVIZ_VERSION="(?<version>.+)"$/)
if (wirevizVersionFound) {
const { version } = wirevizVersionFound.groups
diagramLibraryVersions.wireviz = version
}
}

const svgbobCargoContent = await fs.readFile(ospath.join(rootDir, 'server', 'ops', 'docker', 'Cargo.toml'), 'utf8')
Expand Down
6 changes: 0 additions & 6 deletions ci/tests/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ services:
- KROKI_BPMN_HOST=bpmn
- KROKI_EXCALIDRAW_HOST=excalidraw
- KROKI_DIAGRAMSNET_HOST=diagramsnet
- KROKI_WIREVIZ_HOST=wireviz
ports:
- "8000:8000"

Expand All @@ -35,8 +34,3 @@ services:
image: yuzutech/kroki-diagramsnet:smoketests
expose:
- "8005"

wireviz:
image: yuzutech/kroki-wireviz:smoketests
ports:
- "8006:8006"
4 changes: 0 additions & 4 deletions docker-bake-release.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,3 @@ target "kroki-excalidraw" {
target "kroki-diagramsnet" {
tags = ["yuzutech/kroki-diagramsnet:${RELEASE_VERSION}", "yuzutech/kroki-diagramsnet:latest"]
}

target "kroki-wireviz" {
tags = ["yuzutech/kroki-wireviz:${RELEASE_VERSION}", "yuzutech/kroki-wireviz:latest"]
}
7 changes: 1 addition & 6 deletions docker-bake.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ variable "TAG" {
}

group "companion-images" {
targets = ["kroki-mermaid", "kroki-bpmn", "kroki-excalidraw", "kroki-diagramsnet", "kroki-wireviz"]
targets = ["kroki-mermaid", "kroki-bpmn", "kroki-excalidraw", "kroki-diagramsnet"]
}

target "kroki" {
Expand Down Expand Up @@ -39,8 +39,3 @@ target "kroki-diagramsnet" {
context = "diagrams.net"
tags = ["yuzutech/kroki-diagramsnet:${TAG}"]
}

target "kroki-wireviz" {
context = "wireviz"
tags = ["yuzutech/kroki-wireviz:${TAG}"]
}
23 changes: 0 additions & 23 deletions docs/modules/setup/examples/k8s-multi-pod/wireviz-deployment.yaml

This file was deleted.

15 changes: 0 additions & 15 deletions docs/modules/setup/examples/k8s-multi-pod/wireviz-service.yaml

This file was deleted.

6 changes: 5 additions & 1 deletion server/ops/docker/jdk11-jammy/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ ARG UMLET_VERSION="2023-03-20_UMLet_v15.1"
ARG GRAPHVIZ_VERSION="8.0.5"
ARG DITAA_VERSION="1.0.3"
ARG BLOCKDIAG_VERSION="3.1.0"
ARG WIREVIZ_VERSION="0.3.3"
ARG TARGETARCH

LABEL \
Expand Down Expand Up @@ -298,6 +299,9 @@ RUN wget "https://github.com/yuzutech/umlet/releases/download/${UMLET_VERSION}/u
RUN wget "https://github.com/yuzutech/blockdiag/releases/download/v${BLOCKDIAG_VERSION}/blockdiag-bundle-linux-${TARGETARCH}.bin" -O /usr/bin/blockdiag && \
chmod +x /usr/bin/blockdiag

RUN wget "https://github.com/yuzutech/WireViz/releases/download/v${WIREVIZ_VERSION}/wireviz-linux-${TARGETARCH}.bin" -O /usr/bin/wireviz && \
chmod +x /usr/bin/wireviz

COPY --from=kroki-builder-static-svgbob /usr/local/cargo/bin/svgbob_cli /usr/bin/svgbob
COPY --from=kroki-builder-static-erd /root/.local/bin/erd /usr/bin/erd
COPY --from=kroki-builder-static-pikchr /build/pikchr /usr/bin/pikchr
Expand Down Expand Up @@ -329,7 +333,7 @@ ENV KROKI_PLANTUML_BIN_PATH=/usr/bin/plantuml
ENV KROKI_TIKZ2SVG_BIN_PATH=/usr/bin/tikz2svg
ENV KROKI_DITAA_BIN_PATH=/usr/bin/ditaa
ENV KROKI_SYMBOLATOR_BIN_PATH=/usr/bin/symbolator
ENV KROKI_BLOCKDIAG_BIN_PATH=/usr/bin/blockdiag
ENV KROKI_WIREVIZ_BIN_PATH=/usr/bin/wireviz
ENV JAVA_OPTS="-Dlogback.configurationFile=/etc/kroki/logback.xml -Dvertx.logger-delegate-factory-class-name=io.vertx.core.logging.SLF4JLogDelegateFactory"

COPY --chown=kroki:kroki target/kroki-server.jar /usr/local/kroki/kroki-server.jar
Expand Down
2 changes: 1 addition & 1 deletion server/src/main/java/io/kroki/server/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ static void start(Vertx vertx, JsonObject config, Handler<AsyncResult<HttpServer
registry.register(new D2(vertx, config, commander), "d2");
registry.register(new TikZ(vertx, config, commander), "tikz");
registry.register(new Dbml(vertx, config, commander), "dbml");
registry.register(new Wireviz(vertx, config), "wireviz");
registry.register(new Wireviz(vertx, config, commander), "wireviz");

router.post("/")
.handler(bodyHandler)
Expand Down
6 changes: 1 addition & 5 deletions server/src/main/java/io/kroki/server/service/Wavedrom.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,11 @@ public String getVersion() {
public void convert(String sourceDecoded, String serviceName, FileFormat fileFormat, JsonObject options, Handler<AsyncResult<Buffer>> handler) {
vertx.executeBlocking(future -> {
try {
byte[] result = vega(sourceDecoded.getBytes());
byte[] result = commander.execute(sourceDecoded.getBytes(), binPath);
future.complete(result);
} catch (IOException | InterruptedException | IllegalStateException e) {
future.fail(e);
}
}, res -> handler.handle(res.map(o -> Buffer.buffer((byte[]) o))));
}

private byte[] vega(byte[] source) throws IOException, InterruptedException, IllegalStateException {
return commander.execute(source, binPath);
}
}
33 changes: 21 additions & 12 deletions server/src/main/java/io/kroki/server/service/Wireviz.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.kroki.server.service;

import io.kroki.server.action.Commander;
import io.kroki.server.action.Delegator;
import io.kroki.server.decode.DiagramSource;
import io.kroki.server.decode.SourceDecoder;
Expand All @@ -13,28 +14,29 @@
import io.vertx.ext.web.client.HttpResponse;
import io.vertx.ext.web.client.WebClient;

import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

public class Wireviz implements DiagramService {

private static final List<FileFormat> SUPPORTED_FORMATS = Arrays.asList(FileFormat.PNG, FileFormat.SVG);

private final WebClient client;
private final Vertx vertx;
private final String binPath;
private final SourceDecoder sourceDecoder;
private final String host;
private final int port;
private final Commander commander;

public Wireviz(Vertx vertx, JsonObject config) {
this.client = WebClient.create(vertx);
public Wireviz(Vertx vertx, JsonObject config, Commander commander) {
this.vertx = vertx;
this.binPath = config.getString("KROKI_WIREVIZ_BIN_PATH", "wireviz");
this.sourceDecoder = new SourceDecoder() {
@Override
public String decode(String encoded) throws DecodeException {
return DiagramSource.decode(encoded);
}
};
this.host = config.getString("KROKI_WIREVIZ_HOST", "127.0.0.1");
this.port = config.getInteger("KROKI_WIREVIZ_PORT", 8006);
this.commander = commander;
}

@Override
Expand All @@ -49,13 +51,20 @@ public SourceDecoder getSourceDecoder() {

@Override
public String getVersion() {
return "0.3.2";
return "0.3.3";
}

@Override
public void convert(String sourceDecoded, String serviceName, FileFormat fileFormat, JsonObject options, Handler<AsyncResult<Buffer>> handler) {
String requestURI = "/" + serviceName + "/" + fileFormat.getName();
Handler<AsyncResult<HttpResponse<Buffer>>> responseHandler = Delegator.createHandler(host, port, requestURI, handler);
Delegator.delegate(client, host, port, requestURI, sourceDecoded, options, responseHandler);
vertx.executeBlocking(future -> {
try {
byte[] result = commander.execute(sourceDecoded.getBytes(), binPath,
"--format=" + fileFormat.getName(),
"-");
future.complete(result);
} catch (IOException | InterruptedException | IllegalStateException e) {
future.fail(e);
}
}, res -> handler.handle(res.map(o -> Buffer.buffer((byte[]) o))));
}
}
3 changes: 0 additions & 3 deletions wireviz/.dockerignore

This file was deleted.

14 changes: 0 additions & 14 deletions wireviz/.editorconfig

This file was deleted.

2 changes: 0 additions & 2 deletions wireviz/.gitignore

This file was deleted.

25 changes: 0 additions & 25 deletions wireviz/Dockerfile

This file was deleted.

12 changes: 0 additions & 12 deletions wireviz/Makefile

This file was deleted.

35 changes: 0 additions & 35 deletions wireviz/README.adoc

This file was deleted.

52 changes: 0 additions & 52 deletions wireviz/examples.py

This file was deleted.

11 changes: 0 additions & 11 deletions wireviz/requirements.txt

This file was deleted.

Empty file removed wireviz/src/backend/__init__.py
Empty file.
Loading

0 comments on commit 729318b

Please sign in to comment.