Render YAML hostname with url scheme

Ability to create full URL scheme from hostname in render YAML
It appears that the render YAML specification does not allow for specifying a URL scheme on any environment variables with hostname. The example below uses the hostport property to add a REDIS_URL environment variable and sets it to the hostname. However the hostname will only be “example-redis:1234” and will not have a URL schema prefix such as “redis://example-redis:1234” this causes applications assuming a full URL prefix to not work.

Obviously this can be fixed in the application itself by adding the prefix to the ENV variables but services such as Heroku and Rails conform to general standard that the ENV variable will have a full URL schema. So migrating like I am from Heroku to Render requires application development that is specific to the render platform.

Environment Variables in dashboard vs render YAML
This also creates another problem when trying to manually change the env variable to add the prefix in the render dashboard. This works, however when a new deployment is triggered and the render YAML is synced the prefixed version is overwritten by the render YAML file and causes the service to obviously fail.

Would love to see how you guys could handle ensuring environment variables could have prefixes or full URL schemes in the YAML specification. It would be great to have some warning or preference when we edit an environment variable that is actually specified in the YAML file the given service is synced to!

- type: worker
  name: british_community_sidekiq
  env: ruby
  region: frankfurt
  numInstances: 1
  buildCommand: "bundle install"
  startCommand: "bundle exec sidekiq -c 3 -q default -q mailers"
  envVars:
    - key: REDIS_URL
      fromService:
        name: british-community-redis-queue
        type: pserv
        property: hostport
1 Like

Hi @sammovale ,

Thanks for the detailed feedback! Having the specific examples and motivations is really helpful.

I checked out our internal issue tracker, and found that we’ve already agreed these are important changes to make. I added your feedback, and have asked the team to re-evaluate when we might schedule working on them. I don’t think we’ll be able to change the hostport format in the short term, unfortunately, so you will still need a workaround.

No worries Dan! Glad I could help! Look forward to these changes. I will just remove my env variable from the render.yml file for now so it isnt overwriting the edited version with the “redis://” prefix.

Here’s an alternative solution if you don’t want to hardcode your Redis URL:

Set REDIS_HOSTPORT in your render.yaml file:

  - key: REDIS_HOSTPORT
    fromService:
      type: pserv
      name: foobar-redis
      property: hostport

Then, in your build script set REDIS_URL like so:

export REDIS_URL="redis://${REDIS_HOSTPORT}"

Your app now has access to a REDIS_URL variable with the URI scheme.

One caveat to keep in mind is that REDIS_URL is not set automatically when you open a Rails console for example. So you’ll need to re-run the above code before opening a console.

@dan Have you considered adding a new url property rather than replacing the existing hostport one? That seems like a relatively straightforward fix.

Not a bad idea, thanks for the suggestion! Unfortunately I will need to use the rails console from time to time and having to rerun that code all the time beforehand seems cumbersome.

@dan Okay my bad, I just realized we set up Redis as a private service. So when exposing a url property you don’t really know which scheme to use. It could be any kind of service.

1 Like

Another workaround option similar to @marc’s suggestion is to add the following to config/application.rb. Note that this is specific to Rails.

ENV['REDIS_URL'] = "redis://#{ENV['REDIS_HOSTPORT']}"

You could also make this environment-specific by overriding it in one of the files in config/environments.

This depends on you setting the REDIS_HOSTPORT env var in your render.yaml similar to this

  - key: REDIS_HOSTPORT
    fromService:
      type: pserv
      name: foobar-redis
      property: hostport

I think this will allow the REDIS_URL to be set properly both in production and in rails console.