Fixes: 1) Fixed irregular Bash array formatting within SPINNER; 2) Resolved typo in COLOR array definition. Extra: Simplified docker commands by removing redundant `docker compose` prefix and replaced with shorter aliases; enhanced code readability and formatting.
52 lines
1.6 KiB
Bash
Executable file
52 lines
1.6 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
SPINNER=('|' '/' '-' '\')
|
|
COLORS=(97 37)
|
|
DELAY=0.1
|
|
|
|
hide_cursor() { tput civis 2>/dev/null || true; }
|
|
show_cursor() { tput cnorm 2>/dev/null || true; }
|
|
|
|
spinner() {
|
|
local pid=$1 msg=$2 i=0 frame color
|
|
hide_cursor
|
|
while kill -0 "$pid" 2>/dev/null; do
|
|
frame="${SPINNER[i % ${#SPINNER[@]}]}"
|
|
color="${COLORS[i % ${#COLORS[@]}]}"
|
|
printf "\r\e[36m%s... \e[0m\e[%sm%s\e[0m" "$msg" "$color" "$frame"
|
|
((i++))
|
|
sleep "$DELAY"
|
|
done
|
|
show_cursor
|
|
}
|
|
|
|
run_with_spinner() {
|
|
local args="$1" msg="$2" rc
|
|
printf "\e[36m%s... \e[0m" "$msg"
|
|
|
|
bash -c "docker --ansi never $args" &> /dev/null &
|
|
local pid=$!
|
|
|
|
spinner "$pid" "$msg"
|
|
|
|
wait "$pid" || rc=$?
|
|
rc=${rc:-0}
|
|
|
|
if [[ $rc -eq 0 ]]; then
|
|
printf "\r\e[32m✔\e[0m %s\n" "$msg"
|
|
else
|
|
printf "\r\e[33m✖ (exit %d)\e[0m %s\n" "$rc" "$msg"
|
|
fi
|
|
}
|
|
|
|
echo
|
|
|
|
run_with_spinner "compose down" "Stopping services (down)"
|
|
run_with_spinner "compose up -d --build" "Rebuilding & starting services"
|
|
run_with_spinner "compose exec app poetry run python manage.py migrate --no-input" "Applying database migrations"
|
|
run_with_spinner "compose exec app poetry run python manage.py collectstatic --no-input" "Collecting static files"
|
|
run_with_spinner "compose exec app poetry run python manage.py set_default_caches" "Setting default caches"
|
|
run_with_spinner "system prune -f" "Cleaning up unused Docker data"
|
|
|
|
echo -e "\n\e[1mAll done! Your application is up and running.\e[0m"
|