Skip to content

Commit

Permalink
fix: include JAR dependencies in Kotlin deploys
Browse files Browse the repository at this point in the history
By adding the following fragment to the POM:

```xml
<execution>
    <id>copy-dependencies</id>
    <phase>compile</phase>
    <goals>
        <goal>copy-dependencies</goal>
    </goals>
    <configuration>
        <outputDirectory>${project.build.directory}/dependency</outputDirectory>
        <includeScope>runtime</includeScope>
    </configuration>
</execution>
```

`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.
  • Loading branch information
alecthomas committed Oct 12, 2023
1 parent c19fe47 commit 40457f8
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 15 deletions.
20 changes: 10 additions & 10 deletions Procfile.nowatch
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions backend/common/download/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"os"
"path/filepath"
"time"

"connectrpc.com/connect"
"github.com/alecthomas/errors"
Expand All @@ -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() {
Expand All @@ -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)
}
Expand Down Expand Up @@ -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())
}
17 changes: 14 additions & 3 deletions examples/echo-kotlin/pom.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
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">
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">

<modelVersion>4.0.0</modelVersion>
<groupId>xyz.block</groupId>
Expand Down Expand Up @@ -86,6 +86,17 @@
</artifactItems>
</configuration>
</execution>
<execution>
<id>copy-dependencies</id>
<phase>compile</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/dependency</outputDirectory>
<includeScope>runtime</includeScope>
</configuration>
</execution>
</executions>
</plugin>
<!-- Run the Wire compiler -->
Expand Down Expand Up @@ -133,4 +144,4 @@
</plugin>
</plugins>
</build>
</project>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -175,15 +175,15 @@ class ModuleGenerator() {
"""
module = "${module}"
language = "kotlin"
deploy = ["main", "classes"]
deploy = ["main", "classes", "dependency"]
""".trimIndent()
)

val mainFile = Path.of(buildDir, "main")
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(
Expand Down

0 comments on commit 40457f8

Please sign in to comment.