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


10 months ago

The deploy didn't work using github/actions


10 months ago

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


10 months ago

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


10 months ago

Thank you everybody to try help me.


10 months ago

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


10 months 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?


10 months ago

Thalles I am using Railway


10 months ago

But with CI


10 months ago

I need to deploy just the backend on Railway.app


10 months ago

And I used the interface settings and follow the steps


10 months ago

but didn't work


10 months 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


10 months ago

I follow this link before


10 months ago

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


10 months ago

I changed the settings properly


10 months ago

what issues did you have then?


10 months ago

are you using turborepo?


10 months ago

the ci on github actions is that

1309266592001032200


10 months ago

On the railway is the other picture


10 months ago

wait a secound


10 months ago

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


10 months ago

So I follow the link before that


10 months ago

and didn't work again


10 months ago

what i have to change?


10 months ago

Deploy is npm run start:build


10 months ago

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


10 months ago

No I am not using turborepo. I createad using workspaces


10 months ago

created*


10 months ago

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


10 months ago

I would like to use the same with Railway


10 months ago

without learn other tool or method



10 months ago

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


10 months ago

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


10 months ago

I followed this link before



10 months ago

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


10 months ago

railway up should just get your code and push it


10 months ago

Yeah but didn't work


10 months ago

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


10 months ago

what didnt worked?


10 months ago

Is there some example that I could follow?


10 months ago

none that i know


10 months ago

I got it. I will try again


10 months ago

But is hard back and back the same issue


10 months ago

Deploy should be easy


10 months ago

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


maddsua
HOBBY

10 months ago

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


10 months ago

no, he's following an outdated blog post


maddsua
HOBBY

10 months ago

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


maddsua
HOBBY

10 months ago

oh, Brody is about to publish an updated version


10 months ago

yeah, confused on what issue he's getting


maddsua
HOBBY

10 months ago

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


maddsua
HOBBY

10 months 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

10 months ago

much cleaner


maddsua
HOBBY

10 months ago

🤌


10 months 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


10 months 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?


10 months ago

you can simply have railway wait on your CI -


10 months ago

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


10 months ago

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


10 months ago

is the source of your service your GitHub repo?


10 months ago

I can only share the file

1311467399119114363


10 months ago

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


10 months ago

Thank you


growlab-organics
PRO

4 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

4 months ago

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


Status changed to Solved adam 4 months ago