#!/bin/bash # Quick fix script for production issues # Ensures proxy network exists and container is properly connected set -e echo "๐Ÿ”ง Production Fix Script" echo "=======================" echo "" # Colors RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' NC='\033[0m' # No Color COMPOSE_FILE="docker-compose.production.yml" # Check if proxy network exists echo "๐ŸŒ Checking proxy network..." if docker network ls | grep -q "proxy"; then echo -e "${GREEN}โœ… 'proxy' network exists${NC}" else echo -e "${YELLOW}โš ๏ธ 'proxy' network does not exist. Creating...${NC}" docker network create proxy || { echo -e "${RED}โŒ Failed to create proxy network${NC}" echo "This might be because Nginx Proxy Manager hasn't created it yet." echo "Please ensure Nginx Proxy Manager is running and has created the 'proxy' network." exit 1 } echo -e "${GREEN}โœ… 'proxy' network created${NC}" fi echo "" # Check if container is running echo "๐Ÿ“ฆ Checking container status..." CONTAINER_ID=$(docker ps -q -f "name=portfolio-app") if [ -z "$CONTAINER_ID" ]; then echo -e "${RED}โŒ Container is not running${NC}" echo "Starting container..." docker compose -f $COMPOSE_FILE up -d echo "Waiting for container to start..." sleep 10 else echo -e "${GREEN}โœ… Container is running${NC}" fi echo "" # Check if container is connected to proxy network echo "๐Ÿ”— Checking network connectivity..." if docker inspect portfolio-app --format='{{range $net, $conf := .NetworkSettings.Networks}}{{$net}} {{end}}' | grep -q "proxy"; then echo -e "${GREEN}โœ… Container is connected to 'proxy' network${NC}" else echo -e "${YELLOW}โš ๏ธ Container is NOT connected to 'proxy' network${NC}" echo "Connecting container to proxy network..." # Stop container docker compose -f $COMPOSE_FILE stop portfolio # Connect to proxy network docker network connect proxy portfolio-app || { echo -e "${RED}โŒ Failed to connect container to proxy network${NC}" echo "Trying to recreate container..." docker compose -f $COMPOSE_FILE up -d --force-recreate } # Start container docker compose -f $COMPOSE_FILE start portfolio echo -e "${GREEN}โœ… Container recreated and connected to proxy network${NC}" fi echo "" # Wait for health check echo "โณ Waiting for container to be healthy..." for i in {1..30}; do HEALTH=$(docker inspect portfolio-app --format='{{.State.Health.Status}}' 2>/dev/null || echo "starting") if [ "$HEALTH" == "healthy" ]; then echo -e "${GREEN}โœ… Container is healthy${NC}" break fi if [ $i -eq 30 ]; then echo -e "${YELLOW}โš ๏ธ Container health check timeout${NC}" echo "Container logs:" docker logs portfolio-app --tail=30 else echo "Waiting... ($i/30)" sleep 2 fi done echo "" # Test API endpoints echo "๐Ÿงช Testing API endpoints..." if docker exec portfolio-app curl -f -s --max-time 5 http://localhost:3000/api/health > /dev/null 2>&1; then echo -e "${GREEN}โœ… Health endpoint is working${NC}" else echo -e "${RED}โŒ Health endpoint is not working${NC}" echo "Container logs:" docker logs portfolio-app --tail=50 exit 1 fi echo "" # Summary echo "๐Ÿ“Š Summary:" echo "---------" echo -e "${GREEN}โœ… Production fix completed${NC}" echo "" echo "Next steps:" echo "1. Verify Nginx Proxy Manager configuration:" echo " - Forward Hostname/IP: portfolio-app" echo " - Forward Port: 3000" echo " - Ensure 'proxy' network is selected" echo "" echo "2. Test the website: https://dk0.dev" echo "" echo "3. If still having issues, run: ./scripts/diagnose-production.sh"