Skip to content

Commit 83f9be9

Browse files
ianmacartneyConvex, Inc.
authored andcommitted
update fly.io self-hosting docs (#34141)
Updating fly.io docs GitOrigin-RevId: 942dbde3e67e2564200c4cf48570c7c28de638c5
1 parent 039cad4 commit 83f9be9

File tree

1 file changed

+102
-30
lines changed

1 file changed

+102
-30
lines changed

self-hosted/SELFHOSTING.md

Lines changed: 102 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ Community support is available for self-hosted Convex in the `#open-source`
1818
channel in the [Convex Discord](https://discord.gg/convex).
1919

2020
Development of the Convex backend is led by the Convex team. We
21-
[welcome bug fixes](./CONTRIBUTING.md) and
22-
[love receiving feedback](https://discord.gg/convex). We keep this repository
23-
synced with any internal development work within a handful of days.
21+
[welcome bug fixes](https://github.com/get-convex/convex-backend/blob/main/crates/convex/CONTRIBUTING.md)
22+
and [love receiving feedback](https://discord.gg/convex). We keep this
23+
repository synced with any internal development work within a handful of days.
2424

2525
# Self Hosting Via Docker
2626

@@ -35,6 +35,8 @@ docker compose pull
3535
docker compose up
3636
```
3737

38+
Note: if you see permissions issues, try `docker logout ghcr.io`.
39+
3840
Once your Convex backend is running in Docker, you can ask it to generate admin
3941
keys for use from the dashboard/CLI.
4042

@@ -81,14 +83,39 @@ connect to Postgres.
8183

8284
# Self Hosting with [Fly.io](https://fly.io/)
8385

84-
From the self-hosted directory, deploy the backend.
86+
## Setup
87+
88+
Copy the
89+
[`self-hosted` files](https://github.com/get-convex/convex-backend/tree/main/self-hosted)
90+
to your local machine. You don't need to copy it into your project directory,
91+
but you can.
8592

8693
```sh
87-
fly launch
94+
npx degit get-convex/convex-backend/self-hosted ./self-hosted
95+
cd self-hosted
8896
```
8997

90-
Note the URL of the app that gets printed out, which will be of the form
91-
`https://<app-name>.fly.dev` (no trailing slash).
98+
Note: `degit` is a tool for copying files from git repositories.
99+
100+
## Deploying the backend to Fly.io
101+
102+
The backend "deploy" can mean two things:
103+
104+
1. Deploying the Convex docker image to Fly.io.
105+
2. Deploying your app's Convex functions to the fly machine running Convex.
106+
107+
Steps:
108+
109+
1. Deploy the backend to Fly.io.
110+
111+
```sh
112+
fly launch
113+
```
114+
115+
Future deployments can be done with `fly deploy`.
116+
117+
2. Note the URL of the app that gets printed out, which will be of the form
118+
`https://<app-name>.fly.dev` (no trailing slash).
92119

93120
In the fly.toml file, change the env variables `CONVEX_CLOUD_ORIGIN` and
94121
`CONVEX_SITE_ORIGIN` to:
@@ -105,41 +132,58 @@ fly deploy
105132
```
106133

107134
Copy and paste the fly url to set `NEXT_PUBLIC_DEPLOYMENT_URL` in the
108-
dashboard/fly.toml file.
135+
dashboard/fly.toml file. 3. Generate an admin key.
109136

110137
```sh
111-
cd dashboard
112-
fly launch
138+
fly ssh console --app self-hosted-backend --command "./generate_admin_key.sh"
113139
```
114140

115-
Visit the dashboard at the url output from the fly deploy command. Generate
116-
admin key to login to the dashboard.
141+
Unless you edited the app's `fly.toml`, the name is `self-hosted-backend`. If
142+
you specified a different name, replace `self-hosted-backend` with it.
117143

118-
```sh
119-
fly ssh console --command "./generate_admin_key.sh"
120-
```
144+
This admin key will be used to authorize the CLI and access the dashboard.
121145

122-
In your frontend app directory
146+
4. Inside your app, create a `.env.local` file with the following variables:
123147

124-
```sh
125-
npm install convex@alpha
126-
```
148+
```sh
149+
CONVEX_SELF_HOST_URL='<url-to-your-fly-backend>'
150+
CONVEX_SELF_HOST_ADMIN_KEY='<your-admin-key>'
151+
```
127152

128-
Write these environment variables to .env.local
153+
5. To deploy your Convex functions to the backend, you'll use the `convex` CLI.
129154

130-
```sh
131-
CONVEX_SELF_HOST_URL='<NEXT_PUBLIC_DEPLOYMENT_URL>'
132-
CONVEX_SELF_HOST_ADMIN_KEY='<your-admin-key>'
133-
```
155+
In your frontend app directory, install `convex`.
134156

135-
Push your Convex functions
157+
```sh
158+
npm install convex@alpha
159+
```
136160

137-
```sh
138-
npx convex self-host dev
139-
```
161+
To continuously deploy code for development:
162+
163+
```sh
164+
npx convex self-host dev
165+
```
166+
167+
This will continuously deploy your functions as you edit them. It will also
168+
set environment variables for your frontend, like`VITE_CONVEX_URL`. If you
169+
only want to deploy once, run `npx convex self-host dev --once`.
170+
171+
To deploy code once, e.g. for production:
140172

141-
Visit the dashboard - you should see your functions and be able to edit data,
142-
run functions, etc.
173+
```sh
174+
npx convex self-host deploy --env-file <path to env file>
175+
```
176+
177+
If you don't want to ues a path, call it with the env variables set. It will
178+
not read any .env file by default.
179+
180+
**Note:** It's up to you whether a backend is for development or production.
181+
There is no distinction within the instance. If you only have one backend,
182+
you can run `npx convex self-host dev` or `npx convex self-host deploy`
183+
depending on whether you want it to live-update or not.
184+
185+
An extension of this is that you can have many backends for staging or
186+
previews. The difference will be in the environment variables.
143187

144188
### HTTP Actions
145189

@@ -150,6 +194,34 @@ example:
150194
- And you have an HTTP action named `/sendEmail`
151195
- You would call it at `https://self-hosted-backend.fly.dev/http/sendEmail`
152196

197+
## Deploying the dashboard to Fly.io
198+
199+
The dashboard allows you to see logs, read/write data, run functions, and more.
200+
You can run the dashboard locally (see [SELFHOSTING.md](SELFHOSTING.md)), or
201+
also deploy it to Fly.io.
202+
203+
1. Go into the dashboard directory where you copied the self-hosted files.
204+
205+
```sh
206+
cd self-hosted/dashboard
207+
```
208+
209+
2. Update `NEXT_PUBLIC_DEPLOYMENT_URL` in the dashboard/fly.toml file to the url
210+
of your fly-hosted backend, if you haven't already.
211+
212+
3. Deploy the dashboard to Fly.io.
213+
214+
```sh
215+
fly launch
216+
```
217+
218+
You should now be able to visit the dashboard at the url output by fly.
219+
220+
4. Visit the dashboard and enter the admin key. To log in, it will need the
221+
admin key you generated earlier.
222+
223+
You should see your tables, see and run functions, etc.
224+
153225
# Self Hosting on Postgres with [Neon](https://neon.tech)
154226

155227
Create a project on Neon. Copy the connection string from the Neon dashboard.

0 commit comments

Comments
 (0)