Doppler Setup on Ubuntu 22.04 Gunicorn Nginx FastApi

HI, I am trying to start using doppler.

I have a fastapi application that is run via gunicorn and served via nginx.

Currently I restart my application via:

$ sudo systemctl daemon-reload
$ sudo systemctl restart gunicorn
$ sudo systemctl status gunicorn

With doppler i tried the same but adding doppler run – in front, however, it does not work as my application cannot access the secrets.

If I run $ doppler run --command=“echo $SECRET_NAME” then I also get the secrets echoed.

What should I do to make the application work?

Any suggestions?

Thanks so much.

Manfred

Hi @manfred_beluga!

Welcome to the Doppler Community!

Could you post the systemd unitfile you’re using to gunicorn? Without seeing that exactly, the main thing I can think of is that you might not be setting a DOPPLER_TOKEN in the EnvironmentFile for the unitfile. You would need that set to a service token. Then if you executed gunicorn using doppler run -- ... then it should load everything into the environment. From there, based on what I’ve gathered around FastAPI applications, you’d access them in your application by doing something like this:

from fastapi import FastAPI
from pydantic import BaseSettings, Field, SecretStr

class Settings(BaseSettings):
    # Field required since case-insensitive match wasn't possible
    project: str = Field(..., env="DOPPLER_PROJECT")
    # Field required since case-insensitive match wasn't possible
    config: str = Field(..., env="DOPPLER_CONFIG")
    # matches DB_URL in Doppler
    db_url: SecretStr
    # matches AUTH in Doppler
    auth: SecretStr

settings = Settings()
app = FastAPI()

@app.get("/")
def read_root():
    return {"Project": settings.project, "Config": settings.config, "Auth": settings.auth}

If you’re already doing something like that, posting your unitfile should be helpful!

Regards,
-Joel