From 40457f8ce453a96a5a4ff360f9c5c0b50ef46b0f Mon Sep 17 00:00:00 2001 From: Alec Thomas Date: Thu, 12 Oct 2023 11:55:03 +1100 Subject: [PATCH] fix: include JAR dependencies in Kotlin deploys By adding the following fragment to the POM: ```xml copy-dependencies compile copy-dependencies ${project.build.directory}/dependency runtime ``` `ftl deploy ./target` will upload all dependendcies as well as compiled source. This actually works super well in practice, and I think we can completely remove the need for building a custom `ftl-runner` Docker image. One issue is that this now results in the runners having to download quite a few MB of artefacts on each deploy, but we can mitigate this by making the controller->runner artefact download process incremental too, and have each runner maintain its own cache. Probably something for later though, as it's generally pretty fast so far. --- Procfile.nowatch | 20 +++++++++---------- backend/common/download/download.go | 5 +++++ examples/echo-kotlin/pom.xml | 17 +++++++++++++--- .../block/ftl/generator/ModuleGenerator.kt | 4 ++-- 4 files changed, 31 insertions(+), 15 deletions(-) diff --git a/Procfile.nowatch b/Procfile.nowatch index 2c89e1301d..d67497392f 100644 --- a/Procfile.nowatch +++ b/Procfile.nowatch @@ -1,11 +1,11 @@ controller: build/release/ftl-controller --key C01H5BRT09Y07547SETZ4HWRA09 --bind http://localhost:8892 -runner0: build/release/ftl-runner --key R01H5BTS6ABP1EHGZSAGJMBV50A --language go --language kotlin --bind http://localhost:8894 --template-dir build/template -runner1: build/release/ftl-runner --key R01H5BTSGKQ8AZ9S22N9N1SM9HV --language go --language kotlin --bind http://localhost:8895 --template-dir build/template -runner2: build/release/ftl-runner --key R01H8DD0H13WX636B70WV7D216G --language go --language kotlin --bind http://localhost:8896 --template-dir build/template -runner3: build/release/ftl-runner --key R01H8DD0V6EFZWKV2G2XBBHEDP9 --language go --language kotlin --bind http://localhost:8897 --template-dir build/template -runner4: build/release/ftl-runner --key R01H8DD0Z5GRT3QP1MBARC4TW08 --language go --language kotlin --bind http://localhost:8898 --template-dir build/template -runner5: build/release/ftl-runner --key R01H8DD12R0RZZS8AGYBGVP5KQ8 --language go --language kotlin --bind http://localhost:8899 --template-dir build/template -runner6: build/release/ftl-runner --key R01H8DD15Y9SPGDQMXNJ0CF3C5M --language go --language kotlin --bind http://localhost:8900 --template-dir build/template -runner7: build/release/ftl-runner --key R01H8DD18Z6CTY301G8GE8N52CP --language go --language kotlin --bind http://localhost:8901 --template-dir build/template -runner8: build/release/ftl-runner --key R01H8DD1D1W3KJG7NY63DYCCJMY --language go --language kotlin --bind http://localhost:8902 --template-dir build/template -runner9: build/release/ftl-runner --key R01H8J2BMH8VTNKAT8MB66Q2SHG --language go --language kotlin --bind http://localhost:8903 --template-dir build/template +runner0: build/release/ftl-runner --key R01H5BTS6ABP1EHGZSAGJMBV50A --language go --language kotlin --bind http://localhost:${PORT} --template-dir build/template +runner1: build/release/ftl-runner --key R01H5BTSGKQ8AZ9S22N9N1SM9HV --language go --language kotlin --bind http://localhost:${PORT} --template-dir build/template +runner2: build/release/ftl-runner --key R01H8DD0H13WX636B70WV7D216G --language go --language kotlin --bind http://localhost:${PORT} --template-dir build/template +runner3: build/release/ftl-runner --key R01H8DD0V6EFZWKV2G2XBBHEDP9 --language go --language kotlin --bind http://localhost:${PORT} --template-dir build/template +runner4: build/release/ftl-runner --key R01H8DD0Z5GRT3QP1MBARC4TW08 --language go --language kotlin --bind http://localhost:${PORT} --template-dir build/template +runner5: build/release/ftl-runner --key R01H8DD12R0RZZS8AGYBGVP5KQ8 --language go --language kotlin --bind http://localhost:${PORT} --template-dir build/template +runner6: build/release/ftl-runner --key R01H8DD15Y9SPGDQMXNJ0CF3C5M --language go --language kotlin --bind http://localhost:${PORT} --template-dir build/template +runner7: build/release/ftl-runner --key R01H8DD18Z6CTY301G8GE8N52CP --language go --language kotlin --bind http://localhost:${PORT} --template-dir build/template +runner8: build/release/ftl-runner --key R01H8DD1D1W3KJG7NY63DYCCJMY --language go --language kotlin --bind http://localhost:${PORT} --template-dir build/template +runner9: build/release/ftl-runner --key R01H8J2BMH8VTNKAT8MB66Q2SHG --language go --language kotlin --bind http://localhost:${PORT} --template-dir build/template diff --git a/backend/common/download/download.go b/backend/common/download/download.go index b8edd6e58d..5fefc6c9f2 100644 --- a/backend/common/download/download.go +++ b/backend/common/download/download.go @@ -4,6 +4,7 @@ import ( "context" "os" "path/filepath" + "time" "connectrpc.com/connect" "github.com/alecthomas/errors" @@ -23,6 +24,8 @@ func Artefacts(ctx context.Context, client ftlv1connect.ControllerServiceClient, if err != nil { return errors.WithStack(err) } + start := time.Now() + count := 0 var digest string var w *os.File for stream.Receive() { @@ -32,6 +35,7 @@ func Artefacts(ctx context.Context, client ftlv1connect.ControllerServiceClient, if w != nil { w.Close() } + count++ if !filepath.IsLocal(artefact.Path) { return errors.Errorf("path %q is not local", artefact.Path) } @@ -59,5 +63,6 @@ func Artefacts(ctx context.Context, client ftlv1connect.ControllerServiceClient, if w != nil { w.Close() } + logger.Infof("Downloaded %d artefacts in %s", count, time.Since(start)) return errors.WithStack(stream.Err()) } diff --git a/examples/echo-kotlin/pom.xml b/examples/echo-kotlin/pom.xml index 796e37332a..284a914d0f 100644 --- a/examples/echo-kotlin/pom.xml +++ b/examples/echo-kotlin/pom.xml @@ -1,6 +1,6 @@ + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 xyz.block @@ -86,6 +86,17 @@ + + copy-dependencies + compile + + copy-dependencies + + + ${project.build.directory}/dependency + runtime + + @@ -133,4 +144,4 @@ - + \ No newline at end of file diff --git a/kotlin-runtime/ftl-generator/src/main/kotlin/xyz/block/ftl/generator/ModuleGenerator.kt b/kotlin-runtime/ftl-generator/src/main/kotlin/xyz/block/ftl/generator/ModuleGenerator.kt index 0f7daaa88c..42385911e2 100644 --- a/kotlin-runtime/ftl-generator/src/main/kotlin/xyz/block/ftl/generator/ModuleGenerator.kt +++ b/kotlin-runtime/ftl-generator/src/main/kotlin/xyz/block/ftl/generator/ModuleGenerator.kt @@ -175,7 +175,7 @@ class ModuleGenerator() { """ module = "${module}" language = "kotlin" - deploy = ["main", "classes"] + deploy = ["main", "classes", "dependency"] """.trimIndent() ) @@ -183,7 +183,7 @@ class ModuleGenerator() { mainFile.writeText( """ #!/bin/bash - exec java -cp ftl/jars/ftl-runtime.jar:classes xyz.block.ftl.main.MainKt + exec java -cp "classes:$(printf %s: dependency/*.jar)" xyz.block.ftl.main.MainKt """.trimIndent(), ) mainFile.setPosixFilePermissions(