Skip to content
TypeScript
3.8 KB
Raw Blame
---
title: Doppler
description: Load a Doppler config into your Stack — log in with the browser on your machine, use a service token in CI.
---

[Doppler](https://www.doppler.com) organises secrets into projects,
each with configs such as `dev`, `stg`, and `prd`. `Doppler.Secrets`
downloads one config into the stack's
[secret providers](/environments/secret-providers), without writing
anything to `process.env` or to disk. It ships in the
`@alchemy.run/doppler` package.

```typescript
import * as Doppler from "@alchemy.run/doppler";

secrets: [
  Doppler.Secrets(({ stage }) => ({
    project: "my-app",
    config: stage === "prod" ? "prd" : "dev",
  })),
],
```

Browser login and personal tokens are not scoped to a single config,
so `project` and `config` are required with those. A
[service token](https://docs.doppler.com/docs/service-tokens) is
scoped to one config, so both may be omitted. Doppler's
[branch configs](https://docs.doppler.com/docs/branch-configs) map
neatly onto preview stages if `pr-42` should inherit from `dev`.

## Connect your account

Run `alchemy profile edit --add Doppler`. **Login** opens the Doppler
dashboard; approve the request and the token is stored in your
[profile](/environments/profiles). It shows up in Doppler as
`Alchemy (<your hostname>)`, and
`alchemy profile edit --remove Doppler` revokes it. **API token**
takes a service or
[personal token](https://docs.doppler.com/docs/personal-tokens) you
already have. Non-interactively:

```sh
alchemy profile edit --add Doppler --method api-token --set token=env:DOPPLER_TOKEN
```

## In CI

Profiles are never consulted in CI; the environment decides. The
simplest is a service token in `DOPPLER_TOKEN`:

```yaml
- run: bun alchemy deploy --stage prod --yes
  env:
    DOPPLER_TOKEN: ${{ secrets.DOPPLER_TOKEN }}
```

On Doppler's Team and Enterprise plans, use OIDC to avoid storing a
long-lived Doppler token. Create a
[service account identity](https://docs.doppler.com/docs/service-account-identities)
that trusts your platform's OIDC issuer and set `DOPPLER_IDENTITY_ID`;
Alchemy exchanges the platform's own identity token for a short-lived
Doppler token on every run:

```yaml
jobs:
  deploy:
    permissions:
      id-token: write   # lets the job request an OIDC token
      contents: read
    steps:
      - run: bun alchemy deploy --stage prod --yes
        env:
          DOPPLER_IDENTITY_ID: ${{ vars.DOPPLER_IDENTITY_ID }}
```

Alchemy detects GitHub Actions, Vercel, and supported
Google Cloud runtimes. Each platform must be configured to issue a token
whose issuer, subject, and audience match the Doppler identity's trust policy.
Use your job's actual subject claim when configuring that policy; it can
vary with the repository, branch, environment, and organization settings.

For GitLab, name the token in the job's
[`id_tokens`](https://docs.gitlab.com/ci/secrets/id_token_authentication/)
block `DOPPLER_OIDC_TOKEN` and set its `aud` to the audience trusted by
Doppler. `SIGSTORE_ID_TOKEN` is also detected when `GITLAB_CI` is set.
On other platforms, `DOPPLER_OIDC_TOKEN` accepts an explicitly supplied token.

`DOPPLER_OIDC_AUDIENCE` sets the requested audience on GitHub Actions
and Google Cloud. It is required for Google's
[metadata identity endpoint](https://docs.cloud.google.com/docs/authentication/get-id-token).
It does not change the audience of tokens already supplied by Vercel,
GitLab, or `DOPPLER_OIDC_TOKEN`.

`DOPPLER_TOKEN` wins over `DOPPLER_IDENTITY_ID`, and either wins over
a profile, so a teammate can deploy with a token they were handed.
`alchemy provider check-env` lists these variables.

## Where next

- [Secret providers](/environments/secret-providers) — ordering, mixing sources, and per-stage callbacks.
- [Profiles](/environments/profiles) — where the login lives.
- [Doppler docs](https://docs.doppler.com) — projects, configs, and access control.