Corrige le cache des mises à jour LXC

This commit is contained in:
2026-04-12 14:59:12 +02:00
parent 15528c2062
commit d5db7d7ea4
2 changed files with 86 additions and 3 deletions

View File

@@ -362,6 +362,7 @@ fi
git fetch origin \"\$branch\" git fetch origin \"\$branch\"
git pull --ff-only origin \"\$branch\" git pull --ff-only origin \"\$branch\"
asset_version=\"\$(git rev-parse --short HEAD)\"
install -d -m 0755 \"\$web_root\" install -d -m 0755 \"\$web_root\"
@@ -380,6 +381,10 @@ rsync -a --delete \
--exclude='*' \ --exclude='*' \
\"\$repo_dir/\" \"\$web_root/\" \"\$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\" chown -R www-data:www-data \"\$web_root\"
nginx -t nginx -t
@@ -401,8 +406,8 @@ server {
} }
location ~* \.(?:css|js|png|jpg|jpeg|svg|webp|ico|pdf)$ { location ~* \.(?:css|js|png|jpg|jpeg|svg|webp|ico|pdf)$ {
expires 7d; expires -1;
add_header Cache-Control 'public, max-age=604800'; add_header Cache-Control 'no-cache, no-store, must-revalidate';
} }
} }
NGINX NGINX

View File

@@ -155,7 +155,85 @@ if ! pct status "$ctid" | grep -q "running"; then
sleep 5 sleep 5
fi 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" pct exec "$ctid" -- /usr/local/bin/update-chesscubing "$repo_branch"