From 7a039b23f4e10282cdd672bbaae6d8205a950ea6 Mon Sep 17 00:00:00 2001 From: Stan Runge Date: Sat, 24 Oct 2026 01:59:11 +0000 Subject: [PATCH] deploy: check the books dir from a root container (deploy user cannot traverse /home/stan) Run #78 skipped the /books mount because [ -d /home/stan/books/library ] runs as the deploy account, which has no access to /home/stan (0750). Check inside a container with the dir bind-mounted instead; the mount itself is done by dockerd. --- scripts/deploy-remote.sh | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/scripts/deploy-remote.sh b/scripts/deploy-remote.sh index ebd165b..ee6a73a 100644 --- a/scripts/deploy-remote.sh +++ b/scripts/deploy-remote.sh @@ -19,13 +19,26 @@ environment_name=production image="git.stanrunge.dev/stan/website:$sha" compose="$directory/compose.prod.yml" compose_files=(-f "$compose") +# Images built before the repo rename (stan/personal-website -> stan/website) keep +# their old local name; retag so rollbacks to those SHAs still work. +legacy_image="git.stanrunge.dev/stan/personal-website:$sha" +if ! sudo docker image inspect "$image" >/dev/null 2>&1 && + sudo docker image inspect "$legacy_image" >/dev/null 2>&1; then + sudo docker tag "$legacy_image" "$image" +fi +if ! sudo docker image inspect "$image" >/dev/null 2>&1; then + echo "Image $image is not on this host" >&2; exit 1 +fi # Book files (ebooks + covers) live on the host and are bind-mounted read-only at /books; # the app streams them only to the owner via /trackers/books/files/ (no static path). # Layout: $books_host_dir/library/ and $books_host_dir/covers/. # compose.prod.yml is host-managed, so the mount goes in a generated override file. books_host_dir=${BOOKS_HOST_DIR:-/home/stan/books} case "$books_host_dir" in /*) ;; *) echo 'BOOKS_HOST_DIR must be absolute' >&2; exit 2 ;; esac -if [ -d "$books_host_dir/library" ]; then +# The deploy account can't traverse /home/stan (0750); check from a root container instead. +if sudo docker run --rm --entrypoint sh \ + --mount "type=bind,source=$books_host_dir,target=/books,readonly" "$image" \ + -c 'test -d /books/library' 2>/dev/null; then sudo tee "$directory/compose.books.yml" >/dev/null <&2 fi -# Images built before the repo rename (stan/personal-website -> stan/website) keep -# their old local name; retag so rollbacks to those SHAs still work. -legacy_image="git.stanrunge.dev/stan/personal-website:$sha" -if ! sudo docker image inspect "$image" >/dev/null 2>&1 && - sudo docker image inspect "$legacy_image" >/dev/null 2>&1; then - sudo docker tag "$legacy_image" "$image" -fi -if ! sudo docker image inspect "$image" >/dev/null 2>&1; then - echo "Image $image is not on this host" >&2; exit 1 -fi previous_tag=$(sed -n 's/^IMAGE_TAG=//p' "$directory/.env" | head -n 1) switched=0 rollback() {