mirror of
https://gitlab.kitware.com/cmake/cmake.git
synced 2026-09-25 04:09:36 +03:00
Provide a `.devcontainer` definition, following the Dev Container Specification, to give contributors a ready-made Linux environment with the tools needed to build CMake, run its test suite, build its documentation, and satisfy its style rules. Base the container on Ubuntu, which offers the broadest ecosystem of packages and tooling for development, including a recent `cmake` and the `clang-format` version our style rules require, exactly. Mirror the package lists of the Debian image our CI infrastructure uses, section by section, so that the dependencies available closely match the ones against which merge requests are tested. Build the image the way the images under `.gitlab/ci/docker/` are built: bind mount the package lists and the installation script rather than copying them in, and cache the package lists and downloaded archives so that a rebuild fetches only what has changed. Run optional `.devcontainer/hooks/root.sh` and `.devcontainer/hooks/user.sh` scripts, both ignored by Git, so that developers may customize the container without modifying tracked files. Document usage in a new `Help/dev/devcontainer.rst`. Fixes: #28043
39 lines
1.4 KiB
Bash
Executable File
39 lines
1.4 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
# Create the unprivileged user that the container runs as, given its name,
|
|
# uid, and gid. See `Help/dev/devcontainer.rst`.
|
|
|
|
set -e
|
|
|
|
readonly username="$1"
|
|
readonly uid="$2"
|
|
readonly gid="$3"
|
|
|
|
# The base image already ships an unprivileged user, which usually occupies
|
|
# the uid we want. Remove whoever holds it, and the group holding our gid,
|
|
# before creating ours.
|
|
if getent passwd "$uid" > /dev/null; then
|
|
userdel --remove "$(getent passwd "$uid" | cut -d: -f1)"
|
|
fi
|
|
if getent group "$gid" > /dev/null; then
|
|
groupdel "$(getent group "$gid" | cut -d: -f1)"
|
|
fi
|
|
|
|
groupadd --gid "$gid" "$username"
|
|
useradd --uid "$uid" --gid "$gid" --create-home --shell /bin/bash "$username"
|
|
|
|
# Let the user administer the container, e.g. to install more packages.
|
|
echo "$username ALL=(ALL) NOPASSWD:ALL" > "/etc/sudoers.d/$username"
|
|
chmod 0440 "/etc/sudoers.d/$username"
|
|
|
|
# Pre-create the directories that `devcontainer.json` mounts volumes over so
|
|
# that the volumes inherit the ownership recorded here. Name the parents too:
|
|
# `install -d` records the ownership only of the directories it is given, and
|
|
# tools that write elsewhere under them need to own them as well.
|
|
install -d -o "$username" -g "$username" \
|
|
"/home/$username/.cache" \
|
|
"/home/$username/.cache/ccache" \
|
|
"/home/$username/.config" \
|
|
"/home/$username/.config/glab-cli" \
|
|
"/home/$username/workspace"
|