Skip to content

Commit ca05252

Browse files
emmaling27Convex, Inc.
authored andcommitted
Move fly instructions and config files to a subdirectory (#34157)
Tried to keep this change to just moving files + updating paths so it's easier to read the diffs for the docs updates later. GitOrigin-RevId: 3da8671afd0c2207f2459b3ae5f0f3d1ae3b83b0
1 parent 83f9be9 commit ca05252

File tree

4 files changed

+139
-138
lines changed

4 files changed

+139
-138
lines changed

self-hosted/SELFHOSTING.md renamed to self-hosted/README.md

Lines changed: 1 addition & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -83,144 +83,7 @@ connect to Postgres.
8383

8484
# Self Hosting with [Fly.io](https://fly.io/)
8585

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.
92-
93-
```sh
94-
npx degit get-convex/convex-backend/self-hosted ./self-hosted
95-
cd self-hosted
96-
```
97-
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).
119-
120-
In the fly.toml file, change the env variables `CONVEX_CLOUD_ORIGIN` and
121-
`CONVEX_SITE_ORIGIN` to:
122-
123-
```sh
124-
CONVEX_CLOUD_ORIGIN="<fly app url>"
125-
CONVEX_SITE_ORIGIN="<fly app url>/http"
126-
```
127-
128-
And re-deploy to pick up the changes.
129-
130-
```sh
131-
fly deploy
132-
```
133-
134-
Copy and paste the fly url to set `NEXT_PUBLIC_DEPLOYMENT_URL` in the
135-
dashboard/fly.toml file. 3. Generate an admin key.
136-
137-
```sh
138-
fly ssh console --app self-hosted-backend --command "./generate_admin_key.sh"
139-
```
140-
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.
143-
144-
This admin key will be used to authorize the CLI and access the dashboard.
145-
146-
4. Inside your app, create a `.env.local` file with the following variables:
147-
148-
```sh
149-
CONVEX_SELF_HOST_URL='<url-to-your-fly-backend>'
150-
CONVEX_SELF_HOST_ADMIN_KEY='<your-admin-key>'
151-
```
152-
153-
5. To deploy your Convex functions to the backend, you'll use the `convex` CLI.
154-
155-
In your frontend app directory, install `convex`.
156-
157-
```sh
158-
npm install convex@alpha
159-
```
160-
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:
172-
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.
187-
188-
### HTTP Actions
189-
190-
Note that HTTP actions run on your fly app url under the `/http` path. For
191-
example:
192-
193-
- If your fly app is deployed at `https://self-hosted-backend.fly.dev`
194-
- And you have an HTTP action named `/sendEmail`
195-
- You would call it at `https://self-hosted-backend.fly.dev/http/sendEmail`
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.
86+
See the [Fly instructions](./fly/README.md)
22487

22588
# Self Hosting on Postgres with [Neon](https://neon.tech)
22689

self-hosted/fly/README.md

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
# Self Hosting with [Fly.io](https://fly.io/)
2+
3+
## Setup
4+
5+
Copy the
6+
[`fly` files](https://github.com/get-convex/convex-backend/tree/main/self-hosted/fly)
7+
to your local machine. You don't need to copy it into your project directory,
8+
but you can. `degit` is a tool for copying files from git repositories.
9+
10+
```sh
11+
npx degit get-convex/convex-backend/self-hosted/fly fly
12+
cd fly
13+
```
14+
15+
## Deploying the backend to Fly.io
16+
17+
The backend "deploy" can mean two things:
18+
19+
1. Deploying the Convex docker image to Fly.io.
20+
2. Deploying your app's Convex functions to the fly machine running Convex.
21+
22+
Steps:
23+
24+
1. Deploy the backend to Fly.io.
25+
26+
```sh
27+
cd backend
28+
fly launch
29+
```
30+
31+
Future deployments can be done with `fly deploy`.
32+
33+
2. Note the URL of the app that gets printed out, which will be of the form
34+
`https://<app-name>.fly.dev` (no trailing slash).
35+
36+
In the fly.toml file, change the env variables `CONVEX_CLOUD_ORIGIN` and
37+
`CONVEX_SITE_ORIGIN` to:
38+
39+
```sh
40+
CONVEX_CLOUD_ORIGIN="<fly app url>"
41+
CONVEX_SITE_ORIGIN="<fly app url>/http"
42+
```
43+
44+
And re-deploy to pick up the changes.
45+
46+
```sh
47+
fly deploy
48+
```
49+
50+
Copy and paste the fly url to set `NEXT_PUBLIC_DEPLOYMENT_URL` in the
51+
dashboard/fly.toml file.
52+
53+
3. Generate an admin key.
54+
55+
```sh
56+
fly ssh console --app <app-name> -hosted-backend --command "./generate_admin_key.sh"
57+
```
58+
59+
This admin key will be used to authorize the CLI and access the dashboard.
60+
61+
4. Inside your app, create a `.env.local` file with the following variables:
62+
63+
```sh
64+
CONVEX_SELF_HOST_URL='<url-to-your-fly-backend>'
65+
CONVEX_SELF_HOST_ADMIN_KEY='<your-admin-key>'
66+
```
67+
68+
5. To deploy your Convex functions to the backend, you'll use the `convex` CLI.
69+
70+
In your frontend app directory, install `convex`.
71+
72+
```sh
73+
npm install convex@alpha
74+
```
75+
76+
To continuously deploy code for development:
77+
78+
```sh
79+
npx convex self-host dev
80+
```
81+
82+
This will continuously deploy your functions as you edit them. It will also
83+
set environment variables for your frontend, like`VITE_CONVEX_URL`. If you
84+
only want to deploy once, run `npx convex self-host dev --once`.
85+
86+
To deploy code once, e.g. for production:
87+
88+
```sh
89+
npx convex self-host deploy --env-file <path to env file>
90+
```
91+
92+
If you don't want to ues a path, call it with the env variables set. It will
93+
not read any .env file by default.
94+
95+
**Note:** It's up to you whether a backend is for development or production.
96+
There is no distinction within the instance. If you only have one backend,
97+
you can run `npx convex self-host dev` or `npx convex self-host deploy`
98+
depending on whether you want it to live-update or not.
99+
100+
An extension of this is that you can have many backends for staging or
101+
previews. The difference will be in the environment variables.
102+
103+
### HTTP Actions
104+
105+
Note that HTTP actions run on your fly app url under the `/http` path. For
106+
example:
107+
108+
- If your fly app is deployed at `https://self-hosted-backend.fly.dev`
109+
- And you have an HTTP action named `/sendEmail`
110+
- You would call it at `https://self-hosted-backend.fly.dev/http/sendEmail`
111+
112+
## Deploying the dashboard to Fly.io
113+
114+
The dashboard allows you to see logs, read/write data, run functions, and more.
115+
You can run the dashboard locally (see [SELFHOSTING.md](SELFHOSTING.md)), or
116+
also deploy it to Fly.io.
117+
118+
1. Go into the dashboard directory where you copied the self-hosted files.
119+
120+
```sh
121+
cd dashboard
122+
```
123+
124+
2. Update `NEXT_PUBLIC_DEPLOYMENT_URL` in the dashboard/fly.toml file to the url
125+
of your fly-hosted backend, if you haven't already.
126+
127+
3. Deploy the dashboard to Fly.io.
128+
129+
```sh
130+
fly launch
131+
```
132+
133+
You should now be able to visit the dashboard at the url output by fly.
134+
135+
4. Visit the dashboard and enter the admin key. To log in, it will need the
136+
admin key you generated earlier.
137+
138+
You should see your tables, see and run functions, etc.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)