Do y’all have best practices on using The Kotlin T...
# kotlin-toolchain
j
Do y’all have best practices on using The Kotlin Toolchain in CI environments? I’m currently installing the Kotiln Toolchain in my project’s Dockerfile like so:
Copy code
# We run '--version' because it downloads its dependencies on the first run.
ENV KOTLIN_CLI_NO_WELCOME_BANNER="1"
ENV KOTLIN_CLI_JAVA_HOME="$JAVA_HOME"
ENV HOME="/root"
ENV PATH="/root/.local/bin:$PATH"
RUN echo "Installing Kotlin toolchain" \
    && set -o errexit -o nounset \
    && curl -fsSL <https://kotl.in/install.sh> | sh \
    && kotlin --version
Setting it up in the Dockerfile is good! • It calls the JetBrains CDNs when I rebuild the Dockerfile (~monthly), not every build (~hourly) • Docker caches work well, especially in my CI service (Buildkite) Anyone else using The Kotlin Toolchain in CI?
➕ 1
I can’t figure out how to pin a specific version. When I call
kotlin update
, that applies to the wrapper script in the current directly. I can’t figure out how to configure the version of the
kotlin
on my
$PATH
.
Ooooh, this will work:
Copy code
cd $HOME/.local/bin
kotlin update --target-version 0.12.0 --create
alright, this is where I ultimately landed, after discovering that trick
Copy code
# Kotlin toolchain.
# We run '--version' because it downloads its dependencies on the first run.
ENV KOTLIN_CLI_VERSION="0.12.0"
ENV KOTLIN_CLI_HOME="/root/.local/bin"
ENV KOTLIN_CLI_JAVA_HOME="$JAVA_HOME"
ENV KOTLIN_CLI_NO_WELCOME_BANNER="1"
ENV PATH="$KOTLIN_CLI_HOME:$PATH"
RUN echo "Installing Kotlin toolchain" \
    && set -o errexit -o nounset \
    && curl -fsSL <https://kotl.in/install.sh> | sh \
    && cd "$KOTLIN_CLI_HOME" \
    && kotlin update --target-version "$KOTLIN_CLI_VERSION" --create \
    && kotlin --version \
    && cd / \
github.com/wasmcomputercompany/brevity/blob/…/Dockerfile#…
One drawback of the above is it downloads the latest version AND the specified version when they’re not equal
t
Replace the download url with
<https://packages.jetbrains.team/maven/p/amper/amper/org/jetbrains/kotlin/kotlin-cli/${version}/kotlin-cli-${version}-installer.sh>
packages.jetbrains.team/maven/…/kotlin-cli Tho it might break in future
💯 1
j
Oh I like that
j
Hi Jesse! As usual, thanks for sharing your experience here, it's super useful. I'm wondering why you want to have the Kotlin CLI pre-installed in your docker image. If you have some caching setup in your CI, the `kotlin`/`kotlin.bat` wrappers would take care of provisioning the toolchain they need. And then you can save that part of the cache. Are you trying to save on cache downloads by baking it in? Also do you want to use this Docker image in multiple projects with potentially different Kotlin Toolchain versions?
j
When you say "some caching setup in your CI" what would that be?
j
I mean caching dependencies, Kotlin/Native commonized libs, and maybe the build cache as well, this sort of stuff
In your Gradle setups, do you usually cache some of that stuff?
j
Yeah, with Artifactory!
I assume I can use a custom Maven repo to do that for TKC. But to cache TKC itself?
j
Mmh OK I was more asking about a CI-level cache that would be restored before your build even starts. Something like GitHub Actions cache. So if I understand correctly, you're using an Artifactory repo to mirror Maven Central and/or add more dependencies, and your CI builds always perform remote dependency resolution and re-download stuff from this mirror, right?
I'm working on this composite GitHub Action to leverage the cache from GitHub Actions for Kotlin Toolchain projects, a bit like
setup-gradle
does: github.com/JetBrains/kotlin-toolchain/blob/…/action.yml So this is why I'm asking about caching. Because since the
kotlin
wrapper in your project can provision everything, I usually would rely purely on the CI's cache to streamline this.
j
Oooh this is handy. I can use these paths to do file system caching
👍🏼 1
(my CI can mount a cache directory, if I know it's path)
j
Yes exactly. Side note, though: this cache structure is a bit of a mess at the moment, so it's likely to change (I really want to tidy things up there)
💯 2