How to make sure Volume is attached immediately a Service Starts

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.

Solved$30 Bounty

62 Replies

a year ago

Hey, maybe you can create a service and remove the deployment right after? Can I know what mutations are you using?


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


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


In this order, the first deplyoment isnt persisted


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)


a year ago

Sorry, missed the last part of your message, so basically when you try to remove the initial deployment, nothing happens?


yeah


a year ago

Will give it a test, give me a minute.


a year ago

I see another way of doing this, create an empty service (with no source), attach volume and then call serviceInstanceUpdate with your source.


Thats actually not bad


a year ago

That eliminates the need for the deployments relation and all of the deployments call


Let me give it a go


i think i am meant to run something else after this, to actually get the deployment started


a year ago

Maybe serviceInstanceRedeploy should do the trick


im about to try DeployV2


if that doesnt work ill go redeploy


a year ago

Great, looks like the dashboard uses serviceInstanceDeploy

1446979043504427150


love the help and effort with the debugging man!


thank you so much


moment of truth


wtf, it just stopped


after deploying lol


a year ago

Stopped?


yeah


a year ago

What do you mean? the deployment stopped?


Like removed


I think i know why give me a second, to try again


IT WORKS


Ig there is just one more thing, I manually set the region on the service update, etc


But now I get this always on the service

1446981962974630018




a year ago

Maybe the volume or service are in different regions?


i set them up to be the same


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


Create the Volume, in EU


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


wtf, the deployment is removed now lol


a year ago

time for more tests, give me a minute again


dont worry about this, its because the system was off


a year ago

Just a guess but maybe try serviceInstanceDeploy?


a year ago

"lastCommit": true works for images too


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

Doesnt work


ill try this now


a year ago

Also, I see that you're using $region here, maybe continue with $multiRegionConfig?


Yeah


trying


nshh


donest work


this is weird


For some reason it migrates the Volume to US East


a year 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

1446987648983105546


Yeah isnt, because I want dynamic regions


this worked before when I didnt have volumes


But now with volumes its broken


a year ago

I had no problems following what you did

1446992846358839326


a year 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"
  )
}

Hmm you are forcing null on us east


I’ll try


It works


You are a life saver


Status changed to Solved brody • 11 months ago


Welcome!

Sign in to your Railway account to join the conversation.

Loading...