railway-deploy-hook
v1.0.2
Published
Simple Railway Function to enable Webhook Deploys
Maintainers
Readme
Railway Deploy Hook
Overview
This service provides a webhook endpoint that triggers redeployment of Railway services. It uses the Railway GraphQL API and is designed to be deployed as a Railway Function.
Setup & Deployment
1. Create Railway Function
- Go to Railway and log in
- Create a new project or select an existing one
- Click "New" → "Function"
2. Add Code
Copy the entire contents of the index.js file from this repository and paste it into your Railway Function:
3. Configure Environment Variable
- Go to the "Variables" tab in your Railway Function
- Add a new variable:
- Name:
RAILWAY_API_TOKEN - Value: Your Railway API Token
- Name:
Creating a Railway API Token
- Go to Railway Dashboard
- Click on your profile (top right) → "Account Settings"
- Navigate to "Tokens" in the sidebar
- Click "Create New Token"
- Give the token a name (e.g., "Deploy Hook")
- Copy the generated token and add it as the
RAILWAY_API_TOKENvariable
4. Deploy Function
- Click "Deploy" in your Railway Function
- Wait for the deployment to complete
- Copy the URL of your deployed Function
Usage
Calling the Webhook
Send a POST request to your webhook endpoint with the required query parameters:
POST https://your-function-subdomain.railway.app/webhook?environmentId=ENVIRONMENT_ID&serviceId=SERVICE_IDParameters
environmentId: The ID of the Railway environment where the service is locatedserviceId: The ID of the Railway service to redeploy
Example Request
curl -X POST "https://your-function-url.railway.app/webhook?environmentId=c3b077f3-feb0-448f-80b4-ccdae37a6fb5&serviceId=952f84ee-e0e7-4c76-92df-88e3cfe52e0d"Finding Service and Environment IDs
- Go to your Railway project
- Select the desired environment
- Click on the service you want to deploy
- Go to "Settings" → "General"
- You'll find the IDs under "Service ID" and "Environment ID"
Health Check
Check if your service is running:
curl https://your-function-url.railway.app/healthExpected response:
{
"status": "ok"
}API Responses
Successful Request
{
"success": true,
"message": "Service 952f84ee-e0e7-4c76-92df-88e3cfe52e0d redeployed in environment c3b077f3-feb0-448f-80b4-ccdae37a6fb5"
}Bad Request
{
"error": "Missing required query parameters: environmentId, serviceId"
}Server Error
{
"error": "Error message",
"details": "Detailed error information"
}Automation
You can integrate this webhook into various CI/CD pipelines or automation tools:
- GitHub Actions: Call the webhook after successful tests
- Zapier/Make: Connect with other services
- Cron Jobs: Schedule regular deployments
- Monitoring Tools: Trigger deployments based on metrics
Troubleshooting
Common Issues
- 401 Unauthorized: Check your
RAILWAY_API_TOKEN - 400 Bad Request: Make sure both query parameters (
environmentIdandserviceId) are present - 500 Internal Server Error: Check the logs in your Railway Function
Viewing Logs
- Go to your Railway Function
- Click on the "Deployments" tab
- Click on the current deployment
- Scroll to the "Logs" to diagnose errors
Security
- ⚠️ Keep your
RAILWAY_API_TOKENsecret - 🔒 The token has access to your entire Railway account
- 🛡️ Consider implementing authentication for the webhook endpoint in production environments
Support
For issues or questions:
- Check the Railway Function logs
- Make sure all environment variables are set correctly
- Verify that the service and environment IDs are correct
Note: This service uses the Railway GraphQL API v2. Make sure your API token has the necessary permissions for service deployments.
