legal-ai-assistant/scripts/appctl.sh
2026-05-29 14:04:54 +02:00

76 lines
2.1 KiB
Bash

#!/bin/bash
#########################################################
# ------------------- APPLICATION ------------------
# Starting, stopping, compiling a web application.
#
#########################################################
set -e
cd "$(dirname "$0")/.."
MODE=${1:-"*"}
case $MODE in
# Start the app in background and show status
start)
echo ""
echo "Starting app..."
docker compose up -d --remove-orphans
docker compose ps --format "table {{.Service}}\t{{.State}}\t{{.Ports}}"
echo "The app is available at http://localhost:8000"
echo ""
;;
# Stop all running containers
stop)
echo ""
echo "Stoping app..."
docker compose down
echo ""
;;
# Build images and start the app
build)
echo ""
echo "Building and starting app..."
docker compose up -d --build --remove-orphans
docker compose ps --format "table {{.Service}}\t{{.State}}\t{{.Ports}}"
echo ""
;;
# Stream live logs from all containers
logs)
echo ""
echo "Logs of app (Ctrl+C to exit):"
docker compose logs -f --tail=50
echo ""
;;
# Remove all Docker cache and compose volumes of this project
clean)
echo ""
echo "Cleaning this project's Docker resources..."
docker compose down --volumes --rmi local
echo -e "Project cleaned!"
echo ""
;;
# Show available flags
help)
echo ""
echo "Usage: ./appctl.sh [FLAGS]"
echo ""
echo "Flags:"
echo " --start Start app"
echo " --stop Stop app"
echo " --build Build and start app"
echo " --logs Show live logs"
echo " --clean Clean Docker cache"
echo " --help Show this help"
echo ""
exit 1
;;
# Unknown flag — show hint
*)
echo ""
echo "Error: Unknown flag '$MODE'."
echo "Run ./appctl.sh --help for usage."
echp ""
exit 1
;;
esac