10 months ago
I am currently having an issue with a race condition where I create a service and a volume after that, but because the service image was run before the volume was created persistent storage doesnt happen until a restart of the deployment.
I am currently using the API to create services and volumes.
I have also tried creating the service, then the volume, then removing the deployment and restarting it all sequentially, this doesnt work either. I have to remove and redeploy the service deployment after its completed the first time, only then does the volume work.
62 Replies
10 months ago
Hey, maybe you can create a service and remove the deployment right after? Can I know what mutations are you using?
10 months ago
mutation ServiceCreate($input: ServiceCreateInput!) {
serviceCreate(input: $input) {
id
name
icon
createdAt
updatedAt
project {
baseEnvironmentId
environments {
edges {
node {
deployments(first: 1) {
edges {
node {
id
status
}
}
}
}
}
}
}
}
}Service Create
10 months ago
mutation VolumeCreate($projectId: String!, $environmentId: String!, $serviceId: String!, $mountPath: String!, $region: String!) {
volumeCreate(
input: {projectId: $projectId, environmentId: $environmentId, serviceId: $serviceId, mountPath: $mountPath, region: $region}
) {
id
name
createdAt
}
}Then Volume Create
10 months ago
In this order, the first deplyoment isnt persisted
10 months ago
Then I added a
mutation DeploymentRemove($id: String!) {
deploymentRemove(id: $id)
}
mutation DeploymentRedeploy($id: String!) {
deploymentRedeploy(id: $id) {
id
status
createdAt
}
}So that this runs immediately after volume creation, but it didnt seem to work either (the first deployment wast removed and redployed)
10 months ago
Sorry, missed the last part of your message, so basically when you try to remove the initial deployment, nothing happens?
10 months ago
yeah
10 months ago
Will give it a test, give me a minute.
10 months ago
I see another way of doing this, create an empty service (with no source), attach volume and then call serviceInstanceUpdate with your source.
10 months ago
Thats actually not bad
10 months ago
That eliminates the need for the deployments relation and all of the deployments call
10 months ago
Let me give it a go
10 months ago
i think i am meant to run something else after this, to actually get the deployment started
10 months ago
Maybe serviceInstanceRedeploy should do the trick
10 months ago
im about to try DeployV2
10 months ago
if that doesnt work ill go redeploy
10 months ago
Great, looks like the dashboard uses serviceInstanceDeploy

10 months ago
love the help and effort with the debugging man!
10 months ago
thank you so much
10 months ago
moment of truth
10 months ago
wtf, it just stopped
10 months ago
after deploying lol
10 months ago
Stopped?
10 months ago
yeah
10 months ago
What do you mean? the deployment stopped?
10 months ago
Like removed
10 months ago
I think i know why give me a second, to try again
10 months ago
IT WORKS
10 months ago
Ig there is just one more thing, I manually set the region on the service update, etc
10 months ago
But now I get this always on the service

10 months ago
10 months ago
Maybe the volume or service are in different regions?
10 months ago
i set them up to be the same
10 months ago
After creating the empty service I do this
mutation UpdateRegions($environmentId: String!, $serviceId: String!, $multiRegionConfig: JSON!) {
serviceInstanceUpdate(
environmentId: $environmentId
serviceId: $serviceId
input: {multiRegionConfig: $multiRegionConfig}
)
}Set it to EU
10 months ago
Create the Volume, in EU
10 months ago
Then do this new flow
mutation serviceInstanceUpdateAndDeploy($environmentId: String!, $serviceId: String!, $image: String!, $region: String!) {
serviceInstanceUpdate(input: {source: {image: $image}, region: $region}, serviceId: $serviceId)
serviceInstanceDeployV2(environmentId: $environmentId, serviceId: $serviceId)
}Setting EU as well
10 months ago
wtf, the deployment is removed now lol
10 months ago
time for more tests, give me a minute again
10 months ago
dont worry about this, its because the system was off
10 months ago
Just a guess but maybe try serviceInstanceDeploy?
10 months ago
"lastCommit": true works for images too
10 months ago
will do next, rn im switching the possitions of the calls
- EmptyServiceCreate
- UpdateServiceInstanceRegionOnly
- Create Volume in same region
- Update service adding image and deploying after
10 months ago
Doesnt work
10 months ago
ill try this now
10 months ago
Also, I see that you're using $region here, maybe continue with $multiRegionConfig?
10 months ago
Yeah
10 months ago
trying
10 months ago
nshh
10 months ago
donest work
10 months ago
this is weird
10 months ago
For some reason it migrates the Volume to US East
10 months ago
The only reason I can see here for this is that Railway is using some kind of default region, maybe try updating the preferred region? Not a fix but can help us debug a little bit more

10 months ago
Yeah isnt, because I want dynamic regions
10 months ago
this worked before when I didnt have volumes
10 months ago
But now with volumes its broken
10 months ago
I had no problems following what you did

10 months ago
Here's what I did:
ServiceCreate:
mutation ServiceCreate($input: ServiceCreateInput!) {
serviceCreate(input: $input) {
id
name
icon
createdAt
updatedAt
}
}
{
"input": {
"name": "teste",
"projectId":"40f983b6-e729-4f32-be47-346ef7d5a9c0"
}
}ServiceInstanceUpdate:
mutation update($config: JSON!) {
serviceInstanceUpdate(
environmentId: "55bc433f-96d0-4415-9814-cacf9bd1e475"
serviceId: "cfa44c0c-3f88-4a16-a465-998286082d8a"
input: {multiRegionConfig: $config, source: {image: "hello-world"}}
)
}
{
"config": {
"us-east4-eqdc4a": null,
"europe-west4-drams3a": {
"numReplicas": 1
}
}
}VolumeCreate:
mutation VolumeCreate($projectId: String!, $environmentId: String!, $serviceId: String!, $mountPath: String!, $region: String!) {
volumeCreate(
input: {projectId: $projectId, environmentId: $environmentId, serviceId: $serviceId, mountPath: $mountPath, region: $region}
) {
id
name
createdAt
}
}
{
"projectId": "40f983b6-e729-4f32-be47-346ef7d5a9c0",
"environmentId": "55bc433f-96d0-4415-9814-cacf9bd1e475",
"serviceId": "cfa44c0c-3f88-4a16-a465-998286082d8a",
"mountPath": "/data",
"region": "europe-west4-drams3a"
}ServiceDeploy:
mutation {
serviceInstanceDeploy(
latestCommit: true
serviceId: "cfa44c0c-3f88-4a16-a465-998286082d8a"
environmentId: "55bc433f-96d0-4415-9814-cacf9bd1e475"
)
}10 months ago
Hmm you are forcing null on us east
10 months ago
I’ll try
10 months ago
It works
10 months ago
You are a life saver
Status changed to Solved brody • 10 months ago