#!/bin/bash

# Fast Docker build script optimized for i7-4790K (4 cores/8 threads)
# This script maximizes CPU utilization during Docker builds

echo "🚀 Starting optimized Docker build for i7-4790K"
echo "💻 CPU cores available: $(nproc)"

# Stop existing containers
echo "🛑 Stopping existing containers..."
docker compose down

# Clean up old images to free space (optional)
echo "🧹 Cleaning up old images..."
docker image prune -f

# Set optimal build arguments for your CPU
export DOCKER_BUILDKIT=1
export BUILDKIT_PROGRESS=plain

# Build with maximum parallelism
echo "⚡ Building with maximum CPU utilization..."
docker compose build \
  --parallel \
  --build-arg JOBS=$(nproc) \
  --build-arg NODE_OPTIONS="--max-old-space-size=4096" \
  --no-cache

# Start the optimized container
echo "🔄 Starting optimized container..."
docker compose up -d

# Show build results
echo "✅ Build completed!"
echo "📊 Container status:"
docker compose ps

echo "🎯 Build optimization complete! Your i7-4790K should now be fully utilized."
