Features: 1) Split docker compose build and docker compose up -d into distinct steps with updated messages; 2) Replace custom spinner in Unix script with simplified run_cmd approach;
Fixes: 1) Update final output message to align with application name (`eVibes`); Extra: 1) Remove redundant spinner implementation in Unix script for clarity and reduction of complexity; 2) General script cleanup and minor formatting tweaks.
This commit is contained in:
parent
979e7fdac1
commit
6b829331c3
2 changed files with 32 additions and 55 deletions
|
|
@ -1,60 +1,35 @@
|
|||
#!/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 cmd="$1" msg="$2" rc=0
|
||||
|
||||
printf "\e[36m%s... \e[0m" "$msg"
|
||||
|
||||
bash -c "$cmd" &> /dev/null &
|
||||
local pid=$!
|
||||
|
||||
spinner "$pid" "$msg"
|
||||
|
||||
if ! wait "$pid"; then rc=$?; fi
|
||||
|
||||
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
|
||||
run_cmd() {
|
||||
local msg=$1; shift
|
||||
printf "%s... " "$msg"
|
||||
"$@"
|
||||
printf "OK\n"
|
||||
}
|
||||
|
||||
echo
|
||||
|
||||
run_with_spinner "docker compose --ansi never down || true" \
|
||||
"Stopping services"
|
||||
run_with_spinner "docker compose --ansi never build" \
|
||||
"Rebuilding services"
|
||||
run_with_spinner "docker compose --ansi never up -d" \
|
||||
"Starting services"
|
||||
run_with_spinner "docker compose --ansi never exec app poetry run python manage.py migrate --no-input" \
|
||||
"Applying database migrations"
|
||||
run_with_spinner "docker compose --ansi never exec app poetry run python manage.py collectstatic --no-input" \
|
||||
"Collecting static files"
|
||||
run_with_spinner "docker compose --ansi never exec app poetry run python manage.py set_default_caches" \
|
||||
"Setting default caches"
|
||||
run_with_spinner "docker system prune -f" \
|
||||
"Cleaning up unused Docker data"
|
||||
run_cmd "Stopping services (down)" \
|
||||
docker compose down
|
||||
|
||||
echo -e "\n\e[1mAll done! eVibes is up and running.\e[0m"
|
||||
run_cmd "Rebuilding services" \
|
||||
docker compose build
|
||||
|
||||
run_cmd "Starting services" \
|
||||
docker compose up -d
|
||||
|
||||
run_cmd "Applying database migrations" \
|
||||
docker compose exec app poetry run python manage.py migrate --no-input
|
||||
|
||||
run_cmd "Collecting static files" \
|
||||
docker compose exec app poetry run python manage.py collectstatic --no-input
|
||||
|
||||
run_cmd "Setting default caches" \
|
||||
docker compose exec app poetry run python manage.py set_default_caches
|
||||
|
||||
run_cmd "Cleaning up unused Docker data" \
|
||||
docker system prune -f
|
||||
|
||||
echo
|
||||
echo "All done! eVibes is up and running."
|
||||
|
|
|
|||
|
|
@ -44,8 +44,10 @@ function Invoke-Spinner
|
|||
Write-Host ""
|
||||
Invoke-Spinner -Arguments "compose down" `
|
||||
-Message "Stopping services (down)"
|
||||
Invoke-Spinner -Arguments "compose up -d --build" `
|
||||
-Message "Rebuilding & starting services"
|
||||
Invoke-Spinner -Arguments "compose build" `
|
||||
-Message "Rebuilding services"
|
||||
Invoke-Spinner -Arguments "compose up -d" `
|
||||
-Message "Starting services"
|
||||
Invoke-Spinner -Arguments "compose exec app poetry run python manage.py migrate --no-input" `
|
||||
-Message "Applying database migrations"
|
||||
Invoke-Spinner -Arguments "compose exec app poetry run python manage.py collectstatic --no-input" `
|
||||
|
|
@ -55,4 +57,4 @@ Invoke-Spinner -Arguments "compose exec app poetry run python manage.py set_defa
|
|||
Invoke-Spinner -Arguments "system prune -f" `
|
||||
-Message "Cleaning up unused Docker data"
|
||||
|
||||
Write-Host "`nAll done! Your application is up and running." -ForegroundColor White
|
||||
Write-Host "`nAll done! eVibes is up and running." -ForegroundColor White
|
||||
|
|
|
|||
Loading…
Reference in a new issue