From 9fe3eafde4d9c85c740384f0ed214b6930d96fee 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. --- backend/common/download/download.go | 5 +++++ examples/echo-kotlin/pom.xml | 17 ++++++++++++++--- .../xyz/block/ftl/generator/ModuleGenerator.kt | 4 ++-- 3 files changed, 21 insertions(+), 5 deletions(-) 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(