Skip to content

Commit 393cd64

Browse files
tgberkeleyTom Gotsman
andauthored
Add cloud api docs (#1100)
* first attempt at api docs for cloud * add elements to sidebar and start writing intro * finish additional concepts page * remove old cli commands * final finishes and remove whitelist * final small changes * updates for simon change * add docs for vmtypes and github actions for deploying --------- Co-authored-by: Tom Gotsman <[email protected]>
1 parent b0244c6 commit 393cd64

File tree

11 files changed

+475
-212
lines changed

11 files changed

+475
-212
lines changed

assets/cloud_project_page.png

388 KB
Loading
146 KB
Loading

assets/hosting_tokens.png

154 KB
Loading
Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
1+
```python exec
2+
import reflex as rx
3+
from reflex_image_zoom import image_zoom
4+
from pcweb.pages import docs
5+
from pcweb.styles.styles import get_code_style, cell_style
6+
7+
8+
regions = {
9+
"ams": "Amsterdam, Netherlands",
10+
"arn": "Stockholm, Sweden",
11+
"alt": "Atlanta, Georgia (US)",
12+
"bog": "Bogotá, Colombia",
13+
"bom": "Mumbai, India",
14+
"bos": "Boston, Massachusetts (US)",
15+
"cdg": "Paris, France",
16+
"den": "Denver, Colorado (US)",
17+
"dfw": "Dallas, Texas (US)",
18+
"ewr": "Secaucus, NJ (US)",
19+
"eze": "Ezeiza, Argentina",
20+
"fra": "Frankfurt, Germany",
21+
"gdl": "Guadalajara, Mexico",
22+
"gig": "Rio de Janeiro, Brazil",
23+
"gru": "Sao Paulo, Brazil",
24+
"hkg": "Hong Kong, Hong Kong",
25+
"iad": "Ashburn, Virginia (US)",
26+
"jnb": "Johannesburg, South Africa",
27+
"lax": "Los Angeles, California (US)",
28+
"lhr": "London, United Kingdom",
29+
"mad": "Madrid, Spain",
30+
"mia": "Miami, Florida (US)",
31+
"nrt": "Tokyo, Japan",
32+
"ord": "Chicago, Illinois (US)",
33+
"otp": "Bucharest, Romania",
34+
"phx": "Phoenix, Arizona (US)",
35+
"qro": "Querétaro, Mexico",
36+
"scl": "Santiago, Chile",
37+
"sea": "Seattle, Washington (US)",
38+
"sin": "Singapore, Singapore",
39+
"sjc": "San Jose, California (US)",
40+
"syd": "Sydney, Australia",
41+
"waw": "Warsaw, Poland",
42+
"yul": "Montreal, Canada",
43+
"yyz": "Toronto, Canada"
44+
}
45+
46+
vmtypes = [
47+
{"id": "c1m.5", "name": "Single CPU Small", "cpu_cores": 1, "ram_gb": 0.512},
48+
{"id": "c1m1", "name": "Single CPU Medium", "cpu_cores": 1, "ram_gb": 1.024},
49+
{"id": "c1m2", "name": "Single CPU Large", "cpu_cores": 1, "ram_gb": 2.048},
50+
{"id": "c2m.5", "name": "Double CPU Micro", "cpu_cores": 2, "ram_gb": 0.512},
51+
{"id": "c2m1", "name": "Double CPU Small", "cpu_cores": 2, "ram_gb": 1.024},
52+
{"id": "c2m2", "name": "Double CPU Medium", "cpu_cores": 2, "ram_gb": 2.048},
53+
{"id": "c2m4", "name": "Double CPU Large", "cpu_cores": 2, "ram_gb": 4.096},
54+
{"id": "c4m1", "name": "Quad CPU Micro", "cpu_cores": 4, "ram_gb": 1.024},
55+
{"id": "c4m2", "name": "Quad CPU Small", "cpu_cores": 4, "ram_gb": 2.048},
56+
{"id": "c4m4", "name": "Quad CPU Medium", "cpu_cores": 4, "ram_gb": 4.096},
57+
{"id": "c4m8", "name": "Quad CPU Large", "cpu_cores": 4, "ram_gb": 8.192}
58+
]
59+
60+
```
61+
62+
63+
# Reflex Cloud - Additional Concepts
64+
65+
To go back, i.e. from an app to a project or from a project to your list of projects you just click the `REFLEX logo` in the top left corner of the page.
66+
67+
```md alert info
68+
# All flag values are saved between runs
69+
All your flag values, i.e. environment variables or regions or tokens, are saved between runs. This means that if you run a command and you pass a flag value, the next time you run the same command the flag value will be the same as the last time you ran it. This means you should only set the flag values again if you want to change them.
70+
```
71+
72+
## Environment Variables
73+
74+
75+
Below is an example of how to use an environment variable file. You can pass the `--envfile` flag with the path to the env file. For example:
76+
77+
```bash
78+
reflex deploy --project f88b1574-f101-####-####-5f########## --envfile .env
79+
```
80+
81+
In this example the path to the file is `.env`.
82+
83+
84+
If you prefer to pass the environment variables manually below is deployment command example:
85+
86+
```bash
87+
reflex deploy --project f88b1574-f101-####-####-5f########## --env OPENAI_API_KEY=sk-proj-vD4i9t6U############################
88+
```
89+
90+
They are passed after the `--env` flag as key value pairs.
91+
92+
To pass multiple environment variables, you can repeat the `--env` tag. i.e. `reflex deploy --project f88b1574-f101-####-####-5f########## --env KEY1=VALUE1 --env KEY2=VALUE`. The `--envfile` flag will override any envs set manually.
93+
94+
95+
```md alert info
96+
# More information on Environment Variables
97+
Environment variables are encrypted and safely stored. We recommend that backend API keys or secrets are entered as `envs`. Make sure to enter the `envs` without any quotation marks. We do not show the values of them in any CLI commands, only their names (or keys).
98+
99+
You access the values of `envs` by referencing `os.environ` with their names as keys in your app's backend. For example, if you set an env `ASYNC_DB_URL`, you are able to access it by `os.environ["ASYNC_DB_URL"]`. Some Python libraries automatically look for certain environment variables. For example, `OPENAI_API_KEY` for the `openai` python client. The `boto3` client credentials can be configured by setting `AWS_ACCESS_KEY_ID`,`AWS_SECRET_ACCESS_KEY`. This information is typically available in the documentation of the Python packages you use.
100+
```
101+
102+
## Adding Team Members
103+
104+
If you are a User you have the ability to create, deploy and delete apps, but you do not have the power to add or delete users from that project. You must be an Admin for that.
105+
106+
As an Admin you will see the an `Add user` button in the top right of the screen, as shown in the image below. Clicking on this will allow you to add a user to the project. You will need to enter the email address of the user you wish to add.
107+
108+
```python eval
109+
image_zoom(rx.image(src="/hosting_adding_team_members.png", alt="Adding team members to Reflex Cloud"))
110+
```
111+
112+
```python eval
113+
rx.box(height="20px")
114+
```
115+
116+
```md alert warning
117+
# Currently a User must already have logged in once before they can be added to a project.
118+
At this time a User must be logged in to be added to a project. In future there will be automatic email invites sent to add new users who have never logged in before.
119+
```
120+
121+
122+
123+
124+
125+
## Tokens
126+
127+
A token gives someone else all the permissions you have as a User or an Admin. They can run any Reflex Cloud command from the CLI as if they are you using the `--token` flag. A good use case would be for GitHub actions (you store this token in the secrets).
128+
129+
Tokens are found on the Project List page. If you cannot find it click the Reflex Logo in the top left side of the page until it appears as in the image below.
130+
131+
```python eval
132+
image_zoom(rx.image(src="/hosting_tokens.png", alt="Adding tokens to Reflex Cloud"))
133+
```
134+
135+
136+
## VMTypes
137+
138+
To get all the possible VMTypes you can run the following command:
139+
140+
```bash
141+
reflex apps vmtypes
142+
```
143+
144+
To set which VMType to use when deploying your app you can pass the `--vmtype` flag with the id of the VMType. For example:
145+
146+
```bash
147+
reflex deploy --project f88b1574-f101-####-####-5f########## --vmtype c2m4
148+
```
149+
150+
This will deploy your app with the `c2m4` VMType, giving your app 2 cpu cores and 4 gb of ram.
151+
152+
Below is a table of all the possible VMTypes:
153+
154+
```python eval
155+
rx.table.root(
156+
rx.table.header(
157+
rx.table.row(
158+
rx.table.column_header_cell("id"),
159+
rx.table.column_header_cell("name"),
160+
rx.table.column_header_cell("cpu (cores)"),
161+
rx.table.column_header_cell("ram (gb)"),
162+
),
163+
),
164+
rx.table.body(
165+
*[
166+
rx.table.row(
167+
rx.table.cell(rx.code(vmtype["id"], style=get_code_style("violet"))),
168+
rx.table.cell(vmtype["name"], style=cell_style),
169+
rx.table.cell(vmtype["cpu_cores"], style=cell_style),
170+
rx.table.cell(vmtype["ram_gb"], style=cell_style),
171+
)
172+
for vmtype in vmtypes
173+
]
174+
),
175+
variant="surface",
176+
)
177+
```
178+
179+
## Regions
180+
181+
Below is an example of how to deploy your app in several regions:
182+
183+
```bash
184+
reflex deploy --project f88b1574-f101-####-####-5f########## --region sjc --region iad
185+
```
186+
187+
By default all apps are deloyed in `sjc` if no other regions are given. If you wish to deploy in another region or several regions you can pass the `--region` flag (`-r` also works) with the region code. Check out all the regions that we can deploy to below:
188+
189+
190+
```python eval
191+
rx.table.root(
192+
rx.table.header(
193+
rx.table.row(
194+
rx.table.column_header_cell("Region Code"),
195+
rx.table.column_header_cell("Region"),
196+
),
197+
),
198+
rx.table.body(
199+
*[
200+
rx.table.row(
201+
rx.table.cell(rx.code(region_code, style=get_code_style("violet"))),
202+
rx.table.cell(region_name, style=cell_style),
203+
)
204+
for region_code, region_name in regions.items()
205+
]
206+
),
207+
variant="surface",
208+
)
209+
```

docs/hosting/deploy-quick-start.md

Lines changed: 28 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
# Reflex Hosting Service
1+
# Reflex Cloud - Quick Start
22

33
```python exec
44
import reflex as rx
5-
from pcweb import constants
5+
from reflex_image_zoom import image_zoom
66
from pcweb.pages import docs
7-
from pcweb.templates.docpage import doccmdoutput
87
```
98

109
So far, we have been running our apps locally on our own machines.
@@ -17,70 +16,59 @@ Reflex’s hosting service makes it easy to deploy your apps without worrying ab
1716

1817
### Prerequisites
1918

20-
1. Hosting service requires `reflex>=0.6.5`.
19+
1. Hosting service requires `reflex>=0.6.6`.
2120
2. This tutorial assumes you have successfully `reflex init` and `reflex run` your app.
22-
3. Also make sure you have a `requirements.txt` file at the top level app directory that contains all your python dependencies!
21+
3. Also make sure you have a `requirements.txt` file at the top level app directory that contains all your python dependencies! (To create a `requirements.txt` file, run `pip freeze > requirements.txt`.)
22+
2323

2424
### Authentication
2525

26-
First, create an account or log into it using the following command.
26+
First run the command below to login / signup to your Reflex Cloud account: (command line)
2727

2828
```bash
2929
reflex login
3030
```
3131

3232
You will be redirected to your browser where you can authenticate through Github or Gmail.
3333

34+
### Web UI
35+
36+
Once you are at this URL and you have successfully authenticated, click on the one project you have in your workspace. You should get a screen like this:
37+
38+
```python eval
39+
image_zoom(rx.image(src="/cloud_project_page.png", alt="Reflex Cloud Dashboard"))
40+
```
41+
42+
This screen shows the login command and the deploy command. As we are already logged in, we can skip the login command.
43+
3444
### Deployment
3545

36-
Once you have successfully authenticated, you can start deploying your apps.
46+
Now you can start deploying your app.
3747

38-
Navigate to the project directory that you want to deploy and type the following command:
48+
In your cloud UI copy the `reflex deploy` command similar to the one shown below.
3949

4050
```bash
41-
reflex deploy
51+
reflex deploy --project 2a432b8f-2605-4753-####-####0cd1####
4252
```
4353

44-
The command is by default interactive. It asks you a few questions for information required for the deployment.
45-
46-
**Name**: choose a name for the deployed app. This name will be part of the deployed app URL, i.e. `<app-name>-randomword-randomword.reflex.run`.
54+
In your project directory (where you would normally run `reflex run`) paste this command.
4755

48-
The name should only contain domain name safe characters: no slashes, no underscores.
56+
The command is by default interactive. It asks you a few questions for information required for the deployment.
4957

50-
```md alert info
51-
# Custom domains are available for paid plans.
52-
```
5358

54-
**Regions**: enter the region code here or press `Enter` to accept the default. The default code `sjc` stands for San Jose, California in the US west coast. Check the list of supported regions at [reflex deployments regions](#reflex-deployments-regions).
59+
1. The first question will compare your `requirements.txt` to your python environment and if they are different then it will ask you if you want to update your `requirements.txt` or to continue with the current one. If they are identical this queston will not appear. To create a `requirements.txt` file, run `pip freeze > requirements.txt`.
60+
2. The second question will search for a deployed app with the name of your current app, if it does not find one then it will ask if you wish to proceed in deploying your new app.
61+
3. The third question is optional and will ask you for an app description.
5562

56-
**Envs**: `Envs` are environment variables. You might not have used them at all in your app. In that case, press `Enter` to skip. More on the environment variables in the later section [Environment Variables](#environment-variables).
5763

5864
That’s it! You should receive some feedback on the progress of your deployment and in a few minutes your app should be up. 🎉
5965

6066
```md alert info
61-
# The hosting service does not currently handle database or file upload operations. Set up an external database and use it within your app.
67+
# Once your code is uploaded, the hosting service will start the deployment. After a complete upload, exiting from the command **does not** affect the deployment process. The command prints a message when you can safely close it without affecting the deployment.
6268
```
6369

64-
## See it in Action
70+
If you go back to the Cloud UI you should be able to see your deployed app and other useful app information.
71+
72+
6573

66-
Below is a video of deploying the [AI chat app]({docs.getting_started.chatapp_tutorial.path}) to our hosting service.
6774

68-
```python eval
69-
rx.box(
70-
rx.el.iframe(
71-
src="https://www.loom.com/embed/bee928924a454a8098e741e1d19b2857?sid=38523a3f-4c7d-4ee2-9a51-4ca1a36828dc",
72-
frameborder="0",
73-
webkitallowfullscreen=True,
74-
mozallowfullscreen=True,
75-
allowfullscreen=True,
76-
position="absolute",
77-
top="0",
78-
left="0",
79-
width="100%",
80-
height="100%",
81-
),
82-
position="relative",
83-
padding_bottom="64.94708994708994%",
84-
height="0",
85-
)
86-
```

0 commit comments

Comments
 (0)