Environment Variables

Hello everyone, I'm coming from Digital Ocean, and am very confused as to how to set environment variables. I have an API to deploy that I wrote in Rust. I can get the Dockerfile up and my app deployed using the Railway CLI. I need to set an environment variable called APP_APPLICATION__BASE_URL, which I believe corresponds to RAILWAY_STATIC_URL. Nothing I enter in the "Settings > Variables" page of my deployed app seems to work. In Digital Ocean, you'd get the deployment URL by using ${{APP_URL}}. Any tips would be appreciated.
50 Replies
Percy
Percy•2y ago
Project ID: 05c1b2d1-7483-4da5-9ed4-41c5a5e55ba2
Jeff Mitchell
Jeff MitchellOP•2y ago
I don't see a project ID, but the service ID is 05c1b2d1-7483-4da5-9ed4-41c5a5e55ba2
Brody
Brody•2y ago
may I ask what's wrong with grabbing the url from RAILWAY_STATIC_URL? maybe I should mention that this variable is set automatically, there's nothing you need to do for that variable to exist, this may give you a better idea of what's going on with variables in the container https://utilities.up.railway.app/env-vars
Jeff Mitchell
Jeff MitchellOP•2y ago
If I specify a key value pair, APP_APPLICATION__BASE_URL (which is the format my code wants) and make that correspond to RAILWAY_STATIC_URL, the health check fails, presumably because the /health_check endpoint is not reachable.
Brody
Brody•2y ago
oh I take it you do not want to change that environment variables name?
Jeff Mitchell
Jeff MitchellOP•2y ago
No, no, just trying to understand how to use it correctly.
angelo
angelo•2y ago
Hey there @Jeff Mitchell! https://docs.railway.app/develop/variables#railway-provided-variables You can see all the Railway provided variables here.
Railway Docs
Variables | Railway Docs
Documentation for Railway
Jeff Mitchell
Jeff MitchellOP•2y ago
Yep, found that and read through it.
angelo
angelo•2y ago
In your case, the healthcheck endpoint doesn't need to know the root of your app, you just point it to the route that you expect to return 200 if you wanna remap a var you can do something like
Jeff Mitchell
Jeff MitchellOP•2y ago
Right, which is /health_check...I entered that in the settings.
Jeff Mitchell
Jeff MitchellOP•2y ago
angelo
angelo•2y ago
APP_APPLICATION__BASE_URL and set that to ${{ RAILWAY_STATIC_URL }} You need to template the string
Jeff Mitchell
Jeff MitchellOP•2y ago
Got it...trying again.
angelo
angelo•2y ago
for the record, this value shouldn't affect healthchecks, so curious to see your config there
Jeff Mitchell
Jeff MitchellOP•2y ago
App didn't need a rebuild, but I'm still getting a failed health check. Maybe I've entered the endpoint wrong.
Jeff Mitchell
Jeff MitchellOP•2y ago
Brody
Brody•2y ago
do you have an endpoint registered at that endpoint? (yes I am bad at English)
angelo
angelo•2y ago
are you serving from /health_check?
Jeff Mitchell
Jeff MitchellOP•2y ago
I think so? If I run the app in dev, and go to that endpoint it returns a 200 OK with no body.
angelo
angelo•2y ago
remove the slash at the start?
Jeff Mitchell
Jeff MitchellOP•2y ago
I'm serving a simple page with a login button from the / route.
angelo
angelo•2y ago
I s2g if it's this
Brody
Brody•2y ago
okay million dollar question, what host and what port is your app currently running on?
Jeff Mitchell
Jeff MitchellOP•2y ago
Don't worry, if it is I'll shoot myself 🙂
angelo
angelo•2y ago
me first also this Can you give me a link to your application?
Jeff Mitchell
Jeff MitchellOP•2y ago
Still failing
angelo
angelo•2y ago
Doing so means I can check your project
Jeff Mitchell
Jeff MitchellOP•2y ago
crusty-rustacean-api-production.up.railway.app Should add that I used the Railway CLI to deploy my docker file.
angelo
angelo•2y ago
just your project url (can you believe I can't easily search via url?) the project ID you gave me doesn't lead anywhere 😢
Brody
Brody•2y ago
👋 that was a service id
angelo
angelo•2y ago
oh wow I can look that up one sec Going to remove the healthcheck- my guess here is that you aren't serving at root...
Brody
Brody•2y ago
I like my guess better
angelo
angelo•2y ago
Jeff, your app builds properly, are you listening on 0.0.0.0?
Jeff Mitchell
Jeff MitchellOP•2y ago
Checking... Looking at the spec.yaml for Digital Ocean, which is irrelevant I know, the app should be using 8000...I'm not sure I specified that anywhere when I deployed via the Railway CLI. Just logged in, did init, then link, then up.
angelo
angelo•2y ago
That can help! Adding a PORT var
Brody
Brody•2y ago
then you'd need to tell railway what port your app is listening on, set a PORT variable to 8000
Jeff Mitchell
Jeff MitchellOP•2y ago
Ok, that must be what I'm missing then. Will look that up in the docs.
Brody
Brody•2y ago
a service variable
angelo
angelo•2y ago
oh wow
angelo
angelo•2y ago
Railway
404 - Page not found
Railway is an infrastructure platform where you can provision infrastructure, develop with that infrastructure locally, and then deploy to the cloud.
angelo
angelo•2y ago
logs is showing your app is panicking on request
angelo
angelo•2y ago
anyway- heres more docs, but I don't think its us https://docs.railway.app/deploy/exposing-your-app
Railway Docs
Exposing Your App | Railway Docs
Documentation for Railway
angelo
angelo•2y ago
when you visit root- something must be happening it seems like it's expecting redis?
Jeff Mitchell
Jeff MitchellOP•2y ago
Ok, that's better! I need to finish the rest of the config then.
angelo
angelo•2y ago
(also sorry for looking at your logs- just wanna help you out here)
Jeff Mitchell
Jeff MitchellOP•2y ago
How did you get those logs? If I'd been able to see that I wouldn't have wasted your time. No worries at all, looking at the logs, it was very helpful.
angelo
angelo•2y ago
Clicking the service Opens the logs view (Not a waste, I learn a lot of from these interactions. Still a lot we can do in terms of education)
Jeff Mitchell
Jeff MitchellOP•2y ago
🙂 Noobie noobs like me must drive you guys crazy.
angelo
angelo•2y ago
Only Brody
Jeff Mitchell
Jeff MitchellOP•2y ago
Anyways, thanks so much, the PORT is up there now, and you've helped me out tremendously. BTW, love that the Railway CLI is written in Rust 🙂 All good now, thanks again guys. Postgres is hooked up, solved the Redis panic (was a typo in how I'd defined the environment variable).
Want results from more Discord servers?
Add your server