R
Railway10mo ago
drewbie

Deploying with a GitHub Action

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]
railway environment [env]
This works and links to that environment. However, when I follow it up with
railway link [project_id]
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
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.
57 Replies
Percy
Percy10mo ago
Project ID: d36cedc3-d1a4-453b-9e36-45d7299cabfd
drewbie
drewbieOP10mo ago
d36cedc3-d1a4-453b-9e36-45d7299cabfd
Brody
Brody10mo ago
provide both the --environment and --service flags directly to railway up so you can skip railway link and railway environment
drewbie
drewbieOP10mo ago
Is the service arg the uuid of the service, or the name itself?
Brody
Brody10mo ago
~>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
~>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
drewbie
drewbieOP10mo ago
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?
Brody
Brody10mo ago
is this a build command you have set in the service settings?
drewbie
drewbieOP10mo ago
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
Brody
Brody10mo ago
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
drewbie
drewbieOP10mo ago
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?
Brody
Brody10mo ago
that sounds correct, that what railway up would bundle up and sent to railway
drewbie
drewbieOP10mo ago
Ok I think Im set for now, appreciate the help!
Brody
Brody10mo ago
no prob!
maddsua
maddsua10mo ago
speaking of that, maybe it would be a good idea to create a railway action?
Brody
Brody10mo ago
go for it
maddsua
maddsua10mo ago
u serious? what I mean is I can totally do that but is it actually needed you know better than I do
Brody
Brody10mo ago
if you need it and it's something you want, then build it
maddsua
maddsua10mo ago
I use gitlab 💀
Brody
Brody10mo ago
well that's a whole other separate issue
drewbie
drewbieOP10mo ago
@Brody - - 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 I just cache the CLI in Github, makes it speedy
Brody
Brody10mo ago
railway up does indeed ignore patterns specified in the .gitignore
drewbie
drewbieOP10mo ago
The files are there when I jump into the box. They are fresh every build no?
Brody
Brody10mo ago
jump into the box?
drewbie
drewbieOP10mo ago
open up a shell for the service
Brody
Brody10mo ago
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
drewbie
drewbieOP10mo ago
Ah I see - how can I tell what the directory looks like for the service?
Brody
Brody10mo ago
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
drewbie
drewbieOP10mo ago
Hmm ok - gotta figure out a way around that for my usage then.
Brody
Brody10mo ago
have railway's build generate the types?
drewbie
drewbieOP10mo ago
I think so..
Brody
Brody10mo ago
why not? (genuine question)
drewbie
drewbieOP10mo ago
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
Brody
Brody10mo ago
i think you should let railway do that stuff too, work with railway
drewbie
drewbieOP10mo ago
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
Brody
Brody10mo ago
question, are you building with a dockerfile?
drewbie
drewbieOP10mo ago
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 }}
run: yarn workspace backend supabase link --project-ref ${{ secrets.SUPABASE_PROJECT_REF }} -p ${{ secrets.DATABASE_PASSWORD }}
Brody
Brody10mo ago
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']
[phases.link_supabase]
dependsOn = ['setup']
cmds = ['yarn workspace backend supabase link --project-ref $SUPABASE_PROJECT_REF -p $DATABASE_PASSWORD']
drewbie
drewbieOP10mo ago
where would that phases command by referenced in the build config for the project?
Brody
Brody10mo ago
what do you mean exactly by build config? nixpacks.toml is a build config
drewbie
drewbieOP10mo ago
I am setting the build command in the railway ui for example, are the things in the nixpacks.toml executed before that?
Brody
Brody10mo ago
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
drewbie
drewbieOP10mo ago
Its just one of the commands im running as part of the type generation
Brody
Brody10mo ago
a build command would more so be something like yarn workspace backend build
drewbie
drewbieOP10mo ago
Hm, trying to run the command in the nixpacks.toml
No description
Brody
Brody10mo ago
full build logs please https://bookmarklets.up.railway.app/log-downloader/
Invalid access token format. Must be like `sbp_0102...1920`
Invalid access token format. Must be like `sbp_0102...1920`
drewbie
drewbieOP10mo ago
Am I able to see that error on my end? Its not the build logs?
Brody
Brody10mo ago
yeah i copied it from the log you sent me
drewbie
drewbieOP10mo ago
Ah 🤦‍♂️ - I see it just not where I expected it
Brody
Brody10mo ago
it never is
drewbie
drewbieOP10mo ago
We're in business, that approach is working!
Brody
Brody10mo ago
awesome!
drewbie
drewbieOP10mo ago
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.
Brody
Brody10mo ago
that's actually asked quite frequently cc @Melissa
Melissa
Melissa10mo ago
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
drewbie
drewbieOP10mo ago
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?
Brody
Brody10mo ago
it's not, that would all be internal to railway
birki
birki10mo ago
@drewbie I would highly suggest https://github.com/github/branch-deploy (full disclosure I am the creator) There are examples on how to use it with railway here: https://github.com/github/branch-deploy/blob/main/docs/examples.md#railway Also, here is an article I wrote about what the "branch deploy model" is and why you should use it -> https://blog.birki.io/posts/branch-deploy/
Want results from more Discord servers?
Add your server