ocaml-layer (formerly “setup-ocaml”) is a small collection of scripts for creating custom Docker images and pushing them to Docker Hub. It solves the following problem:
- Installing external dependencies such as native packages, the right version of the ocaml compilers, and public opam packages takes a while - typically over 5 minutes.
- External dependencies don’t change very often, and we don’t we need nor want to build them each time some code changes in the project.
- There are typically no pre-built Docker images available that already contain all the dependencies for a project.
Spinning up a container with all dependencies pre-installed takes about 1 min or less on a service like CircleCI. The rest of the CI job is spent entirely on building and testing the project’s code. This is what you’ll get.
The solution consists in specifying the list of native packages and a list of opam packages, building a Docker container with those, and pushing them to Docker Hub. While there’s nothing new about this approach, I believe it is now easier and still flexible.