Does Kotlin Native compile and run on RedHat's Universal Base Image (UBI)?
First, why build your container image on top of UBI at all? Well, it is apparently best practice on OpenShift, at least if you ask RedHat. They can explain better.
Since Kotlin Native does not work in quite any container — to my knowledge, Alpine is currently not supported — the question presents itself: will it run?
Turns out it does in the way you would expect:
FROM registry.access.redhat.com/ubi7/ubi:latest AS build
<install Java and Kotlin Native>
COPY hello-world.kt ./
RUN export PATH=kotlin-native-linux-${kotlin_version}/bin:$PATH \
&& kotlinc-native hello-world.kt -o hello-world
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
FROM registry.access.redhat.com/ubi7/ubi-minimal:latest AS run
COPY --from=build hello-world.kexe ./hello-world
CMD ./hello-world
I skipped the installation of Kotlin Native here;
it is not as neat as one would wish.
Maybe there will be a Full sources: Gist |
The final image is quite small (~80MB), with only a single binary added to the base image — which is, of course, the point of the exercise.
Proof of life:
$ docker build -t ubi-knative-demo . \
&& docker run --rm ubi-knative-demo
<snip>
Hello World, I'm Kotlin Native!
Building the
|