main #11

Merged
mstoeck3 merged 66 commits from main into forensic-ai 2025-08-11 12:02:56 +00:00
Showing only changes of commit 95ce48192b - Show all commits

105
deploy.sh
View File

@ -34,27 +34,84 @@ if [ ! -f "package.json" ] || [ ! -f "astro.config.mjs" ]; then
exit 1
fi
# Build application
echo "📦 Building application..."
if [ ! -d "node_modules" ]; then
echo "📦 Installing dependencies..."
sudo -u "$ORIGINAL_USER" npm install
# Function to find and use npm
find_and_use_npm() {
echo "🔍 Searching for npm installation..."
# Try system npm first
if command -v npm &> /dev/null; then
echo "✅ Found system npm: $(which npm)"
echo "📦 Installing dependencies..."
sudo -u "$ORIGINAL_USER" npm install
echo "📦 Building application..."
sudo -u "$ORIGINAL_USER" npm run build
return 0
fi
# Try nvm-installed npm
echo "🔍 Checking for nvm installation..."
if sudo -u "$ORIGINAL_USER" bash -c "
export NVM_DIR='$ORIGINAL_HOME/.nvm'
[ -s '\$NVM_DIR/nvm.sh' ] && source '\$NVM_DIR/nvm.sh'
[ -s '$ORIGINAL_HOME/.bashrc' ] && source '$ORIGINAL_HOME/.bashrc'
command -v npm &> /dev/null
"; then
echo "✅ Found nvm-managed npm"
echo "📦 Installing dependencies with nvm..."
sudo -u "$ORIGINAL_USER" bash -c "
export NVM_DIR='$ORIGINAL_HOME/.nvm'
[ -s '\$NVM_DIR/nvm.sh' ] && source '\$NVM_DIR/nvm.sh'
[ -s '$ORIGINAL_HOME/.bashrc' ] && source '$ORIGINAL_HOME/.bashrc'
npm install
"
echo "📦 Building application with nvm..."
sudo -u "$ORIGINAL_USER" bash -c "
export NVM_DIR='$ORIGINAL_HOME/.nvm'
[ -s '\$NVM_DIR/nvm.sh' ] && source '\$NVM_DIR/nvm.sh'
[ -s '$ORIGINAL_HOME/.bashrc' ] && source '$ORIGINAL_HOME/.bashrc'
npm run build
"
return 0
fi
echo "❌ npm not found in system or user environment"
echo ""
echo "💡 Please install Node.js and npm first:"
echo " # Option 1: System package manager"
echo " sudo apt update && sudo apt install nodejs npm"
echo ""
echo " # Option 2: NodeSource repository (recommended)"
echo " curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -"
echo " sudo apt-get install -y nodejs"
echo ""
echo " # Option 3: nvm (as user $ORIGINAL_USER)"
echo " curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash"
echo " source ~/.bashrc"
echo " nvm install 20"
echo ""
return 1
}
# Check for existing build or build if needed
if [ ! -d "dist" ] || [ ! "$(ls -A dist 2>/dev/null)" ]; then
echo "📦 No dist/ directory found, building..."
if ! find_and_use_npm; then
exit 1
fi
else
echo "📦 Found existing dist/ directory"
read -p "🤔 Rebuild application? (y/N): " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
if ! find_and_use_npm; then
echo ""
echo "💡 Using existing dist/ due to build failure"
fi
else
echo "📦 Using existing build"
fi
fi
# Build with proper user context
sudo -u "$ORIGINAL_USER" bash -c "
# Load user environment
[ -s '$ORIGINAL_HOME/.bashrc' ] && source '$ORIGINAL_HOME/.bashrc'
[ -s '$ORIGINAL_HOME/.profile' ] && source '$ORIGINAL_HOME/.profile'
# Load nvm if available
export NVM_DIR='$ORIGINAL_HOME/.nvm'
[ -s '\$NVM_DIR/nvm.sh' ] && source '\$NVM_DIR/nvm.sh'
# Build
npm run build
"
# Verify build succeeded
if [ ! -d "dist" ] || [ ! "$(ls -A dist 2>/dev/null)" ]; then
echo "❌ Error: Build failed or dist/ is empty"
@ -98,13 +155,9 @@ fi
# Setup environment configuration
echo "🔧 Setting up environment configuration..."
if [ -f "$WEBROOT/.env" ]; then
echo "📝 Existing .env found, keeping current configuration"
else
echo "📝 Creating new .env from template..."
cp .env.example "$WEBROOT/.env"
echo "⚠️ IMPORTANT: Edit $WEBROOT/.env with your configuration"
fi
cp .env.example "$WEBROOT/.env"
echo "✅ Created .env from .env.example template"
echo "⚠️ IMPORTANT: Edit $WEBROOT/.env with your configuration"
# Create log files
echo "📝 Creating log files..."