-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidate-env.sh
More file actions
executable file
·104 lines (89 loc) · 2.94 KB
/
Copy pathvalidate-env.sh
File metadata and controls
executable file
·104 lines (89 loc) · 2.94 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/bin/bash
# Environment Validation Script
# This script validates all environment variables and configuration
set -e
echo "🔍 Environment Validation Script"
echo "================================"
# Check if .env.local exists
if [ ! -f ".env.local" ]; then
echo "❌ .env.local not found!"
echo " Please create .env.local with the required environment variables."
echo " See .env.example for reference."
exit 1
fi
echo "✅ .env.local found"
# Load environment variables
set -a
source .env.local
set +a
# Required environment variables
declare -A required_vars=(
["DATABASE_URL"]="Database connection string"
["NEXTAUTH_SECRET"]="NextAuth secret for session encryption"
["GOOGLE_CLIENT_ID"]="Google OAuth client ID"
["GOOGLE_CLIENT_SECRET"]="Google OAuth client secret"
["NEXT_PUBLIC_API_URL"]="Public API URL for frontend"
["NEXTAUTH_URL"]="NextAuth URL (optional for local development)"
)
# Check each required variable
missing_vars=()
for var in "${!required_vars[@]}"; do
if [ -z "${!var}" ]; then
echo "❌ $var is missing: ${required_vars[$var]}"
missing_vars+=("$var")
else
echo "✅ $var is set"
fi
done
if [ ${#missing_vars[@]} -gt 0 ]; then
echo ""
echo "❌ Missing required environment variables:"
printf '%s\n' "${missing_vars[@]}"
exit 1
fi
# Validate DATABASE_URL format
if [[ "$DATABASE_URL" =~ ^postgresql:// ]]; then
echo "✅ DATABASE_URL has correct PostgreSQL format"
else
echo "⚠️ DATABASE_URL doesn't match expected PostgreSQL format"
fi
# Validate NEXTAUTH_SECRET length
if [ ${#NEXTAUTH_SECRET} -ge 32 ]; then
echo "✅ NEXTAUTH_SECRET has sufficient length"
else
echo "⚠️ NEXTAUTH_SECRET should be at least 32 characters long"
fi
# Validate API URL format
if [[ "$NEXT_PUBLIC_API_URL" =~ ^https?:// ]]; then
echo "✅ NEXT_PUBLIC_API_URL has correct URL format"
else
echo "⚠️ NEXT_PUBLIC_API_URL doesn't match expected URL format"
fi
# Test database connection (if possible)
echo ""
echo "🗄️ Testing database connection..."
if command -v psql &> /dev/null; then
if timeout 5 psql "$DATABASE_URL" -c "SELECT 1;" &> /dev/null; then
echo "✅ Database connection successful"
else
echo "⚠️ Could not connect to database. Make sure it's running and accessible."
fi
else
echo "⚠️ psql not found. Cannot test database connection."
fi
# Test API endpoint (if possible)
echo ""
echo "🌐 Testing API endpoint..."
if command -v curl &> /dev/null; then
if timeout 5 curl -f "$NEXT_PUBLIC_API_URL/api/health" &> /dev/null; then
echo "✅ API endpoint is accessible"
else
echo "⚠️ Could not reach API endpoint. Make sure the backend is running."
fi
else
echo "⚠️ curl not found. Cannot test API endpoint."
fi
echo ""
echo "🎉 Environment validation completed!"
echo ""
echo "If you see any warnings, please address them before running the application."