So in Nx monorepo all commands happen at the root. I’ve already configured every app with the correct doppler project using doppler.yaml (if I cd into one of the apps in my monorepo and type doppler secrets
correct secrets are fetched). But all of the doesn’t matter because the commands like nx run-many --target serve --all
happen at the root and not within the project scope, so doppler fails to recognize that apps are actually running and does not inject the secrets.
Any one got Nx executors and commands to work with doppler?
Hi @zestsystem!
Welcome to the Doppler Community!
There are a couple things you could potentially do here, but both of them involve modifying the command
for your targets in your project.json
files to explicitly use the Doppler CLI.
First, you could hardcode the project and config in the command itself:
{
"name": "example",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "packages/example/src",
"projectType": "library",
"targets": {
...
"serve": {
"command": "doppler run -p example -c dev -- YOUR_SERVE_COMMAND_HERE"
},
...
},
"tags": []
}
The next option is similar, but relies on the doppler.yaml
setup. All it does is changes directories before running the command:
{
"name": "example",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "packages/example/src",
"projectType": "library",
"targets": {
...
"serve": {
"command": "cd packages/example && doppler run -- YOUR_SERVE_COMMAND_HERE"
},
...
},
"tags": []
}
I’ll caveat this by stating I haven’t done any development using Nx before, so there could be nuances here I’m not aware of that could cause problems, but in my basic testing both of those worked.
Let me know if this accomplishes what you’re after!
Regards,
-Joel
Thank you for the prompt response!!!
For the server I ended up using the nx:run-commands executor in my project.json like this. “dev” is the new script and “serve” was what I was using before. I was hoping to find a way to inject a script into an executor, but had no luck.
{
"name": "server",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "apps/server/src",
"projectType": "application",
"targets": {
...
"serve": {
"executor": "@nx/js:node",
"defaultConfiguration": "development",
"options": {
"buildTarget": "server:build"
},
"configurations": {
"development": {
"buildTarget": "server:build:development"
},
"production": {
"buildTarget": "server:build:production"
}
}
},
"dev": {
"executor": "nx:run-commands",
"options": {
"cwd": "apps/server",
"command": "doppler run -- ts-node-dev --transpile-only --no-notify --exit-child --respawn -r tsconfig-paths/register src/main.ts"
}
},
...
"tags": []
}
For next.js I was able to use your first solution like this (what I did for server doesnt work).
{
"name": "website",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "apps/website",
"projectType": "application",
"targets": {
...
"dev": {
"executor": "nx:run-commands",
"options": {
"command": "doppler run -p website -c dev -- npx nx serve website"
}
},
"serve": {
"executor": "@nx/next:server",
"defaultConfiguration": "development",
"options": {
"buildTarget": "website:build",
"dev": true
},
"configurations": {
"development": {
"buildTarget": "website:build:development",
"dev": true
},
"production": {
"buildTarget": "website:build:production",
"dev": false
}
}
},
...
"tags": []
}
1 Like