Hi! I was hoping for some help on best practices on Monorepo’s for local development.
I saw this message back in April mentioning there would be some work to add docs for mono’s (Monorepo access token setup tedious - #2 by ryan-blunden) but the only search I found was to highlight adding a doppler.yaml in each repo inside the monorepo.
Anyways! What is the best practice for setting DOPPLER_TOKEN when running docker compose in a local environment?
For example, I have a docker-compose.yaml in my root and then directories for my submodules like /apps/api and /apps/web.
I’ve followed the instructions to add an environment variable called DOPPLER_TOKEN to each item in my docker-compose like so:
DOPPLER_TOKEN="$(doppler configs tokens create dev --plain --max-age 1m)" \
docker-compose -f docker-compose.yml up
However, if run from the root of my monorepo, the DOPPLER_TOKEN command cannot find the project to generate a token.
What is the best practice for defining multiple tokens and setting them within the compose? Should I modify the above sequence to define a DOPPLER_TOKEN_API and DOPPLER_TOKEN_WEB so that it creates two different unique tokens for each project and then I can set those env variables correctly in my docker compose?
Having more information and established patterns for using Doppler with Monorepos is something we want to get out, but we’ve been really busy on our end and haven’t managed to get to it yet. Really sorry about that! We do also have some ideas floating around internally on how to improve our support for monorepo setups in general (e.g., modifying doppler.yaml to allow you to specify configuration for subdirectories, so you can just run doppler setup once at the top level) that we hope to implement in the future (no timeline for this yet though unfortunately!).
Yes, you’re on the right path there! Then you could execute doing something like this:
DOPPLER_TOKEN_API="$(doppler configs tokens create --project api --config dev dev --plain --max-age 1m)" \
DOPPLER_TOKEN_WEB="$(doppler configs tokens create --project web --config dev dev --plain --max-age 1m)" \
docker-compose -f docker-compose.yml up
Being as that’s a pretty long execution line – it might be worthwhile to wrap that in a small bash script you store with your project that starts up docker-compose for you with all the appropriate bits mentioned above.
Let me know if you run into more challenges and I’ll see what I can do to help!
I was about to report back with this similar solution, so I think this will suffice for now. I just had to make sure to reference those unique variables in the environment section of the docker compose instead of just passing DOPPLER_TOKEN
Something like:
environment:
- DOPPLER_TOKEN=${DOPPLER_TOKEN_API}
I like the idea of using the doppler yaml to reference sub directories! No worries though, the initial set up just takes a little longer without it (when you happen to have a lot of microservices )
No problem! Glad that’s working for you. If you have any other ideas on how we could make the monorepo experience better, feel free to open up threads on the forum here and I can get those passed on to our Product team.