From 9eb3c564700238e4844df33d99515aaad8646768 Mon Sep 17 00:00:00 2001 From: Guillaume Grossetie Date: Sun, 23 Apr 2023 18:22:01 +0200 Subject: [PATCH 1/4] Use pre-built binary for GraphViz --- ci/tasks/update-versions.js | 9 +++++++++ server/ops/docker/jdk11-jammy/Dockerfile | 1 + 2 files changed, 10 insertions(+) diff --git a/ci/tasks/update-versions.js b/ci/tasks/update-versions.js index 2d0dcb694..ca15f4db2 100755 --- a/ci/tasks/update-versions.js +++ b/ci/tasks/update-versions.js @@ -205,6 +205,15 @@ try { } } + const d2GoModContent = await fs.readFile(ospath.join(rootDir, 'server', 'ops', 'docker', 'go.mod'), 'utf8') + for (const line of d2GoModContent.split('\n')) { + const d2VersionFound = line.match(/^require oss.terrastruct.com\/d2 v(?.+)$/) + if (d2VersionFound) { + const { version } = d2VersionFound.groups + diagramLibraryVersions.d2 = version + } + } + const svgbobCargoContent = await fs.readFile(ospath.join(rootDir, 'server', 'ops', 'docker', 'Cargo.toml'), 'utf8') for (const line of svgbobCargoContent.split('\n')) { const svgbobVersionFound = line.match(/^svgbob_cli\s*=\s*"(?.+)"$/) diff --git a/server/ops/docker/jdk11-jammy/Dockerfile b/server/ops/docker/jdk11-jammy/Dockerfile index f9a7b1c2e..c3b7a818e 100644 --- a/server/ops/docker/jdk11-jammy/Dockerfile +++ b/server/ops/docker/jdk11-jammy/Dockerfile @@ -211,6 +211,7 @@ ARG D2_VERSION="0.4.1" ARG PLANTUML_VERSION="1.2023.6" ARG UMLET_VERSION="2023-03-20_UMLet_v15.1" ARG GRAPHVIZ_VERSION="8.0.4" +ARG GRAPHVIZ_VERSION="8.0.4" ARG TARGETARCH RUN addgroup --gecos 1000 kroki && adduser --disabled-password --ingroup kroki -u 1000 kroki From 60ed3b3c939368609ed6b35178d9bee84fb21d16 Mon Sep 17 00:00:00 2001 From: Guillaume Grossetie Date: Sat, 6 May 2023 18:39:27 +0200 Subject: [PATCH 2/4] Add tests on PDF and txt --- ci/tests/smoke.js | 7 ++++--- server/src/main/java/io/kroki/server/service/Plantuml.java | 2 +- .../src/main/java/io/kroki/server/service/Structurizr.java | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/ci/tests/smoke.js b/ci/tests/smoke.js index 1f5920dab..b840aba56 100755 --- a/ci/tests/smoke.js +++ b/ci/tests/smoke.js @@ -11,13 +11,13 @@ const tests = [ {engine: 'seqdiag', file: 'sequence.diag', options: {}, outputFormat: ['svg', 'png']}, {engine: 'actdiag', file: 'actions.diag', options: {}, outputFormat: ['svg', 'png']}, {engine: 'nwdiag', file: 'network.diag', options: {}, outputFormat: ['svg', 'png']}, - {engine: 'c4plantuml', file: 'banking-system.puml', options: {}, outputFormat: ['svg']}, + {engine: 'c4plantuml', file: 'banking-system.puml', options: {}, outputFormat: ['svg', 'pdf', 'png', 'txt']}, {engine: 'dbml', file: 'dbml.dbml', options: {}, outputFormat: ['svg']}, {engine: 'ditaa', file: 'components.ditaa', options: {}, outputFormat: ['svg']}, {engine: 'erd', file: 'schema.erd', options: {}, outputFormat: ['svg']}, {engine: 'mermaid', file: 'contribute.mmd', options: {}, outputFormat: ['svg']}, {engine: 'bpmn', file: 'example.bpmn', options: {}, outputFormat: ['svg']}, - {engine: 'plantuml', file: 'architecture.puml', options: {}, outputFormat: ['svg']}, + {engine: 'plantuml', file: 'architecture.puml', options: {}, outputFormat: ['svg', 'pdf', 'png', 'txt']}, {engine: 'svgbob', file: 'cloud.bob', options: {}, outputFormat: ['svg']}, {engine: 'nomnoml', file: 'pirate.nomnoml', options: {}, outputFormat: ['svg']}, {engine: 'packetdiag', file: 'packet.diag', options: {}, outputFormat: ['svg', 'png']}, @@ -50,7 +50,8 @@ const mimeType = { svg: 'image/svg+xml', png: 'image/png', pdf: 'application/pdf', - jpeg: 'image/jpeg' + jpeg: 'image/jpeg', + txt: 'text/plain' } const sendRequest = async (testCase, outputFormat) => { diff --git a/server/src/main/java/io/kroki/server/service/Plantuml.java b/server/src/main/java/io/kroki/server/service/Plantuml.java index 5b3b2a76b..4b7995a32 100644 --- a/server/src/main/java/io/kroki/server/service/Plantuml.java +++ b/server/src/main/java/io/kroki/server/service/Plantuml.java @@ -72,7 +72,7 @@ public class Plantuml implements DiagramService { private static final Pattern START_BLOCK_RX = Pattern.compile("^(@start.*\\n)"); private static final Logger logger = LoggerFactory.getLogger(Plantuml.class); - private static final List SUPPORTED_FORMATS = Arrays.asList(FileFormat.PNG, FileFormat.SVG, FileFormat.JPEG, FileFormat.BASE64, FileFormat.TXT, FileFormat.UTXT); + private static final List SUPPORTED_FORMATS = Arrays.asList(FileFormat.PNG, FileFormat.SVG, FileFormat.PDF, FileFormat.BASE64, FileFormat.TXT, FileFormat.UTXT); private static final Pattern STDLIB_PATH_RX = Pattern.compile("<([a-zA-Z0-9]+)/[^>]+>"); private final Vertx vertx; diff --git a/server/src/main/java/io/kroki/server/service/Structurizr.java b/server/src/main/java/io/kroki/server/service/Structurizr.java index 5d06c4f76..32dff0b17 100644 --- a/server/src/main/java/io/kroki/server/service/Structurizr.java +++ b/server/src/main/java/io/kroki/server/service/Structurizr.java @@ -51,7 +51,7 @@ public class Structurizr implements DiagramService { private final PlantumlCommand plantumlCommand; // same as PlantUML since we convert Structurizr DSL to PlantUML - private static final List SUPPORTED_FORMATS = Arrays.asList(FileFormat.PNG, FileFormat.SVG, FileFormat.JPEG, FileFormat.BASE64, FileFormat.TXT, FileFormat.UTXT); + private static final List SUPPORTED_FORMATS = Arrays.asList(FileFormat.PNG, FileFormat.SVG, FileFormat.PDF, FileFormat.BASE64, FileFormat.TXT, FileFormat.UTXT); private static final String aws = read("structurizr/amazon-web-services.json"); private static final String gcp = read("structurizr/google-cloud-platform.json"); From b5f2afece1d09184fd7cb702a935f47da7226338 Mon Sep 17 00:00:00 2001 From: Guillaume Grossetie Date: Sun, 7 May 2023 12:04:37 +0200 Subject: [PATCH 3/4] Remove duplicate line --- server/ops/docker/jdk11-jammy/Dockerfile | 1 - 1 file changed, 1 deletion(-) diff --git a/server/ops/docker/jdk11-jammy/Dockerfile b/server/ops/docker/jdk11-jammy/Dockerfile index c3b7a818e..f9a7b1c2e 100644 --- a/server/ops/docker/jdk11-jammy/Dockerfile +++ b/server/ops/docker/jdk11-jammy/Dockerfile @@ -211,7 +211,6 @@ ARG D2_VERSION="0.4.1" ARG PLANTUML_VERSION="1.2023.6" ARG UMLET_VERSION="2023-03-20_UMLet_v15.1" ARG GRAPHVIZ_VERSION="8.0.4" -ARG GRAPHVIZ_VERSION="8.0.4" ARG TARGETARCH RUN addgroup --gecos 1000 kroki && adduser --disabled-password --ingroup kroki -u 1000 kroki From 937e95907f4b9c39bd2b979b87fa2499c2d290f9 Mon Sep 17 00:00:00 2001 From: Guillaume Grossetie Date: Sun, 7 May 2023 19:42:09 +0200 Subject: [PATCH 4/4] Add a PDF test --- .../server/service/C4PlantumlServiceTest.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/server/src/test/java/io/kroki/server/service/C4PlantumlServiceTest.java b/server/src/test/java/io/kroki/server/service/C4PlantumlServiceTest.java index 628f17cb4..b9e6765d1 100644 --- a/server/src/test/java/io/kroki/server/service/C4PlantumlServiceTest.java +++ b/server/src/test/java/io/kroki/server/service/C4PlantumlServiceTest.java @@ -16,6 +16,7 @@ import org.junit.jupiter.api.extension.ExtendWith; import java.io.IOException; +import java.nio.charset.StandardCharsets; import static org.assertj.core.api.Assertions.assertThat; @@ -98,4 +99,27 @@ void should_not_use_network() throws IOException, InterruptedException { System.clearProperty("socksProxyPort"); } } + + @Test + void should_convert_to_pdf() throws IOException, InterruptedException { + String diagram = "@startuml\n" + + "!include C4_Context.puml\n" + + "\n" + + "title System Context diagram for Internet Banking System\n" + + "\n" + + "Person(customer, \"Banking Customer\", \"A customer of the bank, with personal bank accounts.\")\n" + + "System(banking_system, \"Internet Banking System\", \"Allows customers to check their accounts.\")\n" + + "\n" + + "System_Ext(mail_system, \"E-mail system\", \"The internal Microsoft Exchange e-mail system.\")\n" + + "System_Ext(mainframe, \"Mainframe Banking System\", \"Stores all of the core banking information.\")\n" + + "\n" + + "Rel(customer, banking_system, \"Uses\")\n" + + "Rel_Back(customer, mail_system, \"Sends e-mails to\")\n" + + "Rel_Neighbor(banking_system, mail_system, \"Sends e-mails\", \"SMTP\")\n" + + "Rel(banking_system, mainframe, \"Uses\")\n" + + "@enduml"; + byte[] convert = plantumlCommand.convert(Plantuml.sanitize(diagram, SafeMode.SAFE), FileFormat.PDF, new JsonObject()); + assertThat(convert).isNotEmpty(); + assertThat(new String(convert, StandardCharsets.UTF_8)).contains("%PDF-1.4"); + } }