Read the health address and roll back correctly in the deploy script
All checks were successful
Validate and deploy Sokko G / validate (push) Successful in 22m48s
Validate and deploy Sokko G / deploy (push) Successful in 15s

Run 324 polled 127.0.0.1:5173 instead of the service's HOST and PORT:
each env file overwrote the value found in the previous one, even when it
did not define the variable, so the check failed against a healthy server.
The rollback then stopped at once, because its local previous_commit
redeclared the read-only global of the same name.

A file now keeps the value of the previous one unless it defines the
variable, and the rollback uses its own name. A test runs the lookup on
real env files and another forbids locals that shadow read-only globals;
both fail on the previous script. The fix applies once the script is
reinstalled on the server.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Shinuwa 2026-11-21 11:44:54 +01:00
parent 2831f01195
commit 632cc06a16
3 changed files with 41 additions and 5 deletions

View file

@ -43,8 +43,9 @@ as_app_user() {
sudo -u "$APP_USER" "$@"
}
# Le nom diffère de la variable globale `previous_commit`, en lecture seule : `local` la redéclarerait et arrêterait le script.
restore_previous_release() {
local previous_commit=$1
local rollback_commit=$1
as_app_user rm -rf -- "$APP_ROOT/website/dist"
if [[ -n "$backup_dist" && -d "$backup_dist" ]]; then
@ -55,18 +56,21 @@ restore_previous_release() {
as_app_user rm -rf -- "$APP_ROOT/node_modules"
as_app_user mv "$backup_node_modules" "$APP_ROOT/node_modules"
fi
as_app_user git -C "$APP_ROOT" checkout --detach "$previous_commit"
as_app_user git -C "$APP_ROOT" checkout --detach "$rollback_commit"
systemctl restart "$SERVICE_NAME" || true
}
# Valeur d'une variable telle que le service la voit : l'environnement systemd l'emporte sur le .env du site.
# Un fichier qui ne définit pas la variable garde la valeur trouvée dans le précédent.
service_env_value() {
local name=$1
local file value=""
local file found value=""
for file in "$APP_ROOT/.env" "$SERVICE_ENV_FILE"; do
[[ -r "$file" ]] || continue
value="$(sed -n "s/^[[:space:]]*$name[[:space:]]*=[[:space:]]*//p" "$file" | tail -n 1 | sed -e 's/^["'"'"']//' -e 's/["'"'"'][[:space:]]*$//' -e 's/[[:space:]]*$//')" || true
grep -Eq "^[[:space:]]*$name[[:space:]]*=" "$file" || continue
found="$(sed -n "s/^[[:space:]]*$name[[:space:]]*=[[:space:]]*//p" "$file" | tail -n 1 | sed -e 's/^["'"'"']//' -e 's/["'"'"'][[:space:]]*$//' -e 's/[[:space:]]*$//')" || true
value=$found
done
printf '%s' "$value"
}