we are big fans of doppler (solves a lot of painful problems). We are currently using the Heroku Integration and we are missing the feature to sync the secrets to the Review App Stage (Review apps are created on PR openings). Its currently only possible to transfer them to an app but not a pipeline (Pipelines | Heroku Dev Center). Pipelines share env vars with multiple apps so that we don’t need to sync them every time we open a PR.
We’re looking at supporting secrets sync for review apps in late Q2, but until then, here is how you could do this programmatically using the Doppler and Heroku CLI (with help from jq).
Note: Just like the Heroku integration, these steps presume you want to only use Doppler for updating review app variables and any variables manually edited in Heroku will get blown away on sync.
I’m going to refer to review app variables as Pipeline Config Vars for the remainder of this post.
To set up:
Create a Dopler config that will contain the Pipeline Config Vars to sync
Create a Doppler Service Token for that config and export the value as the DOPPLER_TOKEN environment variable
Create a Heroku API Key (required in order to set the CI config vars) by running heroku authorizations:create and export the value as the HEROKU_API_KEY environment variable
Install the Heroku API plugin (as the CLI doesn’t natively support Pipeline Config Vars yet) - heroku plugins:install api
Syncing secrets is then a three-step process:
Step 1: Fetch the PIPELINE_ID for the Heroku app (change your-app-name below)
PIPELINE_ID="$(heroku api GET pipelines | jq '.[] | select(.name=="your-app-name")' | jq -r '.id')"
Step 2: Nullify all Pipeline Config Vars
eval heroku api PATCH /pipelines/$PIPELINE_ID/stage/review/config-vars --body "'{$(heroku api GET /pipelines/$PIPELINE_ID/stage/review/config-vars | jq -jr ' . | to_entries[] | "\"\(.key)\":null",","' | sed 's/.$//')}'"
Hey @BradRyan and welcome to the Doppler Community!
It looks like we don’t have Deploy Preview secrets sync natively supported in our current Netlify integration so I’ll flag this with our engineering team and work on a documented solution for you that I should have done by later today.
I’m not a Netlify expert so can you help me understand the difference between Netlify Preview environment variables and the standard build environment variables?
For our company workflow we have a production deployment built from our main/master branch, and then we have “preview deployments” which are essentially deployments for each PR that gets opened against the main branch (this is the same idea as Heroku’s pipelines).
The production app references production environment variables, where we have the preview deployments reference environment variables for our staging environment. This means when we do things like QA or run automated tests against the preview deployments, we aren’t accidentally modifying data from our production database.
Currently, Doppler only allows me to sync one environment to Netlify, which are by default used for both production and preview deployments. I would like to have a means to tell preview deployments to reference staging environment variables and the main branch deploys to reference production environment variables.
Does that clarify things? Let me know if I can try to provide more context or examples of specific things.
Unfortunately, Netlify doesn’t make it possible to support syncing multiple environments as environment variable overrides are only possible if hard-coded into netlify.toml.
This means if you need multiple deployment contexts with different secrets, you’ll need to not use our integration and use multiple service tokens instead.
Thanks @ryan-blunden I have my builds referencing the proper env variables using this approach. I noticed one small mistake in the docs where you listed [context.deploy-preview.environment] instead of [context.deploy-preview].
Here’s the relevant parts of my netlify.toml for reference. I injected an extra env var that is referenced in the client code.
Head’s up the other gotcha with this approach is that these env variables aren’t exposed to Netlify’s Serverless functions since they aren’t set through their UI. That said, I’m running into some other frustrations unrelated to Doppler on that front but will share if I come up with any clever solutions here…
Thanks for letting me know about the typo, and the gotcha with Netlify functions.
Keep me posted about the frustrations you’re having and any insights you glean along the way and I’ll see what I can do to improve our docs in the meantime.
Hey @ryan-blunden the other feature I was looking for was only triggering a webhook on production environments only. In Netlify, I can create a custom deployment webhook that can trigger builds on a certain branch (master in my case). Since I couldn’t apply the webhook specifically for a given environment on Doppler’s side of things, I created a custom plugin in Netlify.
I figured I’d share in case someone else was curious about doing something similar.
Hey @BradRyan, just letting you know we’ve recently added the ability to customize webhook delivery on a per-environment basis. You can find the new options on the webhooks page for a given project. Hope this helps!
@AlexMuller Yep, that’s right! When creating a sync to Heroku, you have the option to sync to either an App or a Pipeline. If you choose Pipeline, then you get to choose what stage you’re syncing to – either Test or Review. That should sync secrets to where you need them! Let us know if you have any problems.