dobu-run: Implement support for persistent HOME inside containers

This commit is contained in:
Peter Cai 2023-06-05 22:22:36 -04:00
parent 6cabe49345
commit 0ea062b5e4
4 changed files with 24 additions and 0 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
config.sh

5
config-default.sh Normal file
View file

@ -0,0 +1,5 @@
# Where should the home directories used in containers be persisted
HOMEDIR_STORAGE=$HOME/.local/share/dobu/homedir
# Whether btrfs subvolumes should be used for homes instead of
# normal subdirectories
HOMEDIR_IS_BTRFS=false

View file

@ -9,9 +9,11 @@ assert_prerequisites
image_name="$(path_to_image_name "apps/$1")"
# image_name is of the form dobu/xxxx, while for containers we want dobu-xxx
container_name="${image_name/\//-}"
home_path="$HOMEDIR_STORAGE/$1"
log "Image name: $image_name"
log "Container name: $container_name"
log "Home directory path: $home_path"
assert_image_exists "$image_name"
@ -28,6 +30,17 @@ fi
# Make sure we have Sommelier running first
ensure_sommelier
# Prepare $HOME for the container
if [ ! -d "$home_path" ]; then
if [ "$HOMEDIR_IS_BTRFS" == "true" ]; then
log "Creating $home_path as a btrfs subvolume"
btrfs subvol create "$home_path"
else
log "Creating $home_path"
mkdir -p "$home_path"
fi
fi
# The fun part: start the container!
# Don't detach like we did with Sommelier, though
podman run --rm --userns=keep-id:uid=1100,gid=1100 \
@ -48,6 +61,8 @@ podman run --rm --userns=keep-id:uid=1100,gid=1100 \
`# Pass through PulseAudio` \
-v "$host_pulse":/xdg_runtime/pulse/native \
-e PULSE_SERVER=unix:/xdg_runtime/pulse/native \
`# $HOME` \
-v "$home_path":/home/user \
`# Miscellaneous` \
-e XDG_SESSION_TYPE=wayland \
-e TZ="$(date +%Z)" \

View file

@ -6,6 +6,9 @@ script_path="$(dirname "$(realpath "$0")")"
DOBU_TMP=/tmp/dobu
. "$script_path/config-default.sh"
[ -f "$script_path/config.sh" ] && . "$script_path/config.sh"
assert_prerequisites() {
command -v podman >/dev/null 2>&1 || die "Podman is required"
[ -S "$XDG_RUNTIME_DIR/$WAYLAND_DISPLAY" ] || die "Dobu must be run under a compliant Wayland compositor"