20 days ago
Hello!
I deploy my application using a Docker image. My usual development cycle looks like this:
Push changes to the Git repository
Build a new Docker image on CircleCI
Use curl to call
serviceInstanceUpdate()with{ "source": { "image": "user/repo:new-tag-vXXX" } }asinputvariable to update the image tag on the Railway serviceUse curl to call
serviceInstanceDeployV2()to deploy the new image tag
This worked great until one day I set the number of replicas for the service to 2 via the UI.
Now, after calling serviceInstanceUpdate(), the number of replicas reverts to one. Why is this happening and how can I fix it?
4 Replies
18 days ago
The numReplicas field in the serviceInstanceUpdate mutation has a default value of 1. When you call the mutation without explicitly including numReplicas in your input, it resets to that default. To preserve your replica count, include numReplicas: 2 (or your desired count) in the input alongside the source field in your serviceInstanceUpdate call.
Status changed to Awaiting User Response Railway • 18 days ago
18 days ago
I would say that this behavior is a little unexpected, but okay.
I can't set a specific number of replicas because it can change between deployments via the dashboard. I need the same number of replicas to be retained after calling serviceInstanceUpdate() as there were before.
Also, as far as I know, the numReplicas field is deprecated (https://station.railway.com/questions/update-number-of-instances-via-api-2499832f), so I need to use multiRegionConfig instead.
I tried to get the current number of replicas by calling serviceInstance(). In response, I received json, which says that I have one replica here .data.serviceInstance.latestDeployment.meta.serviceManifest.deploy.multiRegionConfig, although right now there are two when I look at the UI. Am I getting the number of replicas in some incorrect way, or is something wrong with the API?
I used railway-cli as a reference to get current number of replicas (https://github.com/railwayapp/cli/blob/427c325f220ba2ecdd64828a4bace5426165e86e/src/commands/scale.rs#L161-L168). When I run railway service scale ... I see 1 replica instead of 2 there too.
Status changed to Awaiting Railway Response Railway • 18 days ago
17 days ago
Is your use case just to update the image tag and redeploy?
If so, you can do that via the CLI:
railway link --workspace $WORKSPACE_ID --environment $ENVIRONMENT_ID --project $PROJECT_ID
railway env edit —-service-config $SERVICE_ID "source.image" “user/repo:new-tag-vXXX”Status changed to Awaiting User Response Railway • 17 days ago
14 days ago
It worked, thank you!
Status changed to Awaiting Railway Response Railway • 14 days ago
Status changed to Solved brody • 14 days ago