Speed up dockerization

I am deploying Julia code using docker. In order to speed up the startup of the container I build a package using PackageCompiler.jl.

However this is painfully slow, as it rebuilds everything even if I change one line in the final main entrypoint. Are there any best practices to speed this up? How could I build a sysimage with just the packages and do not precompile my application code? Do I just make a sysimage in a builder stage and copy it over into the the final output stage of the image, together with the main application source code?

I went with a persistent build cache that stores the precompiled package images so that the dependencies don’t need to be recompiled every time. I followed this post.

Is the source code of the packages still in the image? I cannot have that for some private packages.

Oh, I see. In our case that wasn’t a restriction, and the source code is indeed present in the image.

If I do not need to copy the whole .julia this might be possible.

In my limited experience, PrecompileTools.jl can usually make the load time fast enough, so I don’t resort to PackageCompiler, considering that there’s also a startup delay in launching any Docker container. (To clarify, the precompile process is added as a build step for the Docker image.)

1 Like

Also nice. What part of the JULIA_DEPOT_PATH do I need to copy over from the builder stage?

Sorry, I meant just as a step in Dockerfile, not in a separate builder image. If you run “Pkg.precompile()” in the Dockerfile, then the precompile cache is saved.

I understood that, but I do not want to copy everything. As I wrote earlier I specifically do not want the source code in the final image.