From d5db7d7ea4a3bb9bc6e5588e6295fc21d361ddb4 Mon Sep 17 00:00:00 2001 From: Christophe Date: Sun, 12 Apr 2026 14:59:12 +0200 Subject: [PATCH] =?UTF-8?q?Corrige=20le=20cache=20des=20mises=20=C3=A0=20j?= =?UTF-8?q?our=20LXC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/install-proxmox-lxc.sh | 9 +++- scripts/update-proxmox-lxc.sh | 80 +++++++++++++++++++++++++++++++++- 2 files changed, 86 insertions(+), 3 deletions(-) diff --git a/scripts/install-proxmox-lxc.sh b/scripts/install-proxmox-lxc.sh index ed7aebe..aa198b7 100755 --- a/scripts/install-proxmox-lxc.sh +++ b/scripts/install-proxmox-lxc.sh @@ -362,6 +362,7 @@ fi git fetch origin \"\$branch\" git pull --ff-only origin \"\$branch\" +asset_version=\"\$(git rev-parse --short HEAD)\" install -d -m 0755 \"\$web_root\" @@ -380,6 +381,10 @@ rsync -a --delete \ --exclude='*' \ \"\$repo_dir/\" \"\$web_root/\" +while IFS= read -r -d '' html_file; do + perl -0pi -e 's{((?:href|src)=\")(?!https?://|data:|//)([^\"?]+?\.(?:css|js|png|jpg|jpeg|svg|webp|ico|pdf))(?:\?[^"]*)?(\")}{\$1 . \$2 . \"?v='"\"\$asset_version\""'\" . \$3}ge' \"\$html_file\" +done < <(find \"\$web_root\" -maxdepth 1 -type f -name '*.html' -print0) + chown -R www-data:www-data \"\$web_root\" nginx -t @@ -401,8 +406,8 @@ server { } location ~* \.(?:css|js|png|jpg|jpeg|svg|webp|ico|pdf)$ { - expires 7d; - add_header Cache-Control 'public, max-age=604800'; + expires -1; + add_header Cache-Control 'no-cache, no-store, must-revalidate'; } } NGINX diff --git a/scripts/update-proxmox-lxc.sh b/scripts/update-proxmox-lxc.sh index f8a7499..60b5050 100755 --- a/scripts/update-proxmox-lxc.sh +++ b/scripts/update-proxmox-lxc.sh @@ -155,7 +155,85 @@ if ! pct status "$ctid" | grep -q "running"; then sleep 5 fi -pct exec "$ctid" -- test -x /usr/local/bin/update-chesscubing || die "Le script /usr/local/bin/update-chesscubing est absent dans le conteneur." +ct_exec() { + pct exec "$ctid" -- bash -lc "$1" +} + +ct_exec "cat > /usr/local/bin/update-chesscubing <<'SCRIPT' +#!/usr/bin/env bash +set -Eeuo pipefail + +trap 'printf \"Erreur: echec de la commande [%s] a la ligne %s.\\n\" \"\$BASH_COMMAND\" \"\$LINENO\" >&2' ERR + +repo_dir='/opt/chesscubing/repo' +web_root='/var/www/chesscubing/current' +branch=\"\${1:-${repo_branch}}\" + +cd \"\$repo_dir\" + +if ! git diff --quiet || ! git diff --cached --quiet; then + echo 'Le depot de production contient des modifications locales. Mise a jour annulee.' >&2 + exit 1 +fi + +current_branch=\"\$(git rev-parse --abbrev-ref HEAD)\" +if [[ \"\$current_branch\" != \"\$branch\" ]]; then + git checkout \"\$branch\" +fi + +git fetch origin \"\$branch\" +git pull --ff-only origin \"\$branch\" +asset_version=\"\$(git rev-parse --short HEAD)\" + +install -d -m 0755 \"\$web_root\" + +rsync -a --delete \ + --include='*/' \ + --include='*.html' \ + --include='*.css' \ + --include='*.js' \ + --include='*.png' \ + --include='*.jpg' \ + --include='*.jpeg' \ + --include='*.svg' \ + --include='*.webp' \ + --include='*.ico' \ + --include='*.pdf' \ + --exclude='*' \ + \"\$repo_dir/\" \"\$web_root/\" + +while IFS= read -r -d '' html_file; do + perl -0pi -e 's{((?:href|src)=\")(?!https?://|data:|//)([^\"?]+?\.(?:css|js|png|jpg|jpeg|svg|webp|ico|pdf))(?:\?[^"]*)?(\")}{\$1 . \$2 . \"?v='"\"\$asset_version\""'\" . \$3}ge' \"\$html_file\" +done < <(find \"\$web_root\" -maxdepth 1 -type f -name '*.html' -print0) + +chown -R www-data:www-data \"\$web_root\" + +nginx -t +systemctl reload nginx +SCRIPT +chmod +x /usr/local/bin/update-chesscubing" + +ct_exec "cat > /etc/nginx/sites-available/chesscubing.conf <<'NGINX' +server { + listen 80; + listen [::]:80; + server_name _; + + root /var/www/chesscubing/current; + index index.html; + + location / { + try_files \$uri \$uri/ /index.html; + } + + location ~* \.(?:css|js|png|jpg|jpeg|svg|webp|ico|pdf)$ { + expires -1; + add_header Cache-Control 'no-cache, no-store, must-revalidate'; + } +} +NGINX +rm -f /etc/nginx/sites-enabled/default +ln -sf /etc/nginx/sites-available/chesscubing.conf /etc/nginx/sites-enabled/chesscubing.conf" pct exec "$ctid" -- /usr/local/bin/update-chesscubing "$repo_branch"