How do you deploy multiple environment in fly.io like dev, staging and production

I have application built with WASP v15 and deployed to fly.io and I want to have two environment like staging and production
2 Replies
kapa.ai
kapa.ai4d ago
Hi @victor. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- To deploy multiple environments like staging and production for your Wasp v15 application on Fly.io, you can use the Wasp CLI's deployment features along with some Fly.io-specific configurations. Here's how you can approach this: 1. Use different app names for each environment: You can create separate apps for staging and production by using different app names when deploying. For example:
wasp deploy fly launch my-wasp-app-staging mia
wasp deploy fly launch my-wasp-app-production mia

wasp deploy fly launch my-wasp-app-staging mia
wasp deploy fly launch my-wasp-app-production mia

This will create separate apps for staging and production Deploying (https://wasp-lang.dev/docs/advanced/deployment/cli#deploying). 2. Use environment-specific configuration files: After running the setup command, Wasp creates fly-server.toml and fly-client.toml files in your project root. You can maintain separate configuration files for each environment by using the --fly-toml-dir option:
wasp deploy fly setup my-wasp-app-staging mia --fly-toml-dir ./staging
wasp deploy fly setup my-wasp-app-production mia --fly-toml-dir ./production

wasp deploy fly setup my-wasp-app-staging mia --fly-toml-dir ./staging
wasp deploy fly setup my-wasp-app-production mia --fly-toml-dir ./production

This allows you to have different configurations for each environment Setup (https://wasp-lang.dev/docs/advanced/deployment/cli#setup). 3. Set environment-specific variables: You can set different environment variables for each deployment using the secrets set command:
wasp deploy fly cmd secrets set REACT_APP_API_URL=<https://staging-api.example.com> --context=client --app my-wasp-app-staging-client
wasp deploy fly cmd secrets set REACT_APP_API_URL=<https://api.example.com> --context=client --app my-wasp-app-production-client

wasp deploy fly cmd secrets set REACT_APP_API_URL=<https://staging-api.example.com> --context=client --app my-wasp-app-staging-client
wasp deploy fly cmd secrets set REACT_APP_API_URL=<https://api.example.com> --context=client --app my-wasp-app-production-client

This allows you to have different configurations for staging and production Fly.io Regions (https://wasp-lang.dev/docs/advanced/deployment/cli#flyio-regions). 4. Deploy to each environment: When you're ready to deploy, you can use the deploy command with the appropriate configuration:
wasp deploy fly deploy --fly-toml-dir ./staging
wasp deploy fly deploy --fly-toml-dir ./production

wasp deploy fly deploy --fly-toml-dir ./staging
wasp deploy fly deploy --fly-toml-dir ./production

Remember to manage your environment variables carefully, especially for production. You should never store secrets in client-side environment variables Defining Env Vars in Production (https://wasp-lang.dev/docs/project/env-vars#defining-env-vars-in-production). By following these steps, you can maintain separate staging and production environments for your Wasp application on Fly.io. Each environment will have its own configuration, allowing you to test changes in staging before deploying to production. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @victor, 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
miho3d ago
--fly-toml-dir looks like a good option to explore, have you tried doing what the bot suggested?
Want results from more Discord servers?
Add your server