Deploy using CI/CD Github Actions

a year ago

I created a simple script to deploy my backend using github actions and workflow. Could someone help me?

Deploy do Backend na Railway

deploy-backend:
runs-on: ubuntu-latest

steps:
  - name: Checkout the code
    uses: actions/checkout@v2

  - name: Set up Node.js
    uses: actions/setup-node@v2
    with:
      node-version: '18.x'

  - name: Install Railway CLI
    run: npm install -g @railway/cli

  - name: Inject Railway Token
    env:
      RAILWAY_TOKEN: ${{ secrets.RAILWAY_TOKEN }}
    run: echo "RAILWAY_TOKEN is set up."

  - name: Deploy Backend on Railway
    working-directory: ./packages/backend
    run: railway up
Solved

2 Replies


a year ago

what seems to be the issue?


maddsua
HOBBY

a year ago

Well, you could skip the entire install node/cli part by using the docker image directly


maddsua
HOBBY

a year ago

Also, you need to provide service name using the respective flag


a year ago

I am looking to create a script with CI to deploy just the backend on railway. I created a Monorepo and the frontend is on vercel and backend should be in Railway


maddsua
HOBBY

a year ago

deploy-job:
  runs-on: ubuntu-latest
  container: ghcr.io/railwayapp/cli:latest
  env:
    SVC_ID: my-service
    RAILWAY_TOKEN: ${{ secrets.RAILWAY_TOKEN }}
  steps:
    - uses: actions/checkout@v3
    - run: railway up --service=${{ env.SVC_ID }}

maddsua
HOBBY

a year ago

two major differences are:

  1. use docker image directly instead of installing the cli via npm

  2. --service flag that tells to which service to deploy


a year ago

Awesome I will 😄


maddsua
HOBBY

a year ago

well, this should work without an issue


maddsua
HOBBY

a year ago

this is how I deploy my stuff to railway


maddsua
HOBBY

a year ago

you'd only need to update working directory to the one containing your actual code


a year ago

Run railway up --project=1838b8e6-6a84-4a60-9033-3b38888c4746
error: unexpected argument '--project' found

tip: to pass '--project' as a value, use '-- --project'

Usage: railway up [OPTIONS] [PATH]

For more information, try '--help'.
Error: Process completed with exit code 2.


a year ago

I received this error on Github CI terminal


maddsua
HOBBY

a year ago

may I ask what's the --project argument doing there?


maddsua
HOBBY

a year ago

I don't think the cli even has an arg like that


maddsua
HOBBY

a year ago

when running in ci mode you need to provide project token with RAILWAY_TOKEN env var and a service name with --service argument


a year ago

Run railway up --service=1838b8e6-6a84-4a60-9033-3b38888c4746
Service not found
Error: Process completed with exit code 1.


maddsua
HOBBY

a year ago

honestly I don't remember if we support account-scoped access tokens and setting project id via a flag atm


maddsua
HOBBY

a year ago

you need to use service name, not it's id


maddsua
HOBBY

a year ago

because at the time when I was working on fixing ci mode, adding support for that would involve rewriting too much stuff


a year ago

Great, helped me. I will change here


a year ago

could i ask why you arent using the default Railway's build system?


a year ago

I would like to make a CI in a Monorepo send a project Next to Vercel and Backend on Railway


maddsua
HOBBY

a year ago

real


maddsua
HOBBY

a year ago

unbelievable but there are people who don't deploy everything to railway


a year ago

but you can deploy a monorepo on Railway


a year ago


a year ago

Okay so do you have a example of CI like a file I sent here?


maddsua
HOBBY

a year ago

umm if you wanna use monorepo support you don't need to configure gh actions, it's configured in railway dashboard


maddsua
HOBBY

a year ago

you gotta link a repo to a service first, and then play with the settings a bit


a year ago

The deploy didn't work using github/actions


a year ago

I would like to understand better,and I tried a lot to learn how solve it.


a year ago

But I quit haha I have been try to deploy using countinous integrations and I believe is really hard to deploy.


a year ago

Thank you everybody to try help me.


a year ago

Hello @maddsua, how are you? Could we talk about the deploy again?


a year ago

hey, im still confused on why you're not using the Railway's build system.
do you want to run tests and everything before deploying?


a year ago

Thalles I am using Railway


a year ago

But with CI


a year ago

I need to deploy just the backend on Railway.app


a year ago

And I used the interface settings and follow the steps


a year ago

but didn't work


a year ago

what steps went wrong while trying this?
https://docs.railway.com/guides/monorepo
you dont need a CI at all for deploying a specific app inside a monorepo


a year ago

I follow this link before


a year ago

i deploy my backend on Railway and nextjs app on vercel with that


a year ago

I changed the settings properly


a year ago

what issues did you have then?


a year ago

are you using turborepo?


a year ago

the ci on github actions is that

1309266592001032200


a year ago

On the railway is the other picture


a year ago

wait a secound


a year ago

thats the thing, you dont need Github Actions at all for this


a year ago

So I follow the link before that


a year ago

and didn't work again


a year ago

what i have to change?


a year ago

Deploy is npm run start:build


a year ago

ok lets start from the beginning, are you using turborepo?


a year ago

No I am not using turborepo. I createad using workspaces


a year ago

created*


a year ago

But is not a problem. Because the deploy on vercel is working


a year ago

I would like to use the same with Railway


a year ago

without learn other tool or method



a year ago

I would like to use the same idea that is working on vercel


a year ago

If Railway doesn't have support I believe is not about my idea


a year ago

I followed this link before



a year ago

ok, pretty sure you dont need --auto-approve then


a year ago

railway up should just get your code and push it


a year ago

Yeah but didn't work


a year ago

if you want your Github Actions to wait for your build to complete, you can use --ci


a year ago

what didnt worked?


a year ago

Is there some example that I could follow?


a year ago

none that i know


a year ago

I got it. I will try again


a year ago

But is hard back and back the same issue


a year ago

Deploy should be easy


a year ago

feel you, unfortunately there's no example right now
and that blog post is outdated


maddsua
HOBBY

a year ago

hey im confused with what's not working here. is --auto-approve even a real argument?


a year ago

no, he's following an outdated blog post


maddsua
HOBBY

a year ago

if you push from the cli railway has no way of applying any git contributor restrictions


maddsua
HOBBY

a year ago

oh, Brody is about to publish an updated version


a year ago

yeah, confused on what issue he's getting


maddsua
HOBBY

a year ago

also, since the cli now has it's own docker image, there's no need to use npm


maddsua
HOBBY

a year ago

deploy-job:
  runs-on: ubuntu-latest
  container: ghcr.io/railwayapp/cli:latest
  env:
    SVC_ID: my-service
    RAILWAY_TOKEN: ${{ secrets.RAILWAY_TOKEN }}
  steps:
    - uses: actions/checkout@v3
    - run: railway up --service=${{ env.SVC_ID }}

maddsua
HOBBY

a year ago

much cleaner


maddsua
HOBBY

a year ago

🤌


a year ago

im with thalles on this, i dont know why you need railway up here, attach the repo to your railway service and set the correct config


a year ago

Well, it's very confusing and it seems like I'm not being clear in the way I'm explaining the problem.

My intention was to do a continuous integration using github actions, that's the goal.

From what I understand, I need to go to the platform to get the token and insert it into my github actions. However, when I do the deployment, the service is not created on the platform and there are several impediments, whether command or support.

The big question, have you managed to do the deployment the way I'm describing?

If so, do you have any example files that I can analyze the codes for, or do you want mine to analyze?

I don't use turbo repo, but workspaces in the package.json of the root folder. In vercel, a small frontend test worked, I tried to put the backend there and it didn't work, so I wanted to fix it in another location, which would be the railroad.

But no other platform is helping me with this specific problem. Did you manage to see the problem?


a year ago

you can simply have railway wait on your CI -


a year ago

I don't see why railway up is needed, sorry


a year ago

I just followed the other link on the blog. Okay I remove this command. So I only need to run deploy again?


a year ago

is the source of your service your GitHub repo?


a year ago

I can only share the file

1311467399119114363


a year ago

i'm sorry but we are all just repeating ourselves and getting nowhere, we all wish you good luck as you solve this!


a year ago

Thank you


growlab-organics
PRO

5 months ago

Hi everyone, we're trying to deploy a service to our Railway account using the following Github Action but keep seeing the error Project Token not found. We've set the ${{ secrets.RAILWAY_TOKEN }} value to a token created from the project settings page, not sure what else we should do?

  deploy:
    runs-on: ubuntu-latest
    container: ghcr.io/railwayapp/cli:latest
    env:
      RAILWAY_ENVIRONMENT_ID: 48416f8b-40ed-4980-befc-e4222e83697e
      RAILWAY_SERVICE_ID: db5c7057-6541-4842-bb57-49135ce5bd0f
      RAILWAY_TOKEN: ${{ secrets.RAILWAY_TOKEN }}
    steps:
      - uses: actions/checkout@v4
      - run: |
          railway up --ci \
            --environment=$RAILWAY_ENVIRONMENT_ID \
            --service=$RAILWAY_SERVICE_ID

5 months ago

Hello, please create your own thread. This thread was resolved 7 months ago


Status changed to Solved adam 5 months ago