Correct way of using environment variables when deploying via CLI

I've been looking at the documentation and am slightly confused around the way to deploy. I don't know if I'm overthinking it, but according to the docs the server secrets are set like this:
wasp deploy fly cmd secrets set GOOGLE_CLIENT_ID=<...> GOOGLE_CLIENT_SECRET=<...> --context=server
wasp deploy fly cmd secrets set GOOGLE_CLIENT_ID=<...> GOOGLE_CLIENT_SECRET=<...> --context=server
Does that mean you basically go through the .env.server file and add all the variables in one long command?
3 Replies
kapa.ai
kapa.ai•4mo ago
Hi @CamBlackwood. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Yes, you're correct. When deploying your Wasp application using the CLI, you can set the server secrets using the wasp deploy fly cmd secrets set command followed by the environment variables you want to set. This command is used to set environment variables that your server application requires, such as authentication secrets for external services like Google. For example, if you have the following variables in your .env.server file:
DATABASE_URL=postgresql://localhost:5432
GOOGLE_CLIENT_ID=your-google-client-id
GOOGLE_CLIENT_SECRET=your-google-client-secret
DATABASE_URL=postgresql://localhost:5432
GOOGLE_CLIENT_ID=your-google-client-id
GOOGLE_CLIENT_SECRET=your-google-client-secret
You would set these variables using the wasp deploy fly cmd secrets set command like this:
wasp deploy fly cmd secrets set DATABASE_URL=postgresql://localhost:5432 GOOGLE_CLIENT_ID=your-google-client-id GOOGLE_CLIENT_SECRET=your-google-client-secret --context=server
wasp deploy fly cmd secrets set DATABASE_URL=postgresql://localhost:5432 GOOGLE_CLIENT_ID=your-google-client-id GOOGLE_CLIENT_SECRET=your-google-client-secret --context=server
This command sets the DATABASE_URL, GOOGLE_CLIENT_ID, and GOOGLE_CLIENT_SECRET environment variables for your server application. Remember to replace postgresql://localhost:5432, your-google-client-id, and your-google-client-secret with your actual database URL, Google client ID, and Google client secret, respectively. You can confirm that you've added your secrets correctly by running flyctl secrets list in the terminal. Note that you will see hashed versions of your secrets to protect your sensitive data. For more information, you can refer to the Wasp documentation on setting environment variables (https://wasp-lang.dev/docs/advanced/deployment/cli#flyio-regions) and deploying with the Wasp CLI (https://wasp-lang.dev/docs/advanced/deployment/cli#cmd). ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @CamBlackwood, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
miho
miho•4mo ago
Yep, this is the case 😄 Wasp expects your production environemnt to have the env vars there. How you get those env vars there, it really depends on the platform. On Railway you enter them one by one in a GUI. Fly makes it a bit more approachable by allowing you to set them all at once in one long command 😄 Here's my weird local command I use sometimes:
echo $(sed '/^#/d' < .env.server) | tr '\n' ' ' | tr -d "'"
echo $(sed '/^#/d' < .env.server) | tr '\n' ' ' | tr -d "'"
It gives you a string with all the env vars from your .env.server file @CamBlackwood if you don't mind me asking, what would be the best DX for you here?
CamBlackwood
CamBlackwoodOP•4mo ago
Ah makes sense, thanks Miho! I think the best dx would maybe have the command you use built in somehow, or maybe even just add it to the docs for people to use
Want results from more Discord servers?
Add your server