23 days ago
I publish new docker tags from my CI, which I want to deploy directly to Railway. Inspired by other support threads, I came up with the following shell script:#!/usr/bin/env bash
set -Eeuo pipefail
# GraphQL API endpoint
GRAPHQL_ENDPOINT="https://backboard.railway.com/graphql/v2"
# --- Step 1: Update the service instance image ---
UPDATE_IMAGE_QUERY='mutation ServiceInstanceUpdate($serviceId: String!, $environmentId: String!, $input: ServiceInstanceUpdateInput!) {
serviceInstanceUpdate(serviceId: $serviceId, environmentId: $environmentId, input: $input)
}'
UPDATE_IMAGE_PAYLOAD=$(jq -n \
--arg serviceId "$SERVICE_ID" \
--arg environmentId "$ENVIRONMENT_ID" \
--arg image "$DOCKER_IMAGE_URL" \
--arg query "$UPDATE_IMAGE_QUERY" \
'{
query: $query,
variables: {
serviceId: $serviceId,
environmentId: $environmentId,
input: {
source: {
image: $image
}
}
}
}')
echo "Updating image to: $DOCKER_IMAGE_URL"
curl --fail --silent -X POST "$GRAPHQL_ENDPOINT" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $RAILWAY_API_TOKEN" \
-d "$UPDATE_IMAGE_PAYLOAD"
# --- Step 2: Trigger a redeploy ---
REDEPLOY_QUERY='mutation serviceInstanceRedeploy($serviceId: String!, $environmentId: String!) {
serviceInstanceRedeploy(serviceId: $serviceId, environmentId: $environmentId)
}'
REDEPLOY_PAYLOAD=$(jq -n \
--arg serviceId "$SERVICE_ID" \
--arg environmentId "$ENVIRONMENT_ID" \
--arg query "$REDEPLOY_QUERY" \
'{
query: $query,
variables: {
serviceId: $serviceId,
environmentId: $environmentId
}
}')
echo "Triggering redeploy..."
curl --fail --silent -X POST "$GRAPHQL_ENDPOINT" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $RAILWAY_API_TOKEN" \
-d "$REDEPLOY_PAYLOAD"
The commands are running successfully, the image source in the service settings is updated, but the deployment still points to the old tag. What am I doing wrong?
Pinned Solution
15 days ago
All "ReDeploy" actions I tried, redeployed the same docker tag that was currently deployed, but didn't update the tag. What worked for me was calling "serviceInstanceDeployV2".
Here is the full working script:
#!/usr/bin/env bash
set -Eeuo pipefail
# GraphQL API endpoint
GRAPHQL_ENDPOINT="https://backboard.railway.com/graphql/v2"
# --- Step 1: Update the service instance image ---
UPDATE_IMAGE_QUERY='mutation ServiceInstanceUpdate($serviceId: String!, $environmentId: String!, $input: ServiceInstanceUpdateInput!) {
serviceInstanceUpdate(serviceId: $serviceId, environmentId: $environmentId, input: $input)
}'
UPDATE_IMAGE_PAYLOAD=$(jq -n \
--arg serviceId "$SERVICE_ID" \
--arg environmentId "$ENVIRONMENT_ID" \
--arg image "$DOCKER_IMAGE_URL" \
--arg query "$UPDATE_IMAGE_QUERY" \
'{
query: $query,
variables: {
serviceId: $serviceId,
environmentId: $environmentId,
input: {
source: {
image: $image
}
}
}
}')
echo "Updating image to: $DOCKER_IMAGE_URL"
curl --fail --silent -X POST "$GRAPHQL_ENDPOINT" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $RAILWAY_API_TOKEN" \
-d "$UPDATE_IMAGE_PAYLOAD"
# --- Step 2: Trigger a redeploy ---
REDEPLOY_QUERY='mutation serviceInstanceDeployV2($serviceId: String!, $environmentId: String!) {
serviceInstanceDeployV2(serviceId: $serviceId, environmentId: $environmentId)
}'
REDEPLOY_PAYLOAD=$(jq -n \
--arg serviceId "$SERVICE_ID" \
--arg environmentId "$ENVIRONMENT_ID" \
--arg query "$REDEPLOY_QUERY" \
'{
query: $query,
variables: {
serviceId: $serviceId,
environmentId: $environmentId
}
}')
echo "Triggering redeploy..."
curl --fail --silent -X POST "$GRAPHQL_ENDPOINT" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $RAILWAY_API_TOKEN" \
-d "$REDEPLOY_PAYLOAD"
4 Replies
22 days ago
Hi, can you try this:#!/usr/bin/env bash
set -Eeuo pipefail
# GraphQL API endpoint
GRAPHQL_ENDPOINT="https://backboard.railway.com/graphql/v2"
# Update the service instance image
UPDATE_IMAGE_QUERY='mutation ServiceInstanceUpdate($serviceId: String!, $environmentId: String!, $input: ServiceInstanceUpdateInput!) {
serviceInstanceUpdate(serviceId: $serviceId, environmentId: $environmentId, input: $input)
}'
UPDATE_IMAGE_PAYLOAD=$(jq -n \
--arg serviceId "$SERVICE_ID" \
--arg environmentId "$ENVIRONMENT_ID" \
--arg image "$DOCKER_IMAGE_URL" \
--arg query "$UPDATE_IMAGE_QUERY" \
'{
query: $query,
variables: {
serviceId: $serviceId,
environmentId: $environmentId,
input: {
source: {
image: $image
}
}
}
}')
echo "Updating image to: $DOCKER_IMAGE_URL"
curl --fail --silent -X POST "$GRAPHQL_ENDPOINT" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $RAILWAY_API_TOKEN" \
-d "$UPDATE_IMAGE_PAYLOAD"
echo "Deployment will trigger automatically"
What I think is happening is that when you update the service instance configuration and then immediately call serviceInstanceRedeploy, Railway is redeploying the previous deployment object (which still references the old image tag) rather than creating a fresh deployment from the newly updated configuration. So i think the solution is to remove the redeploy step entirely, since Railway automatically triggers a new deployment when you update the service instance source.
22 days ago
Thanks for your answer. I tried your suggestion, but it doesn't work. Updating the image source in the settings does not update the deployment. Interestingly, when I update the docker tag in the service settings via the UI and press the Deploy button, it works. how can I trigger the "deploy button" via the API?
fdietze
Thanks for your answer. I tried your suggestion, but it doesn't work. Updating the image source in the settings does not update the deployment. Interestingly, when I update the docker tag in the service settings via the UI and press the Deploy button, it works. how can I trigger the "deploy button" via the API?
22 days ago
I think you can call deploymentRedeploy
Attachments
15 days ago
All "ReDeploy" actions I tried, redeployed the same docker tag that was currently deployed, but didn't update the tag. What worked for me was calling "serviceInstanceDeployV2".
Here is the full working script:
#!/usr/bin/env bash
set -Eeuo pipefail
# GraphQL API endpoint
GRAPHQL_ENDPOINT="https://backboard.railway.com/graphql/v2"
# --- Step 1: Update the service instance image ---
UPDATE_IMAGE_QUERY='mutation ServiceInstanceUpdate($serviceId: String!, $environmentId: String!, $input: ServiceInstanceUpdateInput!) {
serviceInstanceUpdate(serviceId: $serviceId, environmentId: $environmentId, input: $input)
}'
UPDATE_IMAGE_PAYLOAD=$(jq -n \
--arg serviceId "$SERVICE_ID" \
--arg environmentId "$ENVIRONMENT_ID" \
--arg image "$DOCKER_IMAGE_URL" \
--arg query "$UPDATE_IMAGE_QUERY" \
'{
query: $query,
variables: {
serviceId: $serviceId,
environmentId: $environmentId,
input: {
source: {
image: $image
}
}
}
}')
echo "Updating image to: $DOCKER_IMAGE_URL"
curl --fail --silent -X POST "$GRAPHQL_ENDPOINT" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $RAILWAY_API_TOKEN" \
-d "$UPDATE_IMAGE_PAYLOAD"
# --- Step 2: Trigger a redeploy ---
REDEPLOY_QUERY='mutation serviceInstanceDeployV2($serviceId: String!, $environmentId: String!) {
serviceInstanceDeployV2(serviceId: $serviceId, environmentId: $environmentId)
}'
REDEPLOY_PAYLOAD=$(jq -n \
--arg serviceId "$SERVICE_ID" \
--arg environmentId "$ENVIRONMENT_ID" \
--arg query "$REDEPLOY_QUERY" \
'{
query: $query,
variables: {
serviceId: $serviceId,
environmentId: $environmentId
}
}')
echo "Triggering redeploy..."
curl --fail --silent -X POST "$GRAPHQL_ENDPOINT" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $RAILWAY_API_TOKEN" \
-d "$REDEPLOY_PAYLOAD"
Status changed to Solved brody • 15 days ago