When building container images for applications in interpreted languages (such as Python or JavaScript), the approach is mostly the same:
- Install dependencies.
- Copy source files to the container image.
- Copy the necessary configuration.
- Set the runtime command.
For compiled applications, however, there's an additional step of compiling the application first. There are several possible ways to implement this step, each of them with their pros and cons.
The most obvious approach is to install all the dependencies first, copy the source files, and then compile the application as one of the container build steps. The major benefit is that we can accurately control the toolchain's contents and configuration and therefore have a portable way to build an application. However, the downside is too big to ignore: the resulting container image contains a lot of unnecessary files. After all, we will need neither source code nor the toolchain during...