Skip to content

Commit 0b7d3b0

Browse files
committed
env replace
1 parent 18363eb commit 0b7d3b0

File tree

3 files changed

+482
-59
lines changed

3 files changed

+482
-59
lines changed

apps/docs/content/zerops-yaml/specification.mdx

Lines changed: 184 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ export const languages = [
2626
The `zerops.yaml` file is crucial for defining how Zerops should [build and deploy](/features/pipeline) your application.
2727
Add the `zerops.yaml` file to the **root of your repository** and customize it to suit your application's needs.
2828

29+
:::note Parameter Availability
30+
Not all parameters are available for every service type. Most parameters work across different runtime services, but some are specific to certain service types (e.g., documentRoot for webserver services, routing for Static services). This documentation covers zerops.yaml configuration for runtime services.
31+
:::
32+
2933
---
3034

3135
<GroupCards emoji="🙌" heading="Quick Links to Runtime-Specific Guides" items={languages} />
@@ -39,9 +43,7 @@ zerops:
3943
run: ...
4044
```
4145
42-
- The top-level element is always `zerops`.
43-
- `setup` contains the **hostname** of your service (must exist in Zerops).
44-
- Multiple services can be defined in a single `zerops.yaml` (useful for monorepos):
46+
Multiple services can be defined in a single `zerops.yaml` (useful for monorepos):
4547

4648
```yaml
4749
zerops:
@@ -56,7 +58,15 @@ zerops:
5658

5759
Each service configuration requires `build` and `run` sections. An optional `deploy` section can be added for readiness checks.
5860

59-
## Service Inheritance
61+
## Service Configuration
62+
63+
### setup <Badge type="required" />
64+
65+
Contains the hostname of your service (must exist in Zerops).
66+
67+
```yaml
68+
setup: my-service
69+
```
6070

6171
### extends <Badge type="optional" />
6272

@@ -67,26 +77,22 @@ zerops:
6777
- setup: base
6878
build:
6979
buildCommands:
70-
- echo "hello"
71-
deployFiles: ./
80+
- npm run build
81+
deployFiles: ./dist
7282
run:
73-
start: server run
83+
start: npm start
7484
7585
- setup: prod
7686
extends: base
7787
run:
78-
crontab:
79-
- command: xyz
80-
allContainers: false
81-
timing: "* * * * *"
88+
envVariables:
89+
NODE_ENV: production
8290
8391
- setup: dev
8492
extends: base
8593
run:
86-
crontab:
87-
- command: different command
88-
allContainers: false
89-
timing: "* * * * *"
94+
envVariables:
95+
NODE_ENV: development
9096
```
9197

9298
When using `extends`:
@@ -294,10 +300,11 @@ Defines the port number on which your application listens. Must be between *10*
294300
#### protocol <Badge type="optional" />
295301
Specifies the network protocol to use:
296302
- Allowed values: `TCP` *(default)* or `UDP`
303+
297304
#### httpSupport <Badge type="optional" />
298305
Indicates whether the port is running a web server:
299-
- Default value: `true`
300-
- Set to `false` if a web server isn't running on the port
306+
- Default value: `false`
307+
- Set to `true` if a web server is running on the port
301308
- Only available with TCP protocol
302309
- Used by Zerops for [public access](/features/access) configuration
303310

@@ -330,7 +337,7 @@ run:
330337

331338
### startCommands <Badge type="optional" />
332339

333-
Defines start commands
340+
Defines start commands.
334341

335342
Unlike `start`, you can define multiple commands that starts their own processes.
336343

@@ -341,7 +348,6 @@ run:
341348
- command: npm run start:prod
342349
name: server
343350
# start the replication
344-
345351
- command: litestream replicate -config=litestream.yaml
346352
name: replication
347353
# restore the database on container init
@@ -373,6 +379,140 @@ Defines environment variables for the runtime environment.
373379
DB_PASS: ${db_password}
374380
```
375381

382+
### envReplace <Badge type="optional" />
383+
384+
Automatically replaces environment variable placeholders in your static files with their actual values during deployment.
385+
386+
```yaml
387+
run:
388+
envReplace:
389+
delimiter: "%%"
390+
target:
391+
- config/jwt/public.pem
392+
- config/jwt/private.pem
393+
- ./config/
394+
```
395+
396+
Available parameters:
397+
398+
#### delimiter <Badge type="required" />
399+
Characters that wrap your variable names in placeholders (e.g., `%%` means placeholders look like `%%VARIABLE%%`).
400+
- Type: `string` or `array of strings`
401+
- Supports multiple delimiters simultaneously
402+
403+
#### target <Badge type="required" />
404+
Files or directories to process for variable replacement.
405+
- Type: `string` or `array of strings`
406+
- Can be specific files or directories with glob patterns
407+
- **Important**: Directory paths like `./` only process files in that directory, not subdirectories. For recursive processing, specify each subdirectory explicitly
408+
409+
**How it works:**
410+
1. Define placeholders in your files using the specified delimiters
411+
2. Set environment variables with matching names
412+
3. During deployment, Zerops finds and replaces placeholders with actual values
413+
414+
**Example usage:**
415+
416+
```yaml
417+
run:
418+
envReplace:
419+
delimiter: "%%"
420+
target:
421+
- ./config/
422+
- ./templates/
423+
- ./ # Only processes files in root, not subdirectories
424+
```
425+
426+
File content before replacement:
427+
```
428+
# config/jwt/public.pem
429+
%%JWT_PUBLIC_KEY_CONTENT%%
430+
```
431+
432+
Environment variable:
433+
```
434+
JWT_PUBLIC_KEY_CONTENT=-----BEGIN PUBLIC KEY-----
435+
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA...
436+
-----END PUBLIC KEY-----
437+
```
438+
439+
The placeholder gets replaced with the actual JWT public key during deployment.
440+
441+
:::warning
442+
When using `./` as target, only files directly in the root directory are processed. Subdirectories are ignored for performance reasons. To process subdirectories, specify each one explicitly in the target array.
443+
:::
444+
445+
### routing <Badge type="optional" />
446+
447+
Configures URL routing, redirects, and HTTP headers (primarily for Static services).
448+
449+
```yaml
450+
run:
451+
routing:
452+
root: /custom/root
453+
cors: "'*' always"
454+
redirects:
455+
- from: /old-path
456+
to: /new-path
457+
status: 301
458+
headers:
459+
- for: "/*"
460+
values:
461+
X-Frame-Options: "'DENY'"
462+
```
463+
464+
Available parameters:
465+
466+
#### root <Badge type="optional" />
467+
Sets a custom root directory for the service.
468+
- Type: `string`
469+
470+
#### cors <Badge type="optional" />
471+
Enables CORS headers for cross-origin requests.
472+
- Type: `string`
473+
- Sets `Access-Control-Allow-Origin`, `Access-Control-Allow-Methods`, `Access-Control-Allow-Headers`, and `Access-Control-Expose-Headers`
474+
- Special case: `"*"` is automatically converted to `'*'`
475+
476+
#### redirects <Badge type="optional" />
477+
Defines URL redirects and rewrites.
478+
- Type: `array of objects`
479+
- Each redirect object supports:
480+
- **from** <Badge type="required" /> - Source path to match (supports wildcards with `*`)
481+
- **to** <Badge type="required" /> - Destination path
482+
- **status** <Badge type="optional" /> - HTTP status code (required for absolute URLs)
483+
- **preservePath** <Badge type="optional" /> - Preserve path after wildcard match
484+
- **preserveQuery** <Badge type="optional" /> - Preserve query parameters
485+
486+
#### headers <Badge type="optional" />
487+
Sets custom HTTP headers for specific paths.
488+
- Type: `array of objects`
489+
- Each header object supports:
490+
- **for** <Badge type="required" /> - Path pattern to match (supports wildcards)
491+
- **values** <Badge type="required" /> - Object with header name/value pairs
492+
493+
**Example usage:**
494+
495+
```yaml
496+
run:
497+
routing:
498+
cors: "'*' always"
499+
redirects:
500+
# Permanent redirect
501+
- from: /old-page
502+
to: /new-page
503+
status: 301
504+
# Wildcard redirect with path preservation
505+
- from: /blog/*
506+
to: /articles/
507+
preservePath: true
508+
status: 302
509+
headers:
510+
- for: "/*"
511+
values:
512+
X-Frame-Options: "'DENY'"
513+
Content-Security-Policy: '"default-src ''self''"'
514+
```
515+
376516
### healthCheck <Badge type="optional" />
377517

378518
Defines a health check for your application.
@@ -427,19 +567,36 @@ Health checks continuously monitor your running application, while readiness che
427567

428568
### crontab <Badge type="optional" />
429569

430-
Defines scheduled commands to run as cron jobs within a service.
570+
Defines scheduled commands to run as cron jobs within a service.
431571

432-
```yaml
433-
run:
434-
crontab:
435-
- command: "date >> /var/log/cron.log"
436-
timing: "0 * * * *"
437-
```
572+
```yaml
573+
run:
574+
crontab:
575+
- command: "date >> /var/log/cron.log"
576+
timing: "0 * * * *"
577+
allContainers: false
578+
```
438579

439580
Setup cron jobs. See [examples](/zerops-yaml/cron).
440581

441582
## Deploy Configuration
442583

584+
### temporaryShutdown <Badge type="optional" />
585+
586+
Controls the container replacement order during deployment.
587+
588+
```yaml
589+
deploy:
590+
temporaryShutdown: true
591+
```
592+
593+
- Type: `boolean`
594+
- Default: `false`
595+
596+
**When `false` (default):** New containers are started before old containers are removed, ensuring zero-downtime deployment.
597+
598+
**When `true`:** Old containers are removed before new containers are started, causing temporary downtime but using fewer resources during deployment.
599+
443600
### readinessCheck <Badge type="optional" />
444601

445602
Defines a readiness check for your application. Requires either `httpGet` object or `exec` object.
@@ -480,4 +637,4 @@ Unlike health checks which run continuously, readiness checks only run during de
480637
For more detailed information on specific configurations, refer to the runtime-specific guides linked at the beginning of this document.
481638
:::
482639

483-
---
640+
*Need help? Join our [Discord community](https://discord.gg/zeropsio).*

0 commit comments

Comments
 (0)