Files
hydra-sql/watch-dev-optimized.sh

39 lines
1.3 KiB
Bash
Raw Normal View History

#!/usr/bin/env bash
# Nom du container en argument, valeur par défaut "hydra-sql"
CONTAINER_KEY="${1:-hydra-sql}"
# Chercher le nom exact du container correspondant
CONTAINER=$(docker ps --filter "name=${CONTAINER_KEY}" --format "{{.Names}}" | head -n1)
if [[ -n "$CONTAINER" ]]; then
echo "Container trouvé : $CONTAINER"
else
echo "Aucun container exact trouvé pour '$CONTAINER_KEY'. Liste des containers contenant ce mot-clé :"
docker ps --format "{{.Names}}" | grep "$CONTAINER_KEY" || echo "Aucun container trouvé"
exit 1
fi
WATCH_DIRS=("src" "templates" "config")
DEBOUNCE_TIME=0.5
# vérifier que inotifywait est installé
if ! command -v inotifywait &> /dev/null; then
echo "inotifywait manquant, installez via 'sudo apt install inotify-tools'"
exit 1
fi
echo "Watching directories: ${WATCH_DIRS[*]} for container: $CONTAINER"
echo "Ignoring var/cache and vendor"
while true; do
CHANGES=$(inotifywait -r -e modify,create,delete --format '%w%f' \
--exclude 'var/cache|vendor' "${WATCH_DIRS[@]}")
if [[ -n "$CHANGES" ]]; then
echo "$(date '+%H:%M:%S') - change detected, debouncing for $DEBOUNCE_TIME s..."
sleep $DEBOUNCE_TIME
echo "$(date '+%H:%M:%S') - restarting container $CONTAINER"
docker restart "$CONTAINER"
fi
done