@@ -18,9 +18,9 @@ Community support is available for self-hosted Convex in the `#open-source`
18
18
channel in the [ Convex Discord] ( https://discord.gg/convex ) .
19
19
20
20
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.
24
24
25
25
# Self Hosting Via Docker
26
26
@@ -35,6 +35,8 @@ docker compose pull
35
35
docker compose up
36
36
```
37
37
38
+ Note: if you see permissions issues, try ` docker logout ghcr.io ` .
39
+
38
40
Once your Convex backend is running in Docker, you can ask it to generate admin
39
41
keys for use from the dashboard/CLI.
40
42
@@ -81,14 +83,39 @@ connect to Postgres.
81
83
82
84
# Self Hosting with [ Fly.io] ( https://fly.io/ )
83
85
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.
85
92
86
93
``` sh
87
- fly launch
94
+ npx degit get-convex/convex-backend/self-hosted ./self-hosted
95
+ cd self-hosted
88
96
```
89
97
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).
92
119
93
120
In the fly.toml file, change the env variables ` CONVEX_CLOUD_ORIGIN ` and
94
121
` CONVEX_SITE_ORIGIN ` to:
@@ -105,41 +132,58 @@ fly deploy
105
132
```
106
133
107
134
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.
109
136
110
137
``` sh
111
- cd dashboard
112
- fly launch
138
+ fly ssh console --app self-hosted-backend --command " ./generate_admin_key.sh"
113
139
```
114
140
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 .
117
143
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.
121
145
122
- In your frontend app directory
146
+ 4 . Inside your app, create a ` .env.local ` file with the following variables:
123
147
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
+ ```
127
152
128
- Write these environment variables to .env.local
153
+ 5 . To deploy your Convex functions to the backend, you'll use the ` convex ` CLI.
129
154
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 ` .
134
156
135
- Push your Convex functions
157
+ ``` sh
158
+ npm install convex@alpha
159
+ ```
136
160
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:
140
172
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.
143
187
144
188
### HTTP Actions
145
189
@@ -150,6 +194,34 @@ example:
150
194
- And you have an HTTP action named ` /sendEmail `
151
195
- You would call it at ` https://self-hosted-backend.fly.dev/http/sendEmail `
152
196
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
+
153
225
# Self Hosting on Postgres with [ Neon] ( https://neon.tech )
154
226
155
227
Create a project on Neon. Copy the connection string from the Neon dashboard.
0 commit comments