|
| 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 | +``` |
0 commit comments