bug: variable persistence
calvinbrewer
PROOP

2 years ago

Through the project/environment/service UI I was manually configuring Variables. The interface picked up the change and prompted me to trigger a manual deployment. The application, during runtime, was not picking up the defined environment varibales.

I installed the CLI and validated the Variables were "undefined"

After some fiddling around, I opened the "Manual edit" modal which was displaying an empty Variable set. After closing the modal, and reopening it the Variables were defined.

I then retried the CLI command and the Variables were defined, triggered a deployment, and all was working as expected.

23 Replies

calvinbrewer
PROOP

2 years ago

Actually, the production deployment is still reporting the environment variables as undefined. Not sure how to proceed


calvinbrewer
PROOP

2 years ago

The build definition also indicated the environment variables are defined, however, these are not being picked up at run time.


calvinbrewer
PROOP

2 years ago

Unable to get this working. I did notice to build step for nix-env is cached. I don't know enough about nix but this is blocking deployments :(


calvinbrewer
PROOP

2 years ago

It's worth noting that I'm using turbo pack and a bun runtime in my application. Bun does read environment variables differently than Node


2 years ago

Hey, there's nothing in these logs that would indicate that a variable isn't available, I'm seeing a "ECONNREFUSED: Failed to connect" error.


calvinbrewer
PROOP

2 years ago

Howdy - the error in the logs is from our database connection process which uses process.env.DB_URL

console.log(
  '[DEBUG] This DB_URL_TEST should be defined:',
  process.env.DB_URL_TEST,
)
const client = postgres(process.env.DB_URL)

I've added a debug statement to the app, to demonstrate the issue in the logs without exposing our secrets.

Dev

> railway run bun run start:api

...
[DEBUG] This DB_URL_TEST should be defined: postgresql://postgres:password@localhost:5432/postgres
...

Production

> bun run start:api

...
[DEBUG] This DB_URL_TEST should be defined: undefined
...

I've validated the variable is defined in the details of the build.


2 years ago

Are both these commands being ran locally?


calvinbrewer
PROOP

2 years ago

The second command is the start script used, for I'm assuming, the Dockerfile entrypoint in Railway. The debug output I'm capturing from the "Deploy Logs" panel


2 years ago

I would need to look into how you setup your Railway project in order to tell you if something was missconfigured in your Railway project or your code.


calvinbrewer
PROOP

2 years ago

What info do I need to provide? I've attached the "Deploy log" but happy to provide any information to help!

Attachments


calvinbrewer
PROOP

2 years ago

What info do I need to provide? I've attached the "Deploy log" but happy to provide any information to help!


calvinbrewer
PROOP

2 years ago

I'd be happy to hop on a call if that's more effective use of time


2 years ago

I'm sorry but we arent able to offer that level of support to Hobby at this time.


2 years ago

Yep you have the variable defined in your service and have deployed the changes.

Meaning this is a code issue, to help you debug this further I would need a minimal reproduceable example


calvinbrewer
PROOP

2 years ago

I'm happy to upgrade to Pro if we can get this sorted as I'm evaluating a few different services for running our production APIs


2 years ago

That wont be necessary at this time, are you able to provide a minimal reproducible example?


calvinbrewer
PROOP

2 years ago

Sure thing - let me put an app together real quick and I'll publish to a public Github repo


calvinbrewer
PROOP

2 years ago

I was able to replicate the issue with using this example application: https://github.com/ByteSliceHQ/turbo-bun-app

In the Varibale definitions set:

TEST_ENV=world

2 years ago

Thank you, I will look into this when I'm at my computer.



calvinbrewer
PROOP

2 years ago

Completely missed that configuration! Specifying the env in the start script did the trick. Thanks for working through that with me rocket emoji

"start": {
  "cache": false,
  "persistent": true,
  "env": ["TEST_ENV"]
}

calvinbrewer
PROOP

2 years ago

I'm a bit confused why it works when running turbo locally, but in the Railway runtime it behaves differently. I'll look into that (as I'm sure it's a global turbo configuration locally or something) and repost here for future people, but for now you've unblocked me. Cheers


2 years ago

Yeah global config or it's ran in loose mode locally.


Loading...