Skip to content

Commit 279a2fa

Browse files
committed
feat: update fetch-vercel-envs script to extract and replace environment variables in index.js files, enhancing configuration management
1 parent 69acd4c commit 279a2fa

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

apps/browserless/server/scripts/fetch-vercel-envs.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,47 @@ echo "{
2626
vercel env pull --environment=production --token=$VERCEL_TOKEN .env.cloud
2727
echo "Vercel environment variables fetched successfully"
2828

29+
# Update environment variables in index.js files
30+
echo "Updating environment variables in index.js files..."
31+
32+
# Extract environment variables from .env.cloud
33+
CLOUD_SUPABASE_ANON_KEY=$(grep -E "^NEXT_PUBLIC_SUPABASE_ANON_KEY=" .env.cloud | cut -d '=' -f2-)
34+
CLOUD_SUPABASE_URL=$(grep -E "^NEXT_PUBLIC_SUPABASE_URL=" .env.cloud | cut -d '=' -f2-)
35+
CLOUD_PG_CONNECTION=$(grep -E "^PG_CONNECTION=" .env.cloud | cut -d '=' -f2-)
36+
CLOUD_SUPABASE_SERVICE_ROLE_KEY=$(grep -E "^SUPABASE_SERVICE_ROLE_KEY=" .env.cloud | cut -d '=' -f2-)
37+
38+
# Extract environment variables from .env.production if it exists
39+
if [ -f ".env.production" ]; then
40+
PROD_SUPABASE_ANON_KEY=$(grep -E "^NEXT_PUBLIC_SUPABASE_ANON_KEY=" .env.production | cut -d '=' -f2-)
41+
PROD_SUPABASE_URL=$(grep -E "^NEXT_PUBLIC_SUPABASE_URL=" .env.production | cut -d '=' -f2-)
42+
PROD_PG_CONNECTION=$(grep -E "^PG_CONNECTION=" .env.production | cut -d '=' -f2-)
43+
PROD_SUPABASE_SERVICE_ROLE_KEY=$(grep -E "^SUPABASE_SERVICE_ROLE_KEY=" .env.production | cut -d '=' -f2-)
44+
fi
45+
46+
# Find all index.js files in /app/extension/scripts
47+
find /app/extension/scripts -name "index.js" | while read -r file; do
48+
echo "Processing $file..."
49+
50+
# Replace environment variables if they exist in production
51+
if [ -n "$PROD_SUPABASE_ANON_KEY" ]; then
52+
sed -i "s|$PROD_SUPABASE_ANON_KEY|$CLOUD_SUPABASE_ANON_KEY|g" "$file"
53+
fi
54+
55+
if [ -n "$PROD_SUPABASE_URL" ]; then
56+
sed -i "s|$PROD_SUPABASE_URL|$CLOUD_SUPABASE_URL|g" "$file"
57+
fi
58+
59+
if [ -n "$PROD_PG_CONNECTION" ]; then
60+
sed -i "s|$PROD_PG_CONNECTION|$CLOUD_PG_CONNECTION|g" "$file"
61+
fi
62+
63+
if [ -n "$PROD_SUPABASE_SERVICE_ROLE_KEY" ]; then
64+
sed -i "s|$PROD_SUPABASE_SERVICE_ROLE_KEY|$CLOUD_SUPABASE_SERVICE_ROLE_KEY|g" "$file"
65+
fi
66+
done
67+
68+
echo "Environment variables updated in index.js files"
69+
2970
# Check if .env.production exists and is writable
3071
if [ ! -w ".env.production" ]; then
3172
echo "Warning: .env.production is not writable, attempting to fix permissions"

0 commit comments

Comments
 (0)