Add Dockerfile and devcontainer.json
This allows both interactive use in IDEs/editors with dev container support as well as building inside the dev container from the command line. The changes are based on https://github.com/kon-foo/InfiniSim/tree/docker-builder-image.
The original PR was extended with the following features:
- ccache and ninja are installed for optional faster builds. Using ninja instead of make speeds up the build from ~ 28 s to 17 s on my machine with 16 threads.
- git and sudo are added for interactive use of the devcontainer
- Store bash history in volume to preserve it across rebuilds
- The non-root user ubuntu with sudo password "ubuntu" was added and is used to avoid producing build artifacts owned by root
- Split args into CMake generation time and CMake build time args
- Allow passing the build directory in docker run
Thank you for the review @NeroBurner, I think I integrated all your findings.
I also changed the following:
- Change the container user to ubuntu:ubuntu since that one already exists anyway. There were also permisison issues stemming from not using ubuntu since the external user would likely have UID 1000 (at least on single user systems). That would lead to external files mapped into the container being owned by ubuntu, not infinitime, which has UID 1001
- Split installation into three sections to increase layer granularity for caching
If you want, I can look into using the container in the pipeline as well. That would ensure that the container itself builds and the application builds inside the container. I would create a second PR for that if you are interested.
I added all review suggestions and tested this in CLion CLion 2024.3.4 and VsCode and (had to add a workaround for a bug in CLion), the devcontainer works in both. Regarding CI usage, I can experiment in my fork to find out about the runtime impact. It is a separate change anyway.