DopplerHQ / cli

The official CLI for interacting with your Doppler secrets and configuration.
https://docs.doppler.com
Apache License 2.0
221 stars 44 forks source link

[BUG] Race condition in `doppler setup` when applying settings in more than one project #403

Open gregdan3 opened 1 year ago

gregdan3 commented 1 year ago

Describe the bug If you run doppler setup in two or more projects at once, they will open the user's doppler config ~/.doppler/.doppler.yaml at the same time and apply their changes to the same copy of the file, resulting in only one of the changes applying. This might occur if the user batches changes across several projects with doppler setup --no-interactive.

To Reproduce

  1. Set up two or more directories with a doppler.yaml
  2. Execute the following in the parent directory of those two:
    parallel "cd {} && doppler setup --no-interactive --debug" ::: *
  3. Check doppler configure in any of the projects, observing that one of the projects has a project and config in its configure, but the others do not
  4. Check ~/.doppler/.doppler.yaml to confirm the same

Example of this occurring:

~/example ❯ parallel "cd {} && doppler setup --no-interactive --debug" ::: *
Auto-selecting project from repo config file
Auto-selecting config from repo config file
┌─────────┬────────┬──────────────────────────────────┐
│ NAME    │ VALUE  │ SCOPE                            │
├─────────┼────────┼──────────────────────────────────┤
│ config  │ prd    │ /home/gregdan3/example/project_2 │
│ project │ common │ /home/gregdan3/example/project_2 │
└─────────┴────────┴──────────────────────────────────┘
Debug: Using config dir /home/gregdan3/.doppler
Debug: Using config file /home/gregdan3/.doppler/.doppler.yaml
Debug: Reading config file
Debug: Reading repo config file doppler.yaml
Debug: Sending anonymous analytics payload: '{"command":"doppler.setup"}'
Debug: Performing HTTP POST to https://cli.doppler.com/v1/analytics
Debug: Writing user config to /home/gregdan3/.doppler/.doppler.yaml
Debug: Writing to temp file /home/gregdan3/.doppler/.doppler.yaml.Q5xDAKWw
Debug: Renaming temp file to /home/gregdan3/.doppler/.doppler.yaml
Auto-selecting project from repo config file
Auto-selecting config from repo config file
┌─────────┬────────┬──────────────────────────────────┐
│ NAME    │ VALUE  │ SCOPE                            │
├─────────┼────────┼──────────────────────────────────┤
│ config  │ prd    │ /home/gregdan3/example/project_1 │
│ project │ common │ /home/gregdan3/example/project_1 │
└─────────┴────────┴──────────────────────────────────┘
Debug: Using config dir /home/gregdan3/.doppler
Debug: Using config file /home/gregdan3/.doppler/.doppler.yaml
Debug: Reading config file
Debug: Reading repo config file doppler.yaml
Debug: Sending anonymous analytics payload: '{"command":"doppler.setup"}'
Debug: Performing HTTP POST to https://cli.doppler.com/v1/analytics
Debug: Writing user config to /home/gregdan3/.doppler/.doppler.yaml
Debug: Writing to temp file /home/gregdan3/.doppler/.doppler.yaml.5QZbeO6Y
Debug: Renaming temp file to /home/gregdan3/.doppler/.doppler.yaml

Expected behavior Doppler should keep track of a lockfile so the config file can only be read and written to by one process at a time.

Desktop (please complete the following information):

CLI Version: Version v3.60.1

Additional context Feel free to let me know if this a harebrained activity that doesn't need fixing- for the time being we'll be working around this by dispatching setup commands consecutively rather than simultaneously anyway.

watsonian commented 1 year ago

@gregdan3 Thanks for reporting this! We'll take a look at it. In the mean time though, one thing you might consider is taking advantage of the monorepo-friendly setup file format we introduced in #394. Essentially, in your example, you could add a single doppler.yaml file in your /home/gregdan3/example directory. The contents of that file might look something like this:

setup:
  - project: common
    config: prd
    path: project_1/
  - project: common
    config: prd
    path: project_2/

You then just need to run something along the lines of doppler setup --no-interactive from the root directory and it'll setup all the subdirectories you configure in the setup file.

Not a solution for the race condition, but perhaps a better way to accomplish what you're after in the mean time.