#Deploying with a GitHub Action

68 messages · Page 1 of 1 (latest)

fast sandal
#

I'm looking for some pointers on how to deploy our app via GitHub actions. Specifically I am having trouble specifying the environment when I link the project.

I have tried running
railway environment [env]
This works and links to that environment. However, when I follow it up with
railway link [project_id]
it prompts me for the environment to deploy to. Is there a way to provide an environment flat to the link so that it knows which environment to deploy to with running railway up?

Any help on this would be appreciated. What I am ultimately trying to do it deploy to a specific service, within a specifc environment from a Github action.

foggy heathBOT
#

Project ID: d36cedc3-d1a4-453b-9e36-45d7299cabfd

fast sandal
#

d36cedc3-d1a4-453b-9e36-45d7299cabfd

real dew
#

provide both the --environment and --service flags directly to railway up so you can skip railway link and railway environment

fast sandal
#

Is the service arg the uuid of the service, or the name itself?

real dew
#
~>railway up --help
Upload and deploy project from the current directory

Usage: railway up [OPTIONS] [PATH]

Arguments:
  [PATH]

Options:
  -d, --detach                     Don't attach to the log stream
  -s, --service <SERVICE>          Service to deploy to (defaults to linked service)
  -e, --environment <ENVIRONMENT>  Environment to deploy to (defaults to linked environment)
      --json                       Output in JSON format
  -h, --help                       Print help
  -V, --version                    Print version
#

i think both work, but im not exactly sure on that

fast sandal
#

Ok, going to give that a whirl! Do i need to adjust the custom build command or will it bypass it when up is used?

real dew
#

is this a build command you have set in the service settings?

fast sandal
#

I had it set in the Railway dashboard from when I was using the github integration

#

and hte build was happening on railway, now the build is happening in the github action and i just want to pass over the directory

real dew
#

build is still happening on railway, your just using the cli to ship your code to railway in a tarball instead of having railway pull your repo

fast sandal
#

Ah ok - but the contents of the current directory that im in with calling railway up is what itll have access to when running its build?

real dew
#

that sounds correct, that what railway up would bundle up and sent to railway

fast sandal
#

Ok I think Im set for now, appreciate the help!

real dew
#

no prob!

heavy tusk
#

speaking of that, maybe it would be a good idea to create a railway action?

real dew
#

go for it

heavy tusk
#

what I mean is I can totally do that but is it actually needed

#

you know better than I do

real dew
#

if you need it and it's something you want, then build it

heavy tusk
#

I use gitlab 💀

real dew
#

well that's a whole other separate issue

fast sandal
#

@real dew -

  • Does this in anyway look at the .gitignore when it runs the build command in Railway to decide whether to include certain files?
  • Is there a way to pry into the deployment to inspect the file contents?
    -- Figured this out (just read the docs 😆 ) - and the file is in fact there, so not quite sure why its saying it cant find it.
  • The problem I am running into is that I am generating the types for the project in Github actions, and passing those types in the newly created files along with the railway up command. When the project is ran in Railway, its not finding those files. Those type files are included in the .gitignore if that makes a difference
fast sandal
real dew
#

railway up does indeed ignore patterns specified in the .gitignore

fast sandal
#

The files are there when I jump into the box. They are fresh every build no?

real dew
#

jump into the box?

fast sandal
#

open up a shell for the service

real dew
#

railway does not provide a shell or ssh for the container, if you are referring to railway shell that is a local shell, but with the linked service variables now available locally

fast sandal
#

Ah I see - how can I tell what the directory looks like for the service?

real dew
#

it would look like your project minus files and folders that are in the .gitignore, but whats been uploaded gets placed in an /app directory at the root of the container

#

if you have the types in your .gitignore file railway up wont upload them

fast sandal
#

Hmm ok - gotta figure out a way around that for my usage then.

real dew
#

have railway's build generate the types?

fast sandal
#

I think so..

real dew
#

why not? (genuine question)

fast sandal
#

Right now just extra config to ensure the type generation scripts can all work within the railway ecosystem (env vars n such) - was aiming to have the dx be all of that was handled in github, and railway just hosted the service

real dew
#

i think you should let railway do that stuff too, work with railway

fast sandal
#

and to be fair I already have to manage the env vars within railway for all of the thing swithin the code the references those values anyways, will just need to add whats needed to generate the types

real dew
#

question, are you building with a dockerfile?

fast sandal
#

I am not

#

Can I reference environment variables inline in the build commands?

#

eg in Github ive got
run: yarn workspace backend supabase link --project-ref ${{ secrets.SUPABASE_PROJECT_REF }} -p ${{ secrets.DATABASE_PASSWORD }}

real dew
#

that doesnt look like a build command, but you can add those env vars to the service and then referance them with the linux $ENV_VAR syntax in a custom phase inside your nixpacks.toml file, like so

[phases.link_supabase]
    dependsOn = ['setup']
    cmds = ['yarn workspace backend supabase link --project-ref $SUPABASE_PROJECT_REF -p $DATABASE_PASSWORD']
fast sandal
#

where would that phases command by referenced in the build config for the project?

real dew
#

what do you mean exactly by build config? nixpacks.toml is a build config

fast sandal
#

I am setting the build command in the railway ui for example, are the things in the nixpacks.toml executed before that?

real dew
#

the command you provided really doesn’t look like a build command, so you ideally wouldn't be setting that kind of command as the build command.
but the phases can run at any point during the build with that dependsOn keyword

fast sandal
#

Its just one of the commands im running as part of the type generation

real dew
#

a build command would more so be something like yarn workspace backend build

fast sandal
#

Hm, trying to run the command in the nixpacks.toml

real dew
#
Invalid access token format. Must be like `sbp_0102...1920`
fast sandal
#

Am I able to see that error on my end? Its not the build logs?

real dew
#

yeah i copied it from the log you sent me

fast sandal
#

Ah 🤦‍♂️ - I see it just not where I expected it

real dew
#

it never is

fast sandal
#

We're in business, that approach is working!

real dew
#

awesome!

fast sandal
#

Just wanted to add a note that it would be cool if there was a way (and if there is I couldnt find it), to create environments on the fly with the CLI. The github integration was neat as it synced the PR to its own environment. Was messing with trying to do that without the github integration and wasnt able to get anywhere.

real dew
#

that's actually asked quite frequently

#

cc @shrewd jetty

shrewd jetty
#

literally just yesterday we were talking about adding the ability to create envs in the CLI. i'll create a ticket, i think Ray is going to start giving the CLI some attention soon

fast sandal
#

Everytime I've come into this Discord for the past year or so you all are always helpful. Much appreciated! Is the github integration open source from you all that I can see what all it was doing?

real dew
#

it's not, that would all be internal to railway

oak walrus