Files
StageAI/deploy.sh

75 lines
1.8 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
# StageAI Deployment Script
# Pulls latest code from Gitea and redeploys via Docker Compose
#
# Usage (on VPS):
# ./deploy.sh # Pull & redeploy
# ./deploy.sh --build-only # Pull & rebuild without restarting
APP_DIR="/home/remmer/StageAI"
PROJECT_NAME="stageai"
REPO_URL="https://mgit.msbls.de/Remmer/StageAI.git"
BRANCH="master"
BUILD_ONLY=false
if [[ "${1:-}" == "--build-only" ]]; then
BUILD_ONLY=true
fi
echo "=== StageAI Deployment ==="
echo "Directory: $APP_DIR"
echo "Branch: $BRANCH"
echo ""
# Navigate to app directory
if [[ ! -d "$APP_DIR" ]]; then
echo "App directory not found. Cloning repo..."
git clone "$REPO_URL" "$APP_DIR"
fi
cd "$APP_DIR"
# Pull latest changes
echo "Pulling latest changes..."
git fetch origin "$BRANCH"
git reset --hard "origin/$BRANCH"
echo "Updated to: $(git log --oneline -1)"
# Rebuild containers
echo ""
echo "Rebuilding containers..."
docker compose -p "$PROJECT_NAME" build --no-cache app
if [[ "$BUILD_ONLY" == true ]]; then
echo ""
echo "Build complete (--build-only mode, skipping restart)."
exit 0
fi
# Restart app container (keep postgres and meilisearch running)
echo ""
echo "Restarting app container..."
docker compose -p "$PROJECT_NAME" up -d app
echo ""
echo "Waiting for app to start..."
sleep 5
# Health check
if curl -sf http://localhost:3002 > /dev/null 2>&1; then
echo "App is running at http://localhost:3002"
else
echo "Warning: App may not be ready yet. Check logs with:"
echo " docker compose -p $PROJECT_NAME logs -f app"
fi
echo ""
echo "=== Deployment complete ==="
echo ""
echo "Useful commands:"
echo " docker compose -p $PROJECT_NAME logs -f app # View app logs"
echo " docker compose -p $PROJECT_NAME ps # Container status"
echo " docker compose -p $PROJECT_NAME restart app # Restart app only"