- Fixed authentication system (removed HTTP Basic Auth popup) - Added session-based authentication with proper logout - Updated rate limiting (20 req/s for login, 5 req/m for admin) - Created production deployment scripts and configs - Updated nginx configuration for dk0.dev domain - Added comprehensive production deployment guide - Fixed logout button functionality - Optimized for production with proper resource limits
150 lines
3.7 KiB
Bash
Executable File
150 lines
3.7 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Production Deployment Script for dk0.dev
|
|
# This script sets up the production environment and deploys the application
|
|
|
|
set -e
|
|
|
|
# Colors for output
|
|
RED='\033[0;31m'
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
BLUE='\033[0;34m'
|
|
NC='\033[0m' # No Color
|
|
|
|
# Logging functions
|
|
log() {
|
|
echo -e "${BLUE}[$(date +'%Y-%m-%d %H:%M:%S')]${NC} $1"
|
|
}
|
|
|
|
error() {
|
|
echo -e "${RED}[ERROR]${NC} $1" >&2
|
|
}
|
|
|
|
success() {
|
|
echo -e "${GREEN}[SUCCESS]${NC} $1"
|
|
}
|
|
|
|
warning() {
|
|
echo -e "${YELLOW}[WARNING]${NC} $1"
|
|
}
|
|
|
|
# Check if running as root
|
|
if [[ $EUID -eq 0 ]]; then
|
|
error "This script should not be run as root"
|
|
exit 1
|
|
fi
|
|
|
|
# Check if Docker is running
|
|
if ! docker info > /dev/null 2>&1; then
|
|
error "Docker is not running. Please start Docker and try again."
|
|
exit 1
|
|
fi
|
|
|
|
log "Starting production deployment for dk0.dev..."
|
|
|
|
# Create production environment file if it doesn't exist
|
|
if [ ! -f .env ]; then
|
|
log "Creating production environment file..."
|
|
cat > .env << EOF
|
|
# Production Environment Configuration for dk0.dev
|
|
NODE_ENV=production
|
|
NEXT_PUBLIC_BASE_URL=https://dk0.dev
|
|
MY_EMAIL=contact@dk0.dev
|
|
MY_INFO_EMAIL=info@dk0.dev
|
|
MY_PASSWORD=your-email-password
|
|
MY_INFO_PASSWORD=your-info-email-password
|
|
ADMIN_BASIC_AUTH=admin:your_secure_password_here
|
|
LOG_LEVEL=info
|
|
PORT=3000
|
|
EOF
|
|
warning "Created .env file with default values. Please update with your actual credentials!"
|
|
fi
|
|
|
|
# Create proxy network if it doesn't exist
|
|
log "Creating proxy network..."
|
|
docker network create proxy 2>/dev/null || {
|
|
log "Proxy network already exists"
|
|
}
|
|
|
|
# Build the application
|
|
log "Building production image..."
|
|
docker build -t portfolio-app:latest . || {
|
|
error "Failed to build image"
|
|
exit 1
|
|
}
|
|
|
|
# Stop existing containers
|
|
log "Stopping existing containers..."
|
|
docker-compose down 2>/dev/null || {
|
|
log "No existing containers to stop"
|
|
}
|
|
|
|
# Start the application
|
|
log "Starting production containers..."
|
|
docker-compose up -d || {
|
|
error "Failed to start containers"
|
|
exit 1
|
|
}
|
|
|
|
# Wait for services to be healthy
|
|
log "Waiting for services to be healthy..."
|
|
HEALTH_CHECK_TIMEOUT=120
|
|
HEALTH_CHECK_INTERVAL=5
|
|
ELAPSED=0
|
|
|
|
while [ $ELAPSED -lt $HEALTH_CHECK_TIMEOUT ]; do
|
|
if curl -f http://localhost:3000/api/health > /dev/null 2>&1; then
|
|
success "Application is healthy!"
|
|
break
|
|
fi
|
|
|
|
sleep $HEALTH_CHECK_INTERVAL
|
|
ELAPSED=$((ELAPSED + HEALTH_CHECK_INTERVAL))
|
|
echo -n "."
|
|
done
|
|
|
|
if [ $ELAPSED -ge $HEALTH_CHECK_TIMEOUT ]; then
|
|
error "Health check timeout. Application may not be running properly."
|
|
log "Container logs:"
|
|
docker-compose logs --tail=50
|
|
exit 1
|
|
fi
|
|
|
|
# Run database migrations
|
|
log "Running database migrations..."
|
|
docker exec portfolio-app npx prisma db push || {
|
|
warning "Database migration failed, but continuing..."
|
|
}
|
|
|
|
# Verify deployment
|
|
log "Verifying deployment..."
|
|
if curl -f http://localhost:3000/api/health > /dev/null 2>&1; then
|
|
success "Production deployment successful!"
|
|
|
|
# Show container status
|
|
log "Container status:"
|
|
docker-compose ps
|
|
|
|
# Show resource usage
|
|
log "Resource usage:"
|
|
docker stats --no-stream --format "table {{.Container}}\t{{.CPUPerc}}\t{{.MemUsage}}"
|
|
|
|
else
|
|
error "Deployment verification failed!"
|
|
log "Container logs:"
|
|
docker-compose logs --tail=50
|
|
exit 1
|
|
fi
|
|
|
|
success "Production deployment completed successfully!"
|
|
log "Application is available at: http://localhost:3000/"
|
|
log "Health check endpoint: http://localhost:3000/api/health"
|
|
log "Admin panel: http://localhost:3000/manage"
|
|
log ""
|
|
log "Next steps:"
|
|
log "1. Update .env file with your actual credentials"
|
|
log "2. Set up SSL certificates for HTTPS"
|
|
log "3. Configure your reverse proxy (nginx/traefik) to point to localhost:3000"
|
|
log "4. Update DNS to point dk0.dev to your server"
|