Skip to content

Commit 7689877

Browse files
committed
more config
1 parent b9b3884 commit 7689877

File tree

2 files changed

+262
-67
lines changed

2 files changed

+262
-67
lines changed

docs/hosting/config_file.md

Lines changed: 213 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ from reflex_image_zoom import image_zoom
44
from pcweb.pages.docs import hosting
55
from pcweb.pages import docs
66
from pcweb.styles.styles import get_code_style, cell_style
7-
87
```
8+
99
## What is reflex cloud config?
1010

1111
The following command:
@@ -16,106 +16,252 @@ reflex cloud config
1616

1717
generates a `cloud.yml` configuration file used to deploy your Reflex app to the Reflex cloud platform. This file tells Reflex how and where to run your app in the cloud.
1818

19+
## Configuration File Structure
20+
21+
The `cloud.yml` file uses YAML format and supports the following structure. **All fields are optional** and will use sensible defaults if not specified:
22+
23+
```yaml
24+
# Basic deployment settings
25+
name: my-app-prod # Optional: defaults to project folder name
26+
description: 'Production deployment' # Optional: empty by default
27+
project: my-client-project # Optional: for organization
28+
29+
# Infrastructure settings
30+
regions: # Optional: defaults to sjc: 1
31+
sjc: 1 # San Jose (primary)
32+
lhr: 2 # London (secondary)
33+
vmtype: c2m2 # Optional: defaults to c1m1
34+
35+
# Custom domain and environment
36+
hostname: myapp.com # Optional: null uses default Reflex URL
37+
envfile: .env.production # Optional: defaults to .env
38+
39+
# Additional dependencies
40+
packages: # Optional: empty by default
41+
- procps
42+
- imagemagick
43+
```
44+
45+
## Configuration Options Reference
46+
47+
```python demo-only
48+
rx.table.root(
49+
rx.table.header(
50+
rx.table.row(
51+
rx.table.column_header_cell(rx.text("Option", size="1", weight="bold", color=rx.color("slate", 11))),
52+
rx.table.column_header_cell(rx.text("Type", size="1", weight="bold", color=rx.color("slate", 11))),
53+
rx.table.column_header_cell(rx.text("Default", size="1", weight="bold", color=rx.color("slate", 11))),
54+
rx.table.column_header_cell(rx.text("Description", size="1", weight="bold", color=rx.color("slate", 11))),
55+
align="center"
56+
)
57+
),
58+
rx.table.body(*[
59+
rx.table.row(
60+
rx.table.cell(rx.text(option, class_name="text-sm")),
61+
rx.table.cell(rx.text(type_, class_name="text-sm")),
62+
rx.table.cell(rx.text(default, class_name="text-sm")),
63+
rx.table.cell(rx.link(description, href=link, class_name="text-sm") if link else rx.text(description, size="1", weight="regular")),
64+
align="center"
65+
) for option, type_, default, description, link in [
66+
("name", "string", "folder name", "Deployment identifier in dashboard", None),
67+
("description", "string", "empty", "Human-readable deployment description", None),
68+
("regions", "object", "sjc: 1", "Region deployment mapping", "/docs/hosting/regions"),
69+
("vmtype", "string", "c1m1", "Virtual machine specifications", "/docs/hosting/machine-types"),
70+
("hostname", "string", "null", "Custom domain configuration", "/docs/hosting/custom-domains"),
71+
("envfile", "string", ".env", "Environment variables file path", "/docs/hosting/secrets-environment-vars"),
72+
("project", "string", "null", "Project organization", None),
73+
("packages", "array", "empty", "Additional system packages", None),
74+
]
75+
]),
76+
variant="ghost",
77+
size="2",
78+
width="100%",
79+
max_width="800px",
80+
)
81+
```
1982

20-
## What does cloud.yml contain?
83+
## Detailed Configuration Options
2184

22-
Here is an example cloud.yml file generated by the command:
85+
### Regions
86+
87+
Available deployment regions with their codes:
88+
89+
- `sjc`: San Jose, California (US West)
90+
- `lhr`: London, United Kingdom (Europe)
91+
- `fra`: Frankfurt, Germany (Europe)
92+
- `syd`: Sydney, Australia (Asia-Pacific)
93+
94+
Specify regions using the format `region: instance_count`:
2395

2496
```yaml
25-
name: default
26-
description: ''
2797
regions:
28-
sjc: 1
29-
lhr: 2
30-
vmtype: c1m1
31-
hostname: null
32-
envfile: .env
33-
project: null
34-
packages:
35-
- procps
98+
sjc: 1 # Primary region with 1 instance
99+
lhr: 2 # Backup region with 2 instances for high availability
36100
```
37101
38-
### Configuration Options Explained
102+
**Use Cases:**
103+
- Single region: Cost-effective for regional applications
104+
- Multi-region: Global applications requiring low latency and redundancy
39105
40-
**name**
41-
- Identifies your deployment in the Reflex Cloud dashboard
42-
- Use descriptive names like `myapp-prod` or `myapp-staging`
106+
### VM Types
43107
44-
**description**
45-
- Optional but helpful for team collaboration
46-
- Document what this deployment is for
108+
Choose the appropriate virtual machine size based on your application needs:
47109
48-
**regions**
49-
- Available regions: `sjc` (San Jose), `lhr` (London), `fra` (Frankfurt), `syd` (Sydney)
50-
- Format: `region: instance_count`
51-
- Use multiple regions for global availability and redundancy
110+
### Custom Domains
52111
53-
**vmtype**
54-
- `c1m1`: 1 CPU, 1GB RAM (development/small apps)
55-
- `c2m2`: 2 CPU, 2GB RAM (production ready)
56-
- `c4m4`: 4 CPU, 4GB RAM (high traffic apps)
57-
- `c8m8`: 8 CPU, 8GB RAM (enterprise apps)
112+
Set `hostname` to use your own domain instead of the default Reflex Cloud URL:
58113

59-
**hostname**
60-
- Leave as `null` for default Reflex Cloud URL
61-
- Set custom domain if you own one
62-
- Requires DNS configuration (see Custom Domains section)
114+
```yaml
115+
hostname: myapp.com
116+
```
63117

64-
**envfile**
65-
- Path to your environment variables file
66-
- Default is `.env` in your project root
67-
- Never commit this file to version control
118+
**Requirements:**
119+
- Domain ownership verification
120+
- DNS configuration (CNAME or A record)
121+
- SSL certificate (handled automatically)
68122

69-
**project**
70-
- Optional: organizes deployments within your account
71-
- Useful for separating client projects or environments
123+
### Environment Variables
72124

73-
**packages**
74-
- Additional packages your app needs
125+
Specify the path to your environment variables file:
75126

76-
### Environment Variables (Optional)
127+
```yaml
128+
envfile: .env.production # Custom environment file
129+
```
77130

78-
If your app uses environment variables, create a `.env` file in your project root:
131+
Example `.env` file structure:
79132

80133
```bash
81-
# Database
134+
82135
DATABASE_URL=postgresql://user:pass@host:port/dbname
83136
84-
# API Keys
85137
OPENAI_API_KEY=your_api_key_here
86138
STRIPE_SECRET_KEY=sk_live_...
87139
88-
# App Configuration
89140
DEBUG=False
90141
SECRET_KEY=your_secret_key_here
142+
```
143+
144+
### Projects
145+
146+
Organize deployments using projects:
147+
148+
```yaml
149+
project: client-alpha # Groups related deployments
150+
```
151+
152+
Projects help separate:
153+
- Different clients or customers
154+
- Development, staging, and production environments
155+
- Team-based application ownership
156+
157+
### Packages
158+
159+
Install additional system packages your application requires:
91160

92-
# Custom Variables
93-
CUSTOM_API_ENDPOINT=https://api.example.com
161+
```yaml
162+
packages:
163+
- procps # Process monitoring tools
164+
- imagemagick # Image processing
165+
- ffmpeg # Media processing
166+
```
167+
168+
## Multiple Configuration Examples
169+
170+
### Minimal Configuration
171+
```yaml
172+
# Uses all defaults - suitable for development
173+
name: my-app-dev
174+
```
175+
176+
### Production Configuration
177+
```yaml
178+
name: myapp-production
179+
description: 'Main production deployment'
180+
regions:
181+
sjc: 2
182+
lhr: 1
183+
vmtype: c4m4
184+
hostname: myapp.com
185+
envfile: .env.production
186+
project: myapp
187+
packages:
188+
- imagemagick
189+
- redis-tools
190+
```
191+
192+
### Multi-Environment Setup
193+
194+
**Development (`cloud-dev.yml`):**
195+
```yaml
196+
name: myapp-dev
197+
description: 'Development environment'
198+
vmtype: c1m1
199+
envfile: .env.development
94200
```
95201

96-
**Security Best Practices:**
97-
- Never commit `.env` to version control
98-
- Use different `.env` files for staging/production
99-
- Rotate secrets regularly
100-
- Use strong, unique values for SECRET_KEY
202+
**Staging (`cloud-staging.yml`):**
203+
```yaml
204+
name: myapp-staging
205+
description: 'Staging environment'
206+
regions:
207+
sjc: 1
208+
vmtype: c2m2
209+
envfile: .env.staging
210+
```
211+
212+
**Production (`cloud-prod.yml`):**
213+
```yaml
214+
name: myapp-production
215+
description: 'Production environment'
216+
regions:
217+
sjc: 2
218+
lhr: 1
219+
vmtype: c4m4
220+
hostname: myapp.com
221+
envfile: .env.production
222+
```
223+
224+
## Using Different Configuration Files
225+
226+
Deploy with specific configuration files:
227+
228+
```bash
229+
# Use default cloud.yml
230+
reflex deploy
231+
232+
# Use specific configuration file
233+
reflex deploy --config cloud-prod.yml
234+
reflex deploy --config cloud-staging.yml
235+
```
236+
237+
## Deployment Workflow
238+
239+
1. **Generate base configuration:**
240+
```bash
241+
reflex cloud config
242+
```
101243

102-
## How to use the cloud.yml
244+
2. **Customize the `cloud.yml` file** based on your requirements using the options above
103245

104-
1. Run reflex cloud config to generate the default `cloud.yml` file.
105-
2. Open `cloud.yml` and customize the keys to fit your app and deployment preferences.
106-
3. Ensure your .env file (or specified envfile) contains the necessary environment variables for your app.
107-
4. Deploy your app using Reflex cloud commands (e.g., reflex deploy).
246+
3. **Create environment file** (if needed):
247+
```bash
248+
touch .env
249+
# Add your environment variables
250+
```
108251

109-
## Where to find values for keys?
252+
4. **Deploy your application:**
253+
```bash
254+
reflex deploy
255+
```
110256

111-
- `regions`: Check Reflex cloud documentation or dashboard for region codes and availability.
112-
- `vmtype`: Check Reflex cloud VM size options to pick the right balance of CPU/memory.
113-
- `hostname`: Use your own domain name if you want a custom URL, or leave as null for default URLs.
114-
- `project`: Your Reflex cloud account projects — find them on the Reflex dashboard.
115-
- `packages`: Add any extra packages your app requires to run.
257+
5. **Monitor deployment** through the (Reflex Cloud)[https://cloud.reflex.dev/] dashboard
116258

117259
## Summary
118260

119-
Reflex Cloud provides a streamlined deployment experience for Python web applications. The `cloud.yml` configuration file gives you control over your deployment while maintaining simplicity. Start with basic configurations and scale up as your application grows.
261+
The `cloud.yml` configuration provides complete control over your Reflex Cloud deployments while maintaining simplicity. All configuration options are optional, allowing you to start with minimal setup and gradually add complexity as your application scales.
120262

121-
For production applications, consider implementing proper monitoring, backup strategies, and CI/CD pipelines to ensure reliable deployments.
263+
Key takeaways:
264+
- Start with basic configuration and expand as needed
265+
- Use multiple configuration files for different environments
266+
- Leverage regions for global availability and redundancy
267+
- Secure environment variables and never commit them to version control

pcweb/flexdown.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,54 @@ def render(self, env) -> rx.Component:
279279
),
280280
)
281281

282+
class DemoOnly(flexdown.blocks.Block):
283+
"""A block that displays only a component demo without showing the code."""
284+
285+
starting_indicator = "```python demo-only"
286+
ending_indicator = "```"
287+
include_indicators = True
288+
theme: str = None
289+
290+
def render(self, env) -> rx.Component:
291+
lines = self.get_lines(env)
292+
code = "\n".join(lines[1:-1])
293+
294+
args = lines[0].removeprefix(self.starting_indicator).split()
295+
296+
exec_mode = env.get("__exec", False)
297+
comp = ""
298+
299+
for arg in args:
300+
if arg.startswith("id="):
301+
comp_id = arg.rsplit("id=")[-1]
302+
break
303+
else:
304+
comp_id = None
305+
306+
if "exec" in args:
307+
env["__xd"].exec(code, env, self.filename)
308+
if not exec_mode:
309+
comp = env[list(env.keys())[-1]]()
310+
elif "graphing" in args:
311+
env["__xd"].exec(code, env, self.filename)
312+
if not exec_mode:
313+
comp = env[list(env.keys())[-1]]()
314+
# Get all the code before the final "def".
315+
parts = code.rpartition("def")
316+
data, code = parts[0], parts[1] + parts[2]
317+
comp = docgraphing(code, comp=comp, data=data)
318+
return comp
319+
elif exec_mode:
320+
return comp
321+
elif "box" in args:
322+
comp = eval(code, env, env)
323+
return rx.box(comp, margin_bottom="1em", id=comp_id)
324+
else:
325+
comp = eval(code, env, env)
326+
327+
# Return only the component without any code display
328+
return rx.box(comp, margin_bottom="1em", id=comp_id)
329+
282330

283331
class DemoBlock(flexdown.blocks.Block):
284332
"""A block that displays a component along with its code."""
@@ -543,6 +591,7 @@ def render(self, env) -> rx.Component:
543591

544592
xd = flexdown.Flexdown(
545593
block_types=[
594+
DemoOnly,
546595
DemoBlock,
547596
AlertBlock,
548597
DefinitionBlock,

0 commit comments

Comments
 (0)