Is there a concise guide to deploying Kotlin full ...
# server
h
Is there a concise guide to deploying Kotlin full stack multiplatform to your own server? I see the installDist steps which seem to just be wrapping up the various libs...following ktor example with shade didn't host the Javascript part...any good references?
I have a feeling the "right" answer is that one shouldn't use the full stack concept but instead a server and client in two separate sub-projects...
Just package your js into jar
h
Thanks! I may give that a try. Does that also have the hot reload that a front end only JS Web project would?
b
Yes, you can run vlient module independently and it has devserver setup to proxy the backend
👍 1
You can merge client module back into true fullstack if you want, but i simply prefer more modular approach. The key here is to pack js output into your fat jar and serve the page as static resources from ktor
h
I'm more interested in "full stack Kotlin" as in shared code between deployment targets not necessarily one uber-target (e.g. being able to build to iOS, Andriod, desktop, web site, and web services)
What is the
buildNativeImage
part of the gradle config doing btw?
b
You can ignore that. It basically packs my fat jar into standalone native executable with graalvm native image
So that I could pack it into lean and fast alpine based docker image
Total image size now it's just over 15mb
h
I thought that's what it was doing. Cool!
b
As compared to almost 200mb when packed with openjdk alpine base
h
Is it a GraalVM image that is self contained or are there dependencies in the Kotlin/Ktor stack that require a JDK installation? Using CIO makes me think you got it to be solely free-standing
n/m you said no openjdk
b
Yeah, with buildNativeImage you get fully standalone linux binary
Then I run upx to further compress it's size
Have a look at the dockerfile
h
Definitely will, thanks!
Right now just doing experimental project to prove to myself the real feasibility and robustness of Kotlin Multiplatform
b
Note that I couldn't ger embedded resources working on native image, so I'm servinge them from files that are copied over to the docker image separately
h
Deployed size bloat is a bit much but anything leveraging npm is going to have that problem
b
Look into graalvm native image for sure then, it reduces the size massivelly
h
How does it reduce the size of the npm node modules that get packaged up?
b
As for your js client, kotlin bundle sizes will always be slightly bigger. But the difference will be less apparent the bigger your project gets
Graalvm only reduces your backend size
h
Yeah it's the train of npm that's really huge
Kotlin React "hello world" type min size is like 2 MB versus fritz2's being about 800 KB of served Kotlin JS files but if they don't grow much either is in the acceptable range for most applications nowadays (besides potential time to render start)
Unfortunately I want to use the OpenGraph API generators which are dependent on Jackson so not sure if Graal can self-contain those or not.
(if I wanted to use that part of your gradle config)