How do i properly deploy?

I am really stuck at the moment on how to deploy. In the docs there are alot of different pages that say alot. I am not sure what and how to pass through the environment variables i set.... For example the DATABASE_URL i can only set that after i deployed right? also WASP_WEB_CLIENT_URL, this is also known after i deployed right and WASP_SERVER_URL? My main question is what env vars do I need to set before running any command and what after? And what environment variables do I need to set myself with that secrets set or --server-secret ?
30 Replies
kapa.ai
kapa.ai3d ago
Hi @Sven. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Deploying a Wasp app involves several steps, including generating deployable code, deploying the API server (backend), deploying the web client (frontend), and deploying a PostgreSQL database. Here's a general overview of the process: 1. Generating Deployable Code: Run the command wasp build to generate deployable code for the whole app in the .wasp/build/ directory. Note that you'll need to switch to PostgreSQL if you're using SQLite as a database (source (https://wasp-lang.dev/docs/advanced/deployment/manually#deploying-a-wasp-app)). 2. Deploying the API Server (backend): Deploy the Docker image defined in the .wasp/build directory to a hosting provider and ensure the required environment variables are correctly set up. The mechanism for setting these up is specific to each provider. 3. Deploying the web client (frontend): This process will depend on your chosen hosting provider. 4. Deploying a PostgreSQL database: This process will also depend on your chosen hosting provider. Regarding your question about environment variables, here are the ones your server will be looking for: - DATABASE_URL: The URL of the PostgreSQL database your app will use. This is required and should be set after you've set up your database (source (https://wasp-lang.dev/docs/advanced/deployment/manually#environment-variables)). - WASP_WEB_CLIENT_URL: The URL where you plan to deploy your frontend app. This is required and should be set after you've deployed your frontend app (source (https://wasp-lang.dev/docs/advanced/deployment/manually#environment-variables)). - WASP_SERVER_URL: The URL where the server is running. This is required and should be set after you've deployed your server (source (https://wasp-lang.dev/docs/advanced/deployment/manually#environment-variables)). - JWT_SECRET: You only need this environment variable if you're using Wasp's auth features. Set it to a random string at least 32 characters long (source (https://wasp-lang.dev/docs/advanced/deployment/manually#environment-variables)). - PORT: The server's HTTP port number. This is where the server listens for requests (default: 3001). Remember, the way you provide these environment variables depends on where you deploy your Wasp project. For example, if you deploy your project to Fly.io, you can define them using the flyctl CLI tool (source (https://wasp-lang.dev/docs/project/env-vars#defining-env-vars-in-production)). For more detailed instructions on deploying to specific providers, you can check the deployment section (https://wasp-lang.dev/docs/advanced/deployment/manually) of the Wasp docs. ---------------------- 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?
NEROX
NEROX3d ago
How it's going @Sven ?
Sven
Sven3d ago
Still not well But besides that fine
NEROX
NEROX3d ago
Where are you stuck? Where are you deploying?
Sven
Sven3d ago
Fly.io is my choice And im just stuck at not knowing what to do with what env vars Like for example in the client.env there is a google analytics thing do i need to fill this in? Or?
NEROX
NEROX3d ago
You should pass them once deployed (server & client vars) Are you working with the OpenSaaS template?
Sven
Sven3d ago
Yesss All of them? and how? I have all env vars there where initially + 1 server var and + 1 client var <- i defined myseld Now some optional vars i commented out like plausible and google analytics on server side. Or do i need to set them?
NEROX
NEROX3d ago
@kapa.ai Hey! I just deployed my OpenSaaS app on Fly! I need to pass the environment variables (env and server). My server vars are: STRIPE_KEY=sk_test_51 STRIPE_WEBHOOK_SECRET=whsec_05 PLAUSIBLE_API_KEY=_lgs-33 And my client vars are: REACT_APP_STRIPE_CUSTOMER_PORTAL=https://billing.stripe.com/p/login/test_9AQ REACT_APP_GOOGLE_ANALYTICS_ID=G-SM6 I also want to set my WASP_WEB_CLIENT_URL to: https://thisismydomain.com
kapa.ai
kapa.ai3d ago
Let me check the knowledge base for you again. One moment! :books: ---------------------- Great! To set environment variables for your Wasp app deployed on Fly.io, you can use the flyctl CLI tool. For your server environment variables, you can set them using the following commands:
flyctl secrets set STRIPE_KEY=sk_test_51
flyctl secrets set STRIPE_WEBHOOK_SECRET=whsec_05
flyctl secrets set PLAUSIBLE_API_KEY=_lgs-33
flyctl secrets set STRIPE_KEY=sk_test_51
flyctl secrets set STRIPE_WEBHOOK_SECRET=whsec_05
flyctl secrets set PLAUSIBLE_API_KEY=_lgs-33
For your client environment variables, you should provide them to the build command. However, remember that client environment variables are embedded into the client code during the build and shipping process, making them public and readable by anyone. Therefore, you should never store secrets in them. Here's an example of how you can provide them:
REACT_APP_STRIPE_CUSTOMER_PORTAL=<https://billing.stripe.com/p/login/test_9AQ> REACT_APP_GOOGLE_ANALYTICS_ID=G-SM6 npm run build
REACT_APP_STRIPE_CUSTOMER_PORTAL=<https://billing.stripe.com/p/login/test_9AQ> REACT_APP_GOOGLE_ANALYTICS_ID=G-SM6 npm run build
Finally, to set your WASP_WEB_CLIENT_URL, you can use the flyctl CLI tool again:
flyctl secrets set WASP_WEB_CLIENT_URL=<https://thisismydomain.com>
flyctl secrets set WASP_WEB_CLIENT_URL=<https://thisismydomain.com>
Remember, these environment variables are read from the server code using process.env.VAR_NAME and from the client code using import.meta.env.VAR_NAME (source (https://wasp-lang.dev/docs/project/env-vars)). For more details on how to define environment variables for each deployment option, you can check the deployment section (https://wasp-lang.dev/docs/advanced/deployment/manually) of the Wasp docs. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @NEROX, 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?
NEROX
NEROX3d ago
Here you have some syntax examples :)
Sven
Sven3d ago
Ah okay thanks for them Wait
ENCRYPTION_KEY=xxxx
# For testing, go to https://dashboard.stripe.com/test/apikeys and get a test stripe key that starts with "sk_test_..."

STRIPE_API_KEY=xxx
# After downloading starting the stripe cli (https://stripe.com/docs/stripe-cli) with `stripe listen --forward-to localhost:3001/payments-webhook` it will output your signing secret

STRIPE_WEBHOOK_SECRET=xxxx
# You can find your Stripe customer portal URL in the Stripe Dashboard under the 'Customer Portal' settings.

# STRIPE_CUSTOMER_PORTAL_URL=xxxs7
STRIPE_CUSTOMER_PORTAL_URL=xxxx


# If using Stripe, go to https://dashboard.stripe.com/test/products and click on + Add Product
# If using Lemon Squeezy, go to https://app.lemonsqueezy.com/products and create new products and variants
PAYMENTS_START_SUBSCRIPTION_PLAN_ID=xx
PAYMENTS_BOOST_SUBSCRIPTION_PLAN_ID=xxx
PAYMENTS_MAX_10_PLAN_ID=xxx



ADMIN_EMAILS[email protected]

# see our guide for setting up google auth: https://wasp-lang.dev/docs/auth/social-auth/google
GOOGLE_CLIENT_ID=722...
GOOGLE_CLIENT_SECRET=GOC...

# get your sendgrid api key at https://app.sendgrid.com/settings/api_keys
SENDGRID_API_KEY=xxxx

# (OPTIONAL) get your openai api key at https://platform.openai.com/account

# (OPTIONAL) get your plausible api key at https://plausible.io/login or

# (OPTIONAL) get your google service account key at
# (OPTIONAL) get your aws s3 credentials at https://console.aws.amazon.com and
ENCRYPTION_KEY=xxxx
# For testing, go to https://dashboard.stripe.com/test/apikeys and get a test stripe key that starts with "sk_test_..."

STRIPE_API_KEY=xxx
# After downloading starting the stripe cli (https://stripe.com/docs/stripe-cli) with `stripe listen --forward-to localhost:3001/payments-webhook` it will output your signing secret

STRIPE_WEBHOOK_SECRET=xxxx
# You can find your Stripe customer portal URL in the Stripe Dashboard under the 'Customer Portal' settings.

# STRIPE_CUSTOMER_PORTAL_URL=xxxs7
STRIPE_CUSTOMER_PORTAL_URL=xxxx


# If using Stripe, go to https://dashboard.stripe.com/test/products and click on + Add Product
# If using Lemon Squeezy, go to https://app.lemonsqueezy.com/products and create new products and variants
PAYMENTS_START_SUBSCRIPTION_PLAN_ID=xx
PAYMENTS_BOOST_SUBSCRIPTION_PLAN_ID=xxx
PAYMENTS_MAX_10_PLAN_ID=xxx



ADMIN_EMAILS[email protected]

# see our guide for setting up google auth: https://wasp-lang.dev/docs/auth/social-auth/google
GOOGLE_CLIENT_ID=722...
GOOGLE_CLIENT_SECRET=GOC...

# get your sendgrid api key at https://app.sendgrid.com/settings/api_keys
SENDGRID_API_KEY=xxxx

# (OPTIONAL) get your openai api key at https://platform.openai.com/account

# (OPTIONAL) get your plausible api key at https://plausible.io/login or

# (OPTIONAL) get your google service account key at
# (OPTIONAL) get your aws s3 credentials at https://console.aws.amazon.com and
# All client-side env vars must start with REACT_APP_ https://wasp-lang.dev/docs/project/env-vars

# See https://docs.opensaas.sh/guides/analytics/#google-analytics
REACT_APP_GOOGLE_ANALYTICS_ID=G-...
REACT_APP_EXTENSION_ID=xxxx
# All client-side env vars must start with REACT_APP_ https://wasp-lang.dev/docs/project/env-vars

# See https://docs.opensaas.sh/guides/analytics/#google-analytics
REACT_APP_GOOGLE_ANALYTICS_ID=G-...
REACT_APP_EXTENSION_ID=xxxx
These are my env vars. I dont use Google auth so i left client_id and client_secret for them as it is. same for this client var REACT_APP_GOOGLE_ANALYTICS_ID also shouldn't REACT_APP_STRIPE_CUSTOMER_PORTAL be a server var?
NEROX
NEROX3d ago
In this case taking into account your .env.server, the command would look like this: flyctl secrets set ENCRYPTION_KEY=xxxx STRIPE_API_KEY=xxx STRIPE_WEBHOOK_SECRET=xxxx etc... Start with flyctl secrets set and start adding the vars to the comand The Stripe user portal variable is a client variable as it is used to take the user to the payment portal.
Sven
Sven3d ago
ah okay and after deployment? hmm in testing it is a server var? How do you know this? and is this a problem too? like did i set all neseccary env vars?
NEROX
NEROX3d ago
Yes No, just remember that in main.wasp there should be the Google Auth lines commented out
Sven
Sven3d ago
yeah i did thanks
Sven
Sven3d ago
for this you said, in the test section it says it is a server var. Why in deployment does it become a client var? How could i know this?
No description
NEROX
NEROX3d ago
ok, did you test if the payments, manage subscription, cancel, etc... worked locally? Have you been able to subscribe and then access the Stripe customer portal and test that you can cancel?
Sven
Sven3d ago
Yeah i did I could access the manage subscription page Through my app
NEROX
NEROX3d ago
Then my mistake, passing it also as flyctl secrets set STRIPE_CUSTOMER_PORTAL_URL=XXX I just remembered that was from an earlier version of OpenSaaS:sadboi:
Sven
Sven3d ago
Ahh ahah Thanks alot for your help Just to he sure the database url and those other things are set by wasp cli if i deploy though there?
NEROX
NEROX3d ago
Yep, as far as I can see you shouldn't have any problems deploying
Sven
Sven3d ago
Oksy cool And if i deploy where and what logs to check inorder to debug of somtehing doesnt work
NEROX
NEROX3d ago
From the Fly panel. You will see after deploying 3 apps (client, sever and db)
No description
NEROX
NEROX3d ago
And in the left side (inside of any app) you will be able to see both real time logs and a log :)
No description
Sven
Sven2d ago
Thanks alot how can i properly set cient side variables after i deployed. i ran wasp deploy fly launch my-wasp-app mia but i forgot to pass through the 1 client var i have this command deployed server, db and client for me and set the databuse_url,jwt, port , and wasp_server_url for me. SO now i need to add my own server vars and then this client var i forgot? how could i do the client var
NEROX
NEROX2d ago
Regarding the server env vars, you can pass them via the command of flyctl secrets set. Regarding that on client env var, it's a very good question
Vinny (@Wasp)
Vinny (@Wasp)2d ago
Kapa is wrong in this case. Follow the docs instead.
Vinny (@Wasp)
Vinny (@Wasp)2d ago
in the docs we have a section about deploying client-side environment variables: https://docs.opensaas.sh/guides/deploying/#deploying-to-flyio
OpenSaaS.sh
Deploying
Open SaaS is a free, open-source, full-stack SaaS starter kit for React + NodeJS.
No description
Vinny (@Wasp)
Vinny (@Wasp)2d ago
so in this case you'd run REACT_APP_EXAMPLE_VAR=xyz-123 wasp deploy fly deploy
Sven
Sven2d ago
Thanks alot
Want results from more Discord servers?
Add your server