#!/bin/sh set -eu # The runner's Docker volume survives individual checkouts. It contains a # copy of the Git originals, optimized variants, and the hash manifests used # by optimize-images.mjs. cache_namespace=$(printf '%s' "${IMAGE_CACHE_NAMESPACE:-shared}" | tr -c 'A-Za-z0-9_.-' '-') case "$cache_namespace" in ''|*[!A-Za-z0-9_.-]*) echo "IMAGE_CACHE_NAMESPACE may only contain letters, digits, ., _ and -" >&2 exit 1 ;; esac cache_volume="website-starter-image-cache-${cache_namespace}" docker volume create "$cache_volume" >/dev/null app_dir="$(pwd)" run_image_prune() { docker run --rm "$@" \ --mount "type=volume,src=$cache_volume,dst=/image-cache" \ --workdir "$app_dir" \ --env IMAGE_CACHE_ROOT=/image-cache \ --env HOST_UID="$(id -u)" \ --env HOST_GID="$(id -g)" \ node:24-slim \ sh -ec ' npm run images:prune chown -R "$HOST_UID:$HOST_GID" /image-cache "$PWD/public/images/content" "$PWD/public/images/slider" "$PWD/public/images/secondary-slider" "$PWD/public/images/backgrounds" ' } # In Gitea Actions, the Docker daemon cannot bind-mount the job container's # workspace path. Share its existing workspace volume instead. if docker inspect "$(hostname)" >/dev/null 2>&1; then run_image_prune --volumes-from "$(hostname)" else run_image_prune --mount "type=bind,src=$app_dir,dst=$app_dir" fi