1

Déploiement sur serveur secondaire

This commit is contained in:
2026-03-11 23:16:25 +01:00
parent cbdd378c4b
commit 52562a8a8b

View File

@@ -13,6 +13,7 @@ fi
# Configuration # Configuration
DEST_USER="${DEPLOY_DEST_USER:?DEPLOY_DEST_USER manquant}" DEST_USER="${DEPLOY_DEST_USER:?DEPLOY_DEST_USER manquant}"
DEST_HOST="${DEPLOY_DEST_HOST:?DEPLOY_DEST_HOST manquant}" DEST_HOST="${DEPLOY_DEST_HOST:?DEPLOY_DEST_HOST manquant}"
SECOND_DEST_HOST="${DEPLOY_SECOND_DEST_HOST:?DEPLOY_SECOND_DEST_HOST manquant}"
DEST_DIR="/var/lib/www/richard-dern.fr/" DEST_DIR="/var/lib/www/richard-dern.fr/"
HUGO_ENV="production" HUGO_ENV="production"
TARGET_OWNER="caddy:caddy" TARGET_OWNER="caddy:caddy"
@@ -33,11 +34,56 @@ is_local_host() {
return 1 return 1
} }
LOCAL_DEPLOY=false DEST_HOSTS=("$DEST_HOST")
if is_local_host "$DEST_HOST"; then if [ "$SECOND_DEST_HOST" != "$DEST_HOST" ]; then
LOCAL_DEPLOY=true DEST_HOSTS+=("$SECOND_DEST_HOST")
fi fi
deploy_to_host() {
local host="$1"
local local_deploy=false
local cmd
if is_local_host "$host"; then
local_deploy=true
fi
if [ "$local_deploy" = true ]; then
if [ ! -d "$DEST_DIR" ]; then
echo "Dossier de destination introuvable: $DEST_DIR" >&2
exit 1
fi
echo "==> Vérification/pose des ACL sur $DEST_DIR"
sudo "$SETFACL_BIN" -R -m u:"$USER":rwx -m m:rwx "$DEST_DIR"
sudo "$SETFACL_BIN" -dR -m u:"$USER":rwx -m m:rwx "$DEST_DIR"
echo "==> Synchronisation locale du site vers $DEST_DIR"
rsync -rlvz --delete \
--exclude='data/***' \
--no-owner --no-group \
--no-perms --omit-dir-times --no-times \
--checksum \
public/ "$DEST_DIR"
find "$DEST_DIR" -type d -name data -exec rm -rf {} +
sudo "$CHOWN_BIN" -R "$TARGET_OWNER" "$DEST_DIR"
return
fi
echo "==> Synchronisation du site vers le serveur $host"
rsync -rlvz --delete \
--exclude='data/***' \
--no-owner --no-group \
--no-perms --omit-dir-times --no-times \
--checksum \
public/ "$DEST_USER@$host:$DEST_DIR"
cmd="find \"$DEST_DIR\" -type d -name data -exec rm -rf {} +"
ssh "$DEST_USER@$host" "$cmd"
ssh "$DEST_USER@$host" "$CHOWN_BIN -R $TARGET_OWNER '$DEST_DIR'"
}
echo "==> Vérification des liens externes" echo "==> Vérification des liens externes"
node "$SCRIPT_DIR/tools/check_external_links.js" node "$SCRIPT_DIR/tools/check_external_links.js"
@@ -62,43 +108,9 @@ npm run stats:generate
echo "==> Génération du site Hugo pour l'environnement $HUGO_ENV (avec nettoyage de destination)" echo "==> Génération du site Hugo pour l'environnement $HUGO_ENV (avec nettoyage de destination)"
hugo --environment "$HUGO_ENV" --cleanDestinationDir hugo --environment "$HUGO_ENV" --cleanDestinationDir
if [ "$LOCAL_DEPLOY" = true ]; then for host in "${DEST_HOSTS[@]}"; do
if [ ! -d "$DEST_DIR" ]; then deploy_to_host "$host"
echo "Dossier de destination introuvable: $DEST_DIR" >&2 done
exit 1
fi
echo "==> Vérification/pose des ACL sur $DEST_DIR"
sudo "$SETFACL_BIN" -R -m u:"$USER":rwx -m m:rwx "$DEST_DIR"
sudo "$SETFACL_BIN" -dR -m u:"$USER":rwx -m m:rwx "$DEST_DIR"
fi
if [ "$LOCAL_DEPLOY" = true ]; then
echo "==> Synchronisation locale du site vers $DEST_DIR"
rsync -rlvz --delete \
--exclude='data/***' \
--no-owner --no-group \
--no-perms --omit-dir-times --no-times \
--checksum \
public/ "$DEST_DIR"
else
echo "==> Synchronisation du site vers le serveur $DEST_HOST"
rsync -rlvz --delete \
--exclude='data/***' \
--no-owner --no-group \
--no-perms --omit-dir-times --no-times \
--checksum \
public/ "$DEST_USER@$DEST_HOST:$DEST_DIR"
fi
if [ "$LOCAL_DEPLOY" = true ]; then
find "$DEST_DIR" -type d -name data -exec rm -rf {} +
sudo "$CHOWN_BIN" -R "$TARGET_OWNER" "$DEST_DIR"
else
CMD="find \"$DEST_DIR\" -type d -name data -exec rm -rf {} +"
ssh "$DEST_USER@$DEST_HOST" "$CMD"
ssh "$DEST_USER@$DEST_HOST" "$CHOWN_BIN -R $TARGET_OWNER '$DEST_DIR'"
fi
node tools/update_lemmy_post_dates.js node tools/update_lemmy_post_dates.js