3 months ago
Hi Railway Support Team,
I'm using GitHub Actions to build Docker images and push them to GitHub Container Registry (GHCR), then deploying those pre-built images to Railway in the same workflow.
Current Setup:
I build and push images to GHCR in one job
I deploy using railway redeploy in a subsequent job
My Railway service is configured to pull from GHCR
The Problem:
Both railway up and railway redeploy have limitations for this workflow:
railway upwould rebuild the image on Railway's infrastructure, which I want to avoid since I'm already building it in GitHub Actions
railway redeployworks for deploying the pre-built image, but it has two issues:It doesn't wait for the deployment to complete—it just triggers the deployment and exits immediately
It requires the first build to be manually click-deployed in Railway's dashboard, which isn't ideal for a fully automated CI/CD pipeline
This means my GitHub Actions workflow continues (and potentially succeeds) even if the Railway deployment fails, which breaks my CI/CD pipeline's failure detection. Additionally, the manual first-deployment requirement prevents true automation.
What I am looking for:
Deploy a pre-built image from GHCR (not rebuild on Railway)
Wait for the deployment to complete
Have the workflow fail if the Railway deployment fails
Work from the first deployment without manual intervention
Questions:
Is there a way to use the Railway CLI to deploy a specific pre-built image and wait for the deployment status?
Is there an avenue to ensure the workflow waits for deployment completion and returns a non-zero exit code on failure?
I have looked into polling from Railways public API. If this is the only option I will dig further here.
Is there a way to trigger the initial deployment programmatically without manual dashboard interaction?
Any guidance on the recommended approach for this use case would be appreciated.
Thank you!
3 Replies
3 months ago
Hey there! We've found the following might help you get unblocked faster:
If you find the answer from one of these, please let us know by solving the thread!
Railway
Hey there! We've found the following might help you get unblocked faster: - [🧵 Wait for CI skips deployments despite successful GitHub Actions completion](https://station.railway.com/questions/wait-for-ci-skips-deployments-despite-su-3829796b) - [📚 Controlling GitHub Autodeploys](https://docs.railway.com/guides/github-autodeploys) - [📚 Deployments](https://docs.railway.com/reference/deployments) If you find the answer from one of these, please let us know by solving the thread!
3 months ago
The above links do not provide answers/solutions to the original post
3 months ago
It might not be the best fit for you, but I thought about something that could be a workaround.
Railway redeploy doesn't wait for completion, it just triggers and exits. The CLI doesn't have a reliable "wait and report status" option for your use case.
The best option might be polling the Railway GraphQL API after triggering the redeploy.
So, what would work basically:
1. Deploying pre-built images, totally supported. Just set your service source to "Docker Image" and point it at ghcr.io/user/yourimage:tag. Railway pulls it, no rebuild.
2. Waiting for deployment- Use the API. e.g (got some AI help there):
- name: Deploy and Wait
env:
RAILWAY_TOKEN: ${{ secrets.RAILWAY_TOKEN }}
SERVICE_ID: ${{ secrets.RAILWAY_SERVICE_ID }}
ENV_ID: ${{ secrets.RAILWAY_ENVIRONMENT_ID }}
run: |
# Trigger redeploy
npx @railway/cli redeploy --service $SERVICE_ID -y
# Poll until done
for i in {1..60}; do
STATUS=$(curl -s -X POST https://backboard.railway.app/graphql/v2 \
-H "Authorization: Bearer $RAILWAY_TOKEN" \
-H "Content-Type: application/json" \
-d '{"query":"{ deployments(first:1, input:{serviceId:\"'$SERVICE_ID'\", environmentId:\"'$ENV_ID'\"}){ edges{ node{ status }}}}"}' \
| jq -r '.data.deployments.edges[0].node.status')
echo "Status: $STATUS"
[[ "$STATUS" == "SUCCESS" ]] && exit 0
[[ "$STATUS" =~ ^(FAILED|CRASHED)$ ]] && exit 1
sleep 10
done
exit 1 # timeout
3. First deployment without clicking. You can use the serviceCreate mutation via the API, but honestly it's easier to just click-deploy once in the dashboard and automate from there.
4. Also, If you connect your GitHub repo directly to Railway, they fire deployment_status events back to GitHub. You could use that to trigger post-deploy actions (see their docs on deployment_status workflows). But this only works if Railway is building from your repo, not pulling from GHCR.
TL;DR
- railway redeploy triggers but doesn't wait
- Poll https://backboard.railway.app/graphql/v2 for deployment status
- Check for SUCCESS or FAILED status in the response
- Exit non-zero on failure to break your pipeline
Sources:
https://docs.railway.app/guides/github-autodeploys (Wait for CI feature)
https://docs.railway.app/reference/deployments (Deployment states/statuses)
https://docs.railway.app/guides/services (Deploying from Docker images)
https://docs.railway.app/deploy/railway-up (CLI deployment)
https://docs.railway.app/reference/public-api (GraphQL API reference)
Community/Forum:
https://station.railway.com/questions/help-deploy-prebuilt-docker-image-via-7df0da30
GraphQL API:
https://backboard.railway.app/graphql/v2 (API endpoint)