web/docs/guides/deployment/cloud-providers/flyio.md
import AddExternalAuthEnvVarsReminder from './_addExternalAuthEnvVarsReminder.md' import { SecretGeneratorBlock } from '../../../project/SecretGeneratorBlock' import { Server, Client, Database } from '../DeploymentTag'
We recommend that you use Wasp Deploy to deploy your Wasp app to Fly.io. Wasp CLI automates deploying the client, the server and the database with one command.
This guide shows you how to deploy your Wasp app's server and provision a database on Fly.io.
To get started, follow these steps:
You can check if you are logged in with fly auth whoami, and if you are not, you can log in with fly auth login.
:::info You need to do this only once per Wasp app. :::
Unless you already have a Fly.io app that you want to deploy to, let's create a new Fly.io app.
After you have built the app, position yourself in .wasp/out/ directory:
cd .wasp/out
Next, run the launch command to set up a new app and create a fly.toml file:
fly launch --remote-only
This will ask you a series of questions, such as asking you to choose a region and whether you'd like a database.
Say yes to Would you like to set up a PostgreSQL database now? and select Development. Fly.io will set a DATABASE_URL for you.
Say no to Would you like to deploy now? (and to any additional questions).
We still need to set up several environment variables.
:::info What if the database setup fails?
If your attempts to initiate a new app fail for whatever reason, then you should run fly apps destroy <app-name> before trying again. Fly does not allow you to create multiple apps with the same name.
:::
Next, let's copy the fly.toml file up to our Wasp project dir for safekeeping.
cp fly.toml ../../
Next, add a few more environment variables for the server code.
fly secrets set PORT=8080
fly secrets set JWT_SECRET=<random_string_at_least_32_characters_long>
fly secrets set WASP_WEB_CLIENT_URL=<url_of_where_client_will_be_deployed>
fly secrets set WASP_SERVER_URL=<url_of_where_server_will_be_deployed>
We can help you generate a JWT_SECRET:
<SecretGeneratorBlock />
:::note
If you do not know what your client URL is yet, don't worry. You can set WASP_WEB_CLIENT_URL after you deploy your client.
:::
If you want to make sure you've added your secrets correctly, run fly secrets list in the terminal. Note that you will see hashed versions of your secrets to protect your sensitive data.
While still in the .wasp/out/ directory, run:
fly deploy --remote-only --config ../../fly.toml
This will build and deploy the backend of your Wasp app on Fly.io to https://<app-name>.fly.dev 🤘🎸
Now, if you haven't, you can deploy your client and add the client URL by running fly secrets set WASP_WEB_CLIENT_URL=<url_of_deployed_client>. We suggest using Netlify for your client, but you can use any static hosting provider.
Additionally, some useful fly commands:
fly logs
fly secrets list
fly ssh console
When you rebuild your Wasp app (with wasp build), it will remove your .wasp/out/ directory. In there, you may have a fly.toml from any prior Fly.io deployments.
While we will improve this process in the future, in the meantime, you have a few options:
fly.toml file to a versioned directory, like your Wasp project dir.From there, you can reference it in fly deploy --config <path> commands, like above.
fly.toml file somewhere before running wasp build, and copy it into .wasp/out/ after.When the fly.toml file exists in .wasp/out/ dir, you do not need to specify the --config <path>.
fly config save -a <app-name> to regenerate the fly.toml file from the remote state stored in Fly.io.