R
Railwayβ€’6mo ago
wetendorff

Help Implementing Branch Previews for Railway

I am currently working on implementing neon branches via GitHub Actions whenever a new pull request is initiated. I've been inspired by the neon demo project "preview-branches-with-vercel." (https://github.com/neondatabase/preview-branches-with-vercel/tree/main) However, I've encountered a challenge when trying to implement the preview site in Railway. The Railway CLI doesn't have an option for creating environments. I can't use automatically created PR environments, as the neon branch action creates a fresh database URL that the preview site needs to connect to the database. I've been trying to find a viable workaround or a way to implement this. However, I'm currently stuck and could use some advice. Does anyone have any suggestions on how I could go about this or if a feature/support is planned to enable such workflows within the Railway ecosystem?
GitHub
GitHub - neondatabase/preview-branches-with-vercel: Example project...
Example project that shows how you can create a branch for every preview deployment on Vercel using GitHub actions - GitHub - neondatabase/preview-branches-with-vercel: Example project that shows h...
22 Replies
Percy
Percyβ€’6mo ago
Project ID: N/A
wetendorff
wetendorffβ€’6mo ago
N/A
Brody
Brodyβ€’6mo ago
I think @Faolain has successfully done this exact same thing, though I can't remember if it was with planet scale or neon
Faolain
Faolainβ€’6mo ago
Indeed I have thanks for the tag Brody. Hey @wetendorff I created my own GitHub action to do exactly this using neon & railway
Faolain
Faolainβ€’6mo ago
The action I created is a bit barebones and only supports one service at the moment but I was thinking to expand it maybe this xmas weekend if I find some time but essentially - https://github.com/Faolain/railway-pr-deploy (for instantiating the environment) - https://github.com/Faolain/railway-pr-delete (for cleanup) and then how to use it
GitHub
GitHub - Faolain/railway-pr-deploy
Contribute to Faolain/railway-pr-deploy development by creating an account on GitHub.
GitHub
GitHub - Faolain/railway-pr-delete
Contribute to Faolain/railway-pr-delete development by creating an account on GitHub.
Faolain
Faolainβ€’6mo ago
and that's the github action on how to use it
wetendorff
wetendorffβ€’6mo ago
Thanks @Faolain and @Brody. It looks exactly like what I'm looking for. Thank you very much! I'll try it out later.
Faolain
Faolainβ€’6mo ago
You're very welcome! Xmas gift πŸ˜›
wetendorff
wetendorffβ€’6mo ago
@Faolain It works like a charm. Thanks again 1010
Faolain
Faolainβ€’6mo ago
you're very welcome! πŸ™‚
wetendorff
wetendorffβ€’6mo ago
@Faolain Just one little thing: For some reason, steps.railway_deploy.outputs.domain appears to be empty πŸ€”
Faolain
Faolainβ€’6mo ago
ah sorry about that, I need to update the docs it's service_domain, not domain that was an older version and I never changed it in the README This is where I set it https://github.com/Faolain/railway-pr-deploy/blob/main/index.js#L282 just updated the docs for it
wetendorff
wetendorffβ€’6mo ago
I relied too heavily on IntelliSense 😊 It works now.
Faolain
Faolainβ€’6mo ago
haha perfect I'm going to be doing an update to support multiple services as it's very "naive" now Would love some railway input though and also some endpoints which would help simplify the steps quite heavily open to any PRs though
wetendorff
wetendorffβ€’6mo ago
I also find it strange that it was not possible to make previews with railway cli.
Faolain
Faolainβ€’6mo ago
agreed, as it's shown it can be done, it's hacky but it works hehe Sidenote I pushed another update to handle multiple services, it's also very very rudimentary at the moment and I don't suggest you update if what you have works @wetendorff but I'm setting up infra so that split workers can work alongside an app. Latest is v2.0.4 but imo the action in theory isn't ready for public consumption as it's very shoot from the hip, I'd like something more professional but time is always a bottleneck. In any case if you happen to have multiple running applications in a project v2.0.4 will work (for example a worker app and an api)
Mahmoud
Mahmoudβ€’5mo ago
I'm working on a blog post which covers this. Glad to see that there's interest πŸ˜„ If you have any Neon-related questions feel free to reach out
ian
ianβ€’4mo ago
Hey @Mahmoud! Did that blog post end up coming out? πŸ˜„ I'd love to know if there's an official way to integrate Neon branches with Railway's automatic PR environments
Mahmoud
Mahmoudβ€’4mo ago
I'm still looking into it. The Railway CLI doesn't support preview deployments so I'll need to do something with the API instead
Faolain
Faolainβ€’4mo ago
Hey @Mahmoud bumping this, https://discord.com/channels/713503345364697088/1188399481507545119/1188592663776219176 we use this live in prod including neon branches & railway
Mahmoud
Mahmoudβ€’4mo ago
oh this is very cool. I saw it but forgot to check it I'll create my own project and try it out. Thanks @Faolain !
ian
ianβ€’4mo ago
Hey @Faolain! Thank you, I'll take a look at those Github Actions as well πŸ™‚ if I'm not mistaken, they create Railway environments programmatically without making use of Railway's native PR environments feature right?
Want results from more Discord servers?
Add your server
More Posts
project build error, it used to work well. Tunnel connection failed: 403 Forbiddeni have a simple project, https://railway.app/project/082a724b-8d54-43c3-92e9-d2b4c03acf57, i updateCan't remove cron job.https://cdn.discordapp.com/attachments/727689277219012669/1188368483583524864/CleanShot_2023-12-24_aDeploying Angular App - "Nixpacks build failed" ErrorHi! I am hoping someone can help me please. I am trying to deploy an Angular App. I have done this bupgrade to pro issuejust upgraded to pro plan, but getting this after i transferd my projectWriting files to a disk increases RAM usageI have a simple program that lets the user send the video. It downloads it and saves to the disk. NoRailway created a new team while I wanted to upgrade my other teamHi there, recently I tried to upgrade my team from the hobby plan to the pro plan to get access to tError: Cannot find module './pnpm.cjs' when trying to build an Nx monorepo appI might just be off the beaten track here with pnpm, as this looks like a build system error rather DockerFile fails to install packages with yarn install and doesn't generate node_modulesThis is my DockerFile ```# Build stage FROM node:18 as builder WORKDIR /app COPY package.json . COPYv2 Migration: N8N - Application failed to respondAfter migrating to v2, I can no longer access my N8N installation. Migration seems to have been compHow to fix 'Application failed to respond' error and add Python (flask) to Nextjs app on Railway?**Context/What I want to do:** I have an app that uses nextjs and flask. I have the following folder