Skip to content

Commit 6ad406d

Browse files
committed
Force IPv4 connections in deployment and database scripts to fix connectivity issues
1 parent 0d3fb45 commit 6ad406d

File tree

3 files changed

+26
-13
lines changed

3 files changed

+26
-13
lines changed

bin/deploy-with-migrations.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ REMOTE_PORT="${DEPLOY_REMOTE_PORT:-2048}"
2323
REMOTE_USER="${DEPLOY_REMOTE_USER:-ubuntu}"
2424
REMOTE_DIR="${DEPLOY_REMOTE_DIR:-www/profullstack.com/pdf}"
2525

26-
# Create SSH options
27-
SSH_OPTS="-p $REMOTE_PORT"
26+
# Create SSH options - force IPv4 to avoid IPv6 connection issues
27+
SSH_OPTS="-4 -p $REMOTE_PORT"
2828

2929
# Deploy the code first using deploy.sh
3030
echo -e "${YELLOW}Running deployment script...${NC}"

bin/deploy.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ REMOTE_DIR="${DEPLOY_REMOTE_DIR:-www/profullstack.com/pdf}"
1616
LOCAL_DIR="."
1717
INSTALL_SERVICE="${INSTALL_SERVICE:-false}"
1818

19-
# Create SSH options
20-
SSH_OPTS="-p $REMOTE_PORT"
21-
SCP_OPTS="-P $REMOTE_PORT"
22-
RSYNC_OPTS="-e \"ssh -p $REMOTE_PORT\""
19+
# Create SSH options - force IPv4 to avoid IPv6 connection issues
20+
SSH_OPTS="-4 -p $REMOTE_PORT"
21+
SCP_OPTS="-4 -P $REMOTE_PORT"
22+
RSYNC_OPTS="-e \"ssh -4 -p $REMOTE_PORT\""
2323

2424
# Set colors for output
2525
GREEN='\033[0;32m'
@@ -42,10 +42,10 @@ if ssh $SSH_OPTS $REMOTE_USER@$REMOTE_HOST "[ -d $REMOTE_DIR ]"; then
4242
# Deploy using rsync with .deployignore
4343
if [ -f .deployignore ]; then
4444
echo -e "${YELLOW}Using .deployignore file for exclusions...${NC}"
45-
rsync -avz --partial --progress -e "ssh -p $REMOTE_PORT" --exclude-from=.deployignore $LOCAL_DIR $REMOTE_USER@$REMOTE_HOST:$REMOTE_DIR
45+
rsync -avz --partial --progress -e "ssh -4 -p $REMOTE_PORT" --exclude-from=.deployignore $LOCAL_DIR $REMOTE_USER@$REMOTE_HOST:$REMOTE_DIR
4646
else
4747
echo -e "${YELLOW}No .deployignore file found. Excluding node_modules/ by default...${NC}"
48-
rsync -avz --partial --progress -e "ssh -p $REMOTE_PORT" --exclude="node_modules/" $LOCAL_DIR $REMOTE_USER@$REMOTE_HOST:$REMOTE_DIR
48+
rsync -avz --partial --progress -e "ssh -4 -p $REMOTE_PORT" --exclude="node_modules/" $LOCAL_DIR $REMOTE_USER@$REMOTE_HOST:$REMOTE_DIR
4949
fi
5050

5151
# Check if rsync was successful

bin/supabase-db.sh

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,9 @@ setup_project() {
213213
export PGPASSWORD="$SUPABASE_DB_PASSWORD"
214214

215215
# Run the link command directly - no retries to avoid confusion
216-
echo -e "${YELLOW}Running: supabase link --project-ref \"$PROJECT_REF\" --password \"$SUPABASE_DB_PASSWORD\" --debug${NC}"
217-
supabase link --project-ref "$PROJECT_REF" --password "$SUPABASE_DB_PASSWORD" --debug
216+
# Add GODEBUG=netdns=4 to force IPv4 DNS resolution
217+
echo -e "${YELLOW}Running: GODEBUG=netdns=4 supabase link --project-ref \"$PROJECT_REF\" --password \"$SUPABASE_DB_PASSWORD\" --debug${NC}"
218+
GODEBUG=netdns=4 supabase link --project-ref "$PROJECT_REF" --password "$SUPABASE_DB_PASSWORD" --debug
218219

219220
if [ $? -eq 0 ]; then
220221
echo -e "${GREEN}Link successful!${NC}"
@@ -276,7 +277,18 @@ run_migrations() {
276277
fi
277278

278279
# Set up the database URL for direct cloud connection
279-
DB_URL="postgresql://postgres:${SUPABASE_DB_PASSWORD}@db.${PROJECT_REF}.supabase.co:5432/postgres"
280+
# Force IPv4 by resolving the hostname to an IPv4 address
281+
echo -e "${YELLOW}Resolving db.${PROJECT_REF}.supabase.co to IPv4 address...${NC}"
282+
DB_HOST=$(getent ahostsv4 db.${PROJECT_REF}.supabase.co | head -n 1 | awk '{print $1}')
283+
284+
if [ -z "$DB_HOST" ]; then
285+
echo -e "${YELLOW}Failed to resolve IPv4 address, using hostname...${NC}"
286+
DB_HOST="db.${PROJECT_REF}.supabase.co"
287+
else
288+
echo -e "${YELLOW}Using IPv4 address: $DB_HOST${NC}"
289+
fi
290+
291+
DB_URL="postgresql://postgres:${SUPABASE_DB_PASSWORD}@$DB_HOST:5432/postgres"
280292
echo -e "${YELLOW}Using cloud database URL for migrations...${NC}"
281293

282294
# Run the migration command directly with the cloud database URL
@@ -286,8 +298,9 @@ run_migrations() {
286298
export PGPASSWORD="$SUPABASE_DB_PASSWORD"
287299

288300
# Run the command with the cloud database URL - no retries to avoid confusion
289-
echo -e "${YELLOW}Running: supabase db push --db-url <DB_URL> --debug${NC}"
290-
supabase db push --db-url "$DB_URL" --debug
301+
# Add GODEBUG=netdns=4 to force IPv4 DNS resolution
302+
echo -e "${YELLOW}Running: GODEBUG=netdns=4 supabase db push --db-url <DB_URL> --debug${NC}"
303+
GODEBUG=netdns=4 supabase db push --db-url "$DB_URL" --debug
291304

292305
if [ $? -eq 0 ]; then
293306
echo -e "${GREEN}Migration successful!${NC}"

0 commit comments

Comments
 (0)