Skip to content

Commit b0888f2

Browse files
author
Neil Munoz
committed
fix: railway deployment pipeline - improved CLI installation and error handling
- Fixed Railway CLI installation with multiple fallback methods - Added robust error handling and file validation - Created standalone installation script for debugging - Improved authentication and deployment process - Added comprehensive logging for troubleshooting
1 parent edac625 commit b0888f2

File tree

4 files changed

+579
-41
lines changed

4 files changed

+579
-41
lines changed

.github/workflows/production-pipeline.yml

Lines changed: 84 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -321,67 +321,110 @@ jobs:
321321
environment:
322322
name: production
323323
url: ${{ steps.deploy.outputs.url }}
324-
324+
325325
steps:
326326
- name: 📥 Checkout Repository
327327
uses: actions/checkout@v4
328328

329+
- name: 🐍 Setup Node.js for Railway CLI
330+
uses: actions/setup-node@v4
331+
with:
332+
node-version: ${{ env.NODE_VERSION }}
333+
329334
- name: 🚂 Deploy to Railway
330335
id: deploy
331336
env:
332337
RAILWAY_TOKEN: ${{ secrets.RAILWAY_TOKEN }}
333338
run: |
334-
echo "Installing Railway CLI..."
335-
# Use specific version that is known to work
336-
RAILWAY_VERSION="v3.17.1"
337-
curl -L -o railway "https://github.com/railwayapp/cli/releases/download/${RAILWAY_VERSION}/railway-linux-amd64" || {
338-
echo "Failed to download specific version, trying alternative..."
339-
# Alternative: Use npm installation
340-
npm install -g @railway/cli
341-
ln -sf $(npm root -g)/@railway/cli/bin/railway /usr/local/bin/railway
342-
}
343-
344-
# Make executable if downloaded directly
345-
if [ -f "railway" ]; then
339+
echo "🚀 Starting Railway deployment process..."
340+
341+
# Method 1: Try npm installation first (most reliable)
342+
echo "📦 Installing Railway CLI via npm..."
343+
npm install -g @railway/cli || {
344+
echo "❌ npm installation failed, trying alternative method..."
345+
346+
# Method 2: Download from GitHub releases with better error handling
347+
echo "⬇️ Downloading Railway CLI from GitHub releases..."
348+
RAILWAY_VERSION="v3.17.1"
349+
350+
# Try multiple download URLs
351+
if curl -L -o railway "https://github.com/railwayapp/cli/releases/download/${RAILWAY_VERSION}/railway-linux-amd64"; then
352+
echo "✅ Download successful"
353+
elif curl -L -o railway "https://github.com/railwayapp/cli/releases/download/${RAILWAY_VERSION}/railway_linux_amd64"; then
354+
echo "✅ Download successful (alternative URL)"
355+
else
356+
echo "❌ All download methods failed"
357+
exit 1
358+
fi
359+
360+
# Verify the downloaded file
361+
if [ ! -f "railway" ]; then
362+
echo "❌ Downloaded file not found"
363+
exit 1
364+
fi
365+
366+
# Check if file is a valid binary (not HTML error page)
367+
if head -n 1 railway | grep -q "Not Found\|404\|HTML"; then
368+
echo "❌ Downloaded file appears to be an error page, not a binary"
369+
cat railway
370+
exit 1
371+
fi
372+
373+
# Make executable and move to PATH
346374
chmod +x railway
347375
sudo mv railway /usr/local/bin/railway
376+
}
377+
378+
# Verify installation
379+
echo "🔍 Verifying Railway CLI installation..."
380+
if ! command -v railway &> /dev/null; then
381+
echo "❌ Railway CLI not found in PATH"
382+
which railway || echo "railway command not found"
383+
exit 1
348384
fi
349-
350-
echo "Verifying Railway CLI installation..."
351-
which railway
385+
386+
echo "✅ Railway CLI installed successfully"
352387
railway --version || railway version
353-
354-
echo "Checking Railway authentication..."
388+
389+
# Authenticate with Railway
390+
echo "🔐 Authenticating with Railway..."
355391
if [ -z "$RAILWAY_TOKEN" ]; then
356-
echo "❌ RAILWAY_TOKEN is not set"
392+
echo "❌ RAILWAY_TOKEN environment variable is not set"
357393
exit 1
358394
fi
359-
echo "✅ RAILWAY_TOKEN is configured"
360-
361-
echo "Deploying to Railway..."
362-
# Use railway up without specific service first
363-
railway up --detach || {
364-
echo "❌ Basic deployment failed, trying with project linking..."
365-
# Try to link to existing project if needed
366-
railway login --token "$RAILWAY_TOKEN" 2>/dev/null || true
367-
railway up --detach
368-
}
369-
370-
echo "✅ Deployment initiated successfully!"
395+
396+
# Login with token
397+
if ! railway login --token "$RAILWAY_TOKEN"; then
398+
echo "❌ Railway authentication failed"
399+
exit 1
400+
fi
401+
402+
echo "✅ Successfully authenticated with Railway"
403+
404+
# Deploy to Railway
405+
echo "🚀 Deploying application to Railway..."
406+
if ! railway up --detach; then
407+
echo "❌ Railway deployment failed"
408+
railway status || echo "Could not get deployment status"
409+
exit 1
410+
fi
411+
412+
echo "✅ Railway deployment initiated successfully!"
413+
414+
# Get deployment URL
415+
echo "🔗 Getting deployment URL..."
416+
sleep 10
417+
railway status || echo "Could not get deployment status"
371418
372419
- name: 🏥 Post-Deployment Health Check
373420
run: |
374-
echo "Waiting for deployment to stabilize..."
421+
echo "Waiting for deployment to stabilize..."
375422
sleep 60
376-
377-
echo "Checking Railway deployment status..."
378-
railway status --service neurobank-fastapi || echo "Status check completed"
379-
380-
echo "✅ Railway deployment initiated successfully!"
381-
echo "🏥 Application will be available shortly at your Railway domain"
382-
echo "📋 Check Railway dashboard for deployment progress and URL"
383-
env:
384-
RAILWAY_TOKEN: ${{ secrets.RAILWAY_TOKEN }}
423+
424+
echo "🔍 Checking Railway deployment status..."
425+
railway status || echo "⚠️ Could not retrieve deployment status"
426+
427+
echo "✅ Railway deployment process completed!"
385428
386429
- name: 📢 Deployment Notification
387430
if: always()

0 commit comments

Comments
 (0)