diff options
| -rw-r--r-- | README.md | 5 | ||||
| -rwxr-xr-x | dbx | 29 | ||||
| -rwxr-xr-x | dbx-create | 18 | ||||
| -rwxr-xr-x | dbx-init | 32 |
4 files changed, 84 insertions, 0 deletions
diff --git a/README.md b/README.md new file mode 100644 index 0000000..89efa6f --- /dev/null +++ b/README.md @@ -0,0 +1,5 @@ +# Containerized Development Environments + +`dbx` is a set of scripts for managing a local containerized development environment. It works by creating a long-lived container named `dbx` with only access to a development root directory, where you can install various developer tools and dependencies without losing sleep at night. + +At its heart, it is extremely similar to Toolbx and Distrobox, but with as reduced permissions as possible for improved security. For example, unlike the aforementioned tools, `dbx` keeps SELinux enforcement; meaning that the `dbx` user cannot access other files if it manages to escape the namespace. In general, it does not try to create a convenient container that is seamlessly integrated with the host, but rather a restricted sandbox where you can install development tools. @@ -0,0 +1,29 @@ +#!/usr/bin/env bash + +set -euo pipefail + +r="$HOME/.dbx" + +usage() { + cat <<EOF +dbx - containerized development environments + +USAGE: + dbx create creates a devbox if one does not already exist + dbx [enter] enters the devbox in the current directory + dbx run CMD [ARGS...] runs a command within the devbox +EOF +} + +cmd="${1:-enter}" +shift + +case "$#:$cmd" in + 0:create|0:enter|[1-9]:run|[1-9][0-9]:run) + "$r/dbx-$cmd" "$@" + ;; + *) + usage + exit 1 + ;; +esac diff --git a/dbx-create b/dbx-create new file mode 100755 index 0000000..bce4f89 --- /dev/null +++ b/dbx-create @@ -0,0 +1,18 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: 0BSD + +set -euo pipefail + +r="$HOME/.dbx" +d="$HOME/Developer/dbxroot" + +podman create \ + --hostname dbx \ + --label manager=dbx \ + --name dbx \ + --user root:root \ + --userns keep-id \ + --volume "$d:$d:z" \ + --volume "$r/dbx-init:/usr/local/bin/dbx-init:ro,z" \ + registry.fedoraproject.org/fedora-toolbox:43 \ + dbx-init diff --git a/dbx-init b/dbx-init new file mode 100755 index 0000000..21f8450 --- /dev/null +++ b/dbx-init @@ -0,0 +1,32 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: 0BSD + +set -euo pipefail + +if [[ ! -f /run/.containerenv ]]; then + echo "ERROR: not in a container." >&2 +fi + +h=/dbx + +dnf install -y \ + fish \ + fzf \ + netcat \ + ripgrep \ + vim-enhanced + +if [[ ! -d $h ]]; then + usermod \ + --home $h \ + --groups wheel \ + --password "" \ + --shell $(command -v fish) \ + $(id -nu 1000) + + mkdir --parents $h + chown --recursive 1000:1000 $h +fi + +touch /run/.dbxenv +sleep infinity |
