I’m in the process of slimming down some of the VPSs I use to run my websites and small webapps. Specifically I would like to slim down to a smaller Linode instance. This should have sufficient specifications for running my OCaml webapps, but compiling them on it (and maintaining the related dependencies) would be annoying. So I would like to build my apps as binaries on a different, more powerful machine and then move them over to my server for deployment.
Is this is a reasonable thing to do? Are there any gotchas I should be aware of? I’m planning on using 64-bit Alpine Linux on both my local machine and the Linode VPS.
It’s certainly reasonable and should be straightfoward if the OS and architecture match between your local host and the VPS (32bit vs 64bit, x86 vs ARM). One thing to watch out for is making sure you have any required system C dependencies available on the VPS if you’re not compiling completely static binaries.
You can use something like Docker (and maybe docker-compose if you have multiple containers) to wrap all this up into a container/containers but they’re not strictly necessary.
It works fine as long as the dependencies are there and the versions are compatible (the same distribution or an older version thereof). This is sometimes how I get amd64 GNU/Linux binaries built on the Macbook: run a Docker container, build binaries, copy binaries out. It is less of a headache than figuring out a cross-compiler toolchain and I can easily pick the base distribution.
Just want to add one point which I ran into not long ago. I was building some binaries in our CI system, and deploying them to an ec2 instance. At one point circleci started having major outages, and some time after, suddenly the app stopped working, no warnings. Upon further investigation I found that the binary included some fancy instructions for vector arithmetic. Turns out circleci had swapped out some of their hardware for some fancy machines with Xeon processors, and one of the libraries I depended on was building some C code under the hood and setting a flag to enable native optimizations. Essentially the generated binary was no longer compatible with vanilla x86-64 processors.
Not saying this will happen to you, but just a tidbit to store in the back of your brain for the day you need it.