smartcrop26/deploy.sh
Vadym Samoilenko f145712998 Add Azure AD SSO authentication and deployment script
- Integrate MSAL (Azure AD) login gating the entire app
- Add deploy.sh for building and serving via Apache on Ubuntu
- Set Vite base path to /smartcrop26/ for subpath deployment
- Add .env.example with required environment variables

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 18:53:48 +00:00

56 lines
1.4 KiB
Bash
Executable file

#!/usr/bin/env bash
# =============================================================================
# SmartCrop26 Deploy Script
# Builds and deploys the SPA to Apache on Ubuntu
# =============================================================================
#
# Apache config for /var/www/html/smartcrop26:
#
# <Directory /var/www/html/smartcrop26>
# Options -Indexes +FollowSymLinks
# AllowOverride None
# FallbackResource /smartcrop26/index.html
# </Directory>
#
# Or create /var/www/html/smartcrop26/.htaccess:
# RewriteEngine On
# RewriteBase /smartcrop26/
# RewriteCond %{REQUEST_FILENAME} !-f
# RewriteCond %{REQUEST_FILENAME} !-d
# RewriteRule . /smartcrop26/index.html [L]
#
# =============================================================================
set -euo pipefail
REPO_DIR=/opt/smartcrop26
WEB_DIR=/var/www/html/smartcrop26
ENV_FILE="$REPO_DIR/.env"
if [ ! -f "$ENV_FILE" ]; then
echo "ERROR: $ENV_FILE not found. Create it with required VITE_ variables."
exit 1
fi
echo "==> Pulling latest code..."
cd "$REPO_DIR"
git pull
echo "==> Copying .env for build..."
cp "$ENV_FILE" "$REPO_DIR/.env"
echo "==> Installing dependencies..."
npm ci
echo "==> Building production bundle..."
npm run build
echo "==> Deploying to $WEB_DIR..."
mkdir -p "$WEB_DIR"
rm -rf "${WEB_DIR:?}"/*
cp -r dist/* "$WEB_DIR/"
echo "==> Setting permissions..."
chown -R www-data:www-data "$WEB_DIR"
echo "==> Deploy complete at $(date '+%Y-%m-%d %H:%M:%S')"