Problem/ Help needed with variable interpolation

I am trying to deploy my docker-based project, which encompasses multiple services (django, postgres, celery, redis, flower). I would like to use my Redis instance with two separate databases.

On my local machine I achieve this via the env vars CELERY_BROKER_URL=redis://redis:6379/1 and CACHE_URL redis://redis:6379/2.

For deployment on render, I tried the following in my render.yaml file

    - key: REDIS_URL
      fromService:
        name: redis
        type: redis
        property: connectionString
    - key: CELERY_BROKER_URL
      value: ${REDIS_URL}/1
    - key: CACHE_URL
      value: ${REDIS_URL}/2

However, as I’ve read later in the docs, variable interpolation does not work in render.yaml files yet and a workaround is to write start script that does the variable interpolation.

So I wrote the following redis_setup.sh script:

#!/bin/bash

# Get the Redis URL
BASE_URL=$REDIS_URL

# Create new environment variables with database numbers
export CELERY_BROKER_URL="${BASE_URL}/1"
export CACHE_URL="${BASE_URL}/2"

# Print the environment variables to verify they are set correctly
echo "Environment variables set:"
echo "BASE_URL: $BASE_URL"
echo "CELERY_BROKER_URL: $CELERY_BROKER_URL"
echo "CACHE_URL: $CACHE_URL"

which is then executed by the following startup.sh script:

#!/bin/bash
. /redis_setup.sh
python manage.py migrate
python manage.py collectstatic --noinput
exec gunicorn config.wsgi

which I use in the render.yaml , in the web service in dockerCommand: "/startup.sh"

When I check the logs of my web service after a deployment, I can see the values of CELERY_BROKER_URL and CACHE_URL printed out as expected as interpolated strings but I can’t see them in the “Environment Variables” in the dashboard on Tender nor if I start a shell session and run printenv nor can I access them in any other way.

What am I missing? How can I have Render pick up the two environment variables created in the script?

Many thanks in advance!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.