Environment variables in a monorepo project
Hello,
I’m working with a monorepo project containing workspaces based in pnpm, because all the apps need the full workspace to be available to be able to build I have to use the folder containing the root of the workspace as the source.root for each application.
I’ve been trying to expose values in the PLATFORM_RELATIONSHIPS variable in the deploy hook by doing the following but this does not seem to work.
export REDIS_URL=redis://$(echo $PLATFORM_RELATIONSHIPS | base64 --decode | jq -r ".redis[0].host")
I kept reading the docs and found information about creating a .environment file in the source.root directory but because the apps have the same source root I’m not sure how to make sure that it only sets environment variables for the current app, I think that I could use an if to check the PLATFORM_APPLICATION_NAME variable to only set environments for the current app but it would be better if I could somehow include it in the applications.yml file or somehow have a separate .environment file for each application.
Thanks for any help!
Comments
Hi there!
I believe if 1) every application’s
source.rootis set to the root directory and 2) you commit a.environmentfile at root, every application will have access to thatREDIS_URLvariable.Your method of using a check for
PLATFORM_APPLICATION_NAMEin.environmentshould work though for this purpose. In the end, it’s probably the simplest way.Placing it in
.environmentis the easiest way to ensure that the variable is available atdeploy,post_deploy,command.start, and during SSH sessions. You could define it explicitly inapplications.yamlfor the app that actually needs access to it, but you would need to repeat the export statement at each of the stages I’ve listed above, and then it still wouldn’t be accessible by default when you SSH into that app container.Please sign in to leave a comment.