coder / envbuilder

Build development environments from a Dockerfile on Docker, Kubernetes, and OpenShift. Enable developers to modify their development environment quickly.
Apache License 2.0
111 stars 23 forks source link

fix(remount): relocate libraries along with their symlinks #255

Closed maxbrunet closed 2 weeks ago

maxbrunet commented 2 weeks ago

This PR adds:

  1. Look up the library directory, the value differs for Debian-based distros (the initial envbuilder image is non-Debian, but the final image may be Debian)
  2. Find the symlinks pointing to mounts in the library directory
  3. Temporarily move the library symlinks pointing to mounts to the magic directory while relocating the mounts
  4. Look up the new library directory (in case it has changed)
  5. Move back the library symlinks and mounts to the new library directory

After that the container should behave like a regular container created by the NVIDIA container runtime. Of course/unfortunately, the process of mounting/unmounting requires GPU containers to run with privileges:

Appropriate privilege (Linux: the CAP_SYS_ADMIN capability) is required to mount/umount filesystems.

https://www.man7.org/linux/man-pages/man2/mount.2.html https://www.man7.org/linux/man-pages/man2/umount.2.html

The logic is not generalized to any symlinks or any directories, it only aims at providing compatibility with the NVIDIA container runtime for now.

More context can be found in this comment https://github.com/coder/envbuilder/issues/143#issuecomment-2192405828

Tested with the following images:

Closes #143