sozsoft-platform/ui/nginx/40-archive-assets.sh
2026-10-17 21:51:10 +03:00

31 lines
1.1 KiB
Bash
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/sh
# nginx imajı açılışta /docker-entrypoint.d/*.sh dosyalarını çalıştırır.
#
# İmajın hash'li chunk'larını (`dist/assets`) arşive ekler ve arşivi /srv/assets volume'unda
# biriktirir: var olan dosya ezilmez (hash'li ad = aynı içerik), yeni dosya kopyalanır. Böylece
# deploy'dan önce açılmış sekmeler kendi sürümlerinin chunk'larını bulmaya devam eder.
#
# Temizlik: imajda artık bulunmayan ve 30 günden eski dosyalar silinir. Çalışan sürümün dosyası
# ne kadar eski olursa olsun silinmez (kontrol imajdaki varlığa göredir, tarihe göre değil).
set -eu
SRC=/usr/share/nginx/html/assets
DST=/srv/assets
KEEP_DAYS=30
mkdir -p "$DST"
cd "$SRC"
find . -type f | while IFS= read -r file; do
[ -e "$DST/$file" ] && continue
mkdir -p "$DST/$(dirname "$file")"
cp "$file" "$DST/$file"
done
cd "$DST"
find . -type f -mtime +"$KEEP_DAYS" | while IFS= read -r file; do
[ -e "$SRC/$file" ] || rm -f "$file"
done
find . -type d -empty -delete 2>/dev/null || true
echo "[assets] arşiv: $(find "$DST" -type f | wc -l) dosya"