Do i need to set client env vars every deploy?
when i deploy an update to fly do i need to set the client env vars again? every deploy
9 Replies
Hi @Sven. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
Yes, you need to set client environment variables every time you deploy an update to Fly.io. This is because client environment variables are embedded into the client code during the build process, not at runtime.
Here's why and how to do it:
1. Client env vars are embedded during build: As explained in the Wasp docs on env vars (https://wasp-lang.dev/docs/project/env-vars#defining-env-vars-in-production), client environment variables are embedded into the client code during the build and shipping process.
2. Set them before building: You need to provide these variables to the build command. For example:
3. For Fly.io deployments: When using
wasp deploy fly deploy
, you can set the client env vars like this:
This was confirmed to work in a Discord support thread (https://discord.com/channels/686873244791210014/1220070515276775516).
4. Every deploy: Since these variables are embedded during the build process, you need to set them every time you deploy an update. They are not persisted between deployments in the same way server environment variables are.
Remember, client environment variables are public and readable by anyone, so never store secrets in them. For sensitive information, use server environment variables instead.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
Sorry @Sven, 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?The short answer is "yes".
You can put the deployment commend into the
package.json
script as deploy
so you can run it with npm run deploy
and you can then always run the correct command.Ohh ye
Would this github action work?
Claude says Value: Your Google Analytics ID (e.g., G-1234567890)
The workflow will now:
Checkout your code
Create a .env.client file with your Google Analytics ID from GitHub secrets
Deploy using the Wasp deploy action
This way, your analytics ID will be securely stored in GitHub secrets and automatically included during each deployment, without being committed to your repository.
Make sure to add .env.client to your .gitignore file if you haven't already to prevent any local versions from being committed:
(I'll test this a few times and report back)
@miho ah would you mind just sanity checking this? I would image this would work, but I only see it working on my localhost (I see analytics on localhost, but not on my website)
jk solved!
Here's a github action that will work
1. Adding
.env.client
won't do anything since that file is only used in development and not while building your app
2. The second bit sounds more promising to me
Have you tested the env approach? Did it work for you? πYes! This was the issue, I'll remove that part as well from the deployment file, the workflow works and I can see it in Google analytics.
I need to adjust the workflow as well so it doesn't download the newest wasp version as well.
Thanks for your review, and hope I'm giving some good code for others
You are, thanks for the contribution π If you want - you can write a step-by-step instructions in a github gist or smth, we can add it to https://github.com/wasp-lang/learning-materials/
GitHub
GitHub - wasp-lang/learning-materials: A place to collect some usef...
A place to collect some useful learning materials for Wasp - wasp-lang/learning-materials
Definitely, I'm headed on vacation tomorrow, but I will definitely do this, there's so much I've learned.
Wasp is awesome,
Where is you all's by you a coffee link?
We appreciate the kind words π if you want to show your support by buying us a cup of coffee, we have Github Sponsors set up: https://github.com/sponsors/wasp-lang
GitHub
Sponsor @wasp-lang on GitHub Sponsors
Wasp is a Rails-like web app framework for React, Node.js and Prisma.
Develop your app in a day and deploy it with a single CLI command.