deployment-docs

Flask and MongoDB (MS3) : Environment variables

To provide secret keys and some further required configuration details, environment variables are added to the service.


During the development process you may have used an env.py file which contained sensitive information. For the application to perform correctly, this information is required in the production environment. When deploying to Heroku, you probably converted that file to a set of config vars.

You may have access to your env.py file in a pinned workspace, but not necessarily. Luckily, Render provides a couple of ways to give your application access to these details without exposing them to the public.

Individual Variables

This allows the addition of individual environment variables.

This would be a good place for development and debug variables when needed.

Secret File

This file will be available ‘behind the scenes’, it is not accessible to the public so the security and secrecy of its content are maintained.

This also acts as a nice backup location of production environment variables should a Gitpod workspace be lost without another external backup of the env.py file.

Process

❌ NO access to env.py

If you do not have access to a copy of your env.py file, please follow the steps below. If you do have access, please skip ahead.

  1. Scroll down and click “Advanced

    Advanced button

  2. Click “Add Environment Variable

    add environment variable button

  3. Open a new browser tab and navigate to your Heroku dashboard and open the Settings tab of your existing app

    settings tab selected

  4. Click “Reveal Config Vars

    reveal config vars button

  5. Copy each config var key and value from Heroku to a new Environment Variable on Render

    Key Value
    IP 0.0.0.0
    PORT 5000
    SECRET_KEY <your secret key>
    MONGO_URI <your Mongo URI>
    MONGO_DBNAME <your MongoDB name>

    a list of environment variables with keys in the left input box and values in the right input box

The IP and PORT variables are used within the Flask application and should not be modified.


✅ Access to env.py

If you have access to a copy of your env.py file, please follow the steps below

  1. Copy the content of your existing env.py file to your clipboard

    an env.py file with all of its contents highlighted for copying

  2. Scroll down and click “Advanced

    Advanced button

  3. Click “Add Secret File

    add secret file button

  4. Paste in the copied text to the File contents text area input and ensure the Filename is env.py

    an example secret file with file name in the upper input and the file contents in lower input

Make sure to click "Save" when done.

Up Next

The final option is whether to Auto-Deploy. The two options are explained in the following page.