From 40f38b58e793b9b61ca4272a7a96f3bbab6810c9 Mon Sep 17 00:00:00 2001 From: Tim Perkins Date: Fri, 12 Jun 2026 22:17:16 -0400 Subject: [PATCH] Use bind mounts for shell config --- containers/base/Containerfile | 7 +------ containers/base/shell_init.sh | 30 ++++++++++++++++++++++++++++++ containers/run.sh | 19 ++++--------------- 3 files changed, 35 insertions(+), 21 deletions(-) create mode 100755 containers/base/shell_init.sh diff --git a/containers/base/Containerfile b/containers/base/Containerfile index 444d842..963ee2c 100644 --- a/containers/base/Containerfile +++ b/containers/base/Containerfile @@ -159,12 +159,6 @@ ENV SHELL_CONFIG_DIR="$VOLS_DIR/shell" RUN mkdir -m 755 $SHELL_CONFIG_DIR \ && chown $DEV_USER_UID:$DEV_USER_GID $SHELL_CONFIG_DIR -# Setup Bash history -RUN BASH_CONFIG_DIR=$SHELL_CONFIG_DIR/bash \ - && sudo -u $DEV_USER mkdir -m 755 $BASH_CONFIG_DIR \ - && sudo -u $DEV_USER touch $BASH_CONFIG_DIR/bash_history \ - && sudo -u $DEV_USER ln -s $BASH_CONFIG_DIR/bash_history $DEV_USER_HOME/.bash_history - # Modify PS1 to put a * after the hostname. This is sort of useful because it # let's you quickly see if you are inside the container or not. RUN sed -i 's;PS1.*\\h;&*;' /root/.bashrc $DEV_USER_HOME/.bashrc @@ -184,6 +178,7 @@ RUN mkdir -m 755 $ENTRYPOINT_DIR COPY entrypoint.sh /entrypoint.sh COPY fix_user.sh $ENTRYPOINT_DIR/00_fix_user.sh COPY login_shim.sh $ENTRYPOINT_DIR/01_login_shim.sh +COPY shell_init.sh $ENTRYPOINT_DIR/04_shell_init.sh # Add ~/.bashrc.d support to the user's ~/.bashrc COPY bashrcd_fragment.bash /tmp/bashrcd_fragment.bash diff --git a/containers/base/shell_init.sh b/containers/base/shell_init.sh new file mode 100755 index 0000000..c6f8a7a --- /dev/null +++ b/containers/base/shell_init.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +# Copyright (c) 2026 Tim Perkins + +set -o errexit +set -o nounset +set -o pipefail +IFS=$'\n\t' + +# This should never happen, but check anyway +if [ -z "${SHELL_CONFIG_DIR:-}" ]; then + echo "ERROR: Essential shell variable is not defined!" >&2 + exit 1 +fi + +is_empty_dir() { + find "$1" -maxdepth 0 -type d -empty | grep -q . +} + +bash_config_dir=$SHELL_CONFIG_DIR/bash + +if is_empty_dir $SHELL_CONFIG_DIR; then + mkdir -m 700 $bash_config_dir + touch $bash_config_dir/bash_history +fi + +# Always create the symlink in the home directory +ln -s $bash_config_dir/bash_history $HOME/.bash_history + +exec "$@" diff --git a/containers/run.sh b/containers/run.sh index 3b27d71..c6db358 100755 --- a/containers/run.sh +++ b/containers/run.sh @@ -11,9 +11,6 @@ IFS=$'\n\t' IMAGE_REPO="ghcr.io/taughz/dev" DEFAULT_TARGET_TAG="main" -# The names of the volumes -SHELL_CONFIG_VOL="shell-config" - # The default projects directory DEFAULT_PROJECTS_DIR="$HOME/Projects" @@ -138,15 +135,6 @@ SHELL_CONFIG_DIR=$(get_from_env "$IMAGE_ENV" "SHELL_CONFIG_DIR") EMACS_CONFIG_DIR=$(get_from_env "$IMAGE_ENV" "EMACS_CONFIG_DIR" || true) DOOM_CONFIG_DIR=$(get_from_env "$IMAGE_ENV" "DOOM_CONFIG_DIR" || true) -# Check for volumes, create them if necessary -vols=($SHELL_CONFIG_VOL) -for vol in "${vols[@]}"; do - if ! docker volume ls -q | grep -q $vol; then - echo "Creating volume: $vol" >&2 - docker volume create $vol > /dev/null - fi -done - # Ensure the files and directories we expect exist ensure_exists f 600 $HOME/.Xauthority ensure_exists d 700 $HOME/.ssh @@ -156,6 +144,7 @@ ensure_exists d 700 $HOME/.xpra ensure_exists f 600 $HOME/.claude.json ensure_exists d 700 $HOME/.claude ensure_exists d 700 $HOME/.taughz +ensure_exists d 700 $HOME/.taughz/shell ensure_exists d 700 $HOME/.taughz/emacs.d ensure_exists d 700 $HOME/.taughz/doom.d @@ -210,7 +199,7 @@ CLAUDE_FLAGS=( ) SHELL_FLAGS=( - --mount "type=volume,src=$SHELL_CONFIG_VOL,dst=$SHELL_CONFIG_DIR" + --mount "type=bind,src=$HOME/.taughz/shell,dst=$SHELL_CONFIG_DIR" ) emacs_flags=() @@ -232,8 +221,8 @@ if [ $use_tz -ne 0 ]; then fi echo_cmd docker run --rm --tty --interactive --privileged --network=host --env "TERM=$TERM" \ - "${DISPLAY_FLAGS[@]}" "${SSH_FLAGS[@]}" "${GPG_FLAGS[@]}" "${GIT_FLAGS[@]}" \ - "${XPRA_FLAGS[@]}" "${CLAUDE_FLAGS[@]}" "${SHELL_FLAGS[@]}" "${fixed_user_flags[@]}" \ + "${fixed_user_flags[@]}" "${DISPLAY_FLAGS[@]}" "${SSH_FLAGS[@]}" "${GPG_FLAGS[@]}" \ + "${GIT_FLAGS[@]}" "${XPRA_FLAGS[@]}" "${CLAUDE_FLAGS[@]}" "${SHELL_FLAGS[@]}" \ "${emacs_flags[@]}" "${projects_flags[@]}" "${tz_flags[@]}" "$TARGET_IMAGE" exit 0