Trigger redeploy after docker image rebuild

lukasdeco
PRO

a year ago

We are trying to trigger a redeploy after we rebuild a docker image for a service. We are doing it with the graphql API in a very manual way right now:```


  redeploy_app:
    name: Redeploy app on Railway
    needs: build_and_push
    runs-on: ubuntu-latest
    steps:
      - name: Call Redeploy API
        env:
          RAILWAY_TOKEN: ${{ secrets.RAILWAY_TOKEN }}
        run: |
          curl https://backboard.railway.app/graphql/v2 \
          -X POST \
          -H "Authorization: Bearer ${RAILWAY_TOKEN}" \
          -H "Content-Type: application/json" \
          --data "{\"query\":\"mutation { deploymentRedeploy(id: \\\"xxxxxxx\\\") { status } }\"}" \

``` The issue is I am getting not authorized error returned. But I know I have this token set correctly, and I even tested locally from the command line and got the same error.Well, any idea why I am getting this error? I have tried creating a token multiple times. ORRR... isn't there an easier way to have a service redeploy after the docker image builds? Thanks for any help!

Solved

7 Replies

a year ago

Calling the API seems like a decent solution to me, but you would want to be using the serviceInstanceDeploy mutation with a "No Team" account token.

Here's the body for that request -

{
  "query": "mutation serviceInstanceDeploy($serviceId: String!, $environmentId: String!) {\n  serviceInstanceDeploy(serviceId: $serviceId, environmentId: $environmentId)\n}\n",
  "variables": {
    "environmentId": "",
    "serviceId": ""
  }
}

Status changed to Solved Railway about 1 year ago


lukasdeco
PRO

a year ago

@brody thank you so much for your help. What is a "No Team" account token? I just tried this with the correct values, but I got the same "Not Authorized" again. I know the IDs are correct because I had a few trial and errors with the wrong values


a year ago

You would be using the wrong token -

https://railway.app/account/tokens

Team -> No Team


lukasdeco
PRO

a year ago

this is odd because I created the token UNDER the team that the service is running under... why would that not work?


a year ago

No clue, all I know is that a team token doesn't work.


lukasdeco
PRO

a year ago

wow it totally worked.... I just wish I knew why. Well thanks a bunch!


a year ago

No problem!


Trigger redeploy after docker image rebuild - Railway Help Station