Hi,
I’m doing small pet project on ocaml and all went well until I decided to write some deployment scripts.
I must say, that I’m not seeking easy solution, my goal (just as an exercise) is total automation.
So, I thought about nix, but I don’t like the idea to use it for package management instead of opam + dune.
I decided to try terraform + anasible + docker.
Terraform for creating digital ocean droplet.
Ansible for basic droplet configuration.
Docker for building application.
There are 2 major problems:
Building my project requires a lot of RAM, at least 3GB, so I have to use expensive server. But I guess I can overcome it by building image locally inside docker.
Docker has mount=cache feature for caching dependencies, however I cannot make it work with opam. Are there some exmaples on how it can be done?
Or may be there is some other way I didn’t think of?
Well, in the end I decided to GH actions (Set up OCaml · Actions · GitHub Marketplace · GitHub) to build binary and publish it as an artefact. Terraform creates a droplet, ansible uses TF state to ssh to the created droplet, download the binary from GH actions, create a systemd service and restarts it.
The only challenge was to integrate ansible and gh-actions. I ended up writing my custom python ansible module, but actually I could may be use gh-cli via ansible for that.
Anyway, it works and I’m pretty happy.
The only problem is that ocaml gh action does not caches builded deps, so despite the fact that I deployed self-hosted GH actions runner on my home computer with Ryzen 5900, it still runs approx 5 minutes in total.