Railway Deployment Guide for Medusa
This guide helps you set up automated deployments for your Medusa application to Railway using GitHub Actions.
Deployment Configuration
This repository includes:
medusa-config.prod.ts- Production-ready configuration for Railwaydeploy-railway.js- Script to prepare your application for deployment.github/workflows/deploy-to-railway.yml- GitHub Actions workflow for automated deployment
One-Time Setup
1. Set up Railway Project
- Create a Railway account at railway.app
- Create a new project
- Add a PostgreSQL database service
- Add a Redis service
- Create two empty services for your Medusa application:
medusa-server- For the server modemedusa-worker- For the worker mode
2. Set up GitHub Secrets
You need to add one secret to your GitHub repository:
RAILWAY_TOKEN - Your Railway Project Token
To generate a Project Token:
- Go to your Railway project
- Navigate to Settings > Tokens
- Click "+ New Token"
- Name your token (e.g., "GitHub Actions")
- Copy the generated token
To add this secret to your GitHub repository:
- Go to your repository settings
- Navigate to Secrets and variables > Actions
- Click "New repository secret"
- Name it
RAILWAY_TOKENand paste the value - Click "Add secret"
How It Works
When you push to your main branch, the GitHub Actions workflow:
-
Runs in Railway's official CLI container, providing direct access to Railway commands
-
First replaces medusa-config.ts with the production version
-
Then uses the deploy-railway.js script to:
- Generate environment variable templates
- Create Railway configuration files
-
Deploys the server to Railway using
railway up --service=medusa-server --detach -
After server deployment completes, prepares and deploys the worker application
This approach uses Railway's recommended container-based deployment method for the most reliable integration.
Manual Deployment
If you want to deploy manually:
# Copy production config to medusa-config.ts first
cp medusa-config.prod.ts medusa-config.ts
# For server mode
node deploy-railway.js --mode=server --ci
# For worker mode
node deploy-railway.js --mode=worker --ci
Then use the Railway CLI to deploy:
# Install Railway CLI if you haven't already
npm install -g @railway/cli
# Login to Railway
railway login
# Generate a project token from Railway dashboard
# Settings > Tokens > New Token
# Use your project token
export RAILWAY_TOKEN=your-project-token
# Deploy server mode
railway up --service medusa-server --detach
# Deploy worker mode
railway up --service medusa-worker --detach
Environment Variables
The deployment script creates template environment variable files:
.env.railway.server- For server mode.env.railway.worker- For worker mode
Important: Before your first deployment, you must:
- Copy the environment variables from these files
- Go to your services on Railway
- Add them in the "Variables" tab using the Raw Editor
Creating Admin User
To create an admin user after deployment:
railway run -s medusa-server "npx medusa user -e [email protected] -p your-password"
Replace [email protected] and your-password with your desired credentials.
Troubleshooting
If you encounter issues:
- Check the GitHub Actions logs
- Check Railway logs for both services
- Ensure your environment variables are set correctly
- Verify your database connections
For more details, refer to the Medusa Railway deployment documentation.