File size: 2,033 Bytes
4e7b77b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env python3
"""

Debug script for Docker container environment

"""

import os
import sys
import sqlite3
import logging

# Set up logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)


def debug_environment():
    """Debug the container environment"""
    print("=== Container Environment Debug ===")

    # Check current directory
    print(f"Current directory: {os.getcwd()}")

    # Check if /app/data exists
    data_dir = "/app/data"
    if os.path.exists(data_dir):
        print(f"βœ… Data directory exists: {data_dir}")
        print(f"   Permissions: {oct(os.stat(data_dir).st_mode)[-3:]}")
        print(f"   Writable: {os.access(data_dir, os.W_OK)}")
    else:
        print(f"❌ Data directory does not exist: {data_dir}")

    # Check environment variables
    print(f"DATABASE_PATH: {os.getenv('DATABASE_PATH', 'Not set')}")
    print(f"TRANSFORMERS_CACHE: {os.getenv('TRANSFORMERS_CACHE', 'Not set')}")
    print(f"HF_HOME: {os.getenv('HF_HOME', 'Not set')}")

    # Try to create data directory
    try:
        os.makedirs(data_dir, mode=0o777, exist_ok=True)
        print(f"βœ… Created/verified data directory: {data_dir}")
    except Exception as e:
        print(f"❌ Failed to create data directory: {e}")

    # Try database connection
    try:
        db_path = os.getenv('DATABASE_PATH', '/app/data/legal_dashboard.db')
        print(f"Testing database connection to: {db_path}")

        # Ensure directory exists
        db_dir = os.path.dirname(db_path)
        os.makedirs(db_dir, mode=0o777, exist_ok=True)

        # Test connection
        conn = sqlite3.connect(db_path)
        cursor = conn.cursor()
        cursor.execute("SELECT 1")
        result = cursor.fetchone()
        print(f"βœ… Database connection successful: {result}")
        conn.close()

    except Exception as e:
        print(f"❌ Database connection failed: {e}")


if __name__ == "__main__":
    debug_environment()