Flavors Introduction
Flavors let you define environment-specific configuration variants without duplicating your entire configuration.
The Problem
Section titled “The Problem”Different environments need different settings:
| Setting | Development | Staging | Production |
|---|---|---|---|
| NODE_ENV | development | staging | production |
| LOG_LEVEL | debug | info | warn |
| Docker target | development | development | production |
Without flavors, you’d need separate config files for each environment.
The Solution: Flavors
Section titled “The Solution: Flavors”Flavors define patches that modify your base configuration:
flavors: production: patches: - op: replace path: /env/NODE_ENV value: productionWhen you use --flavor production, EMB:
- Loads your base configuration
- Applies the flavor’s patches
- Uses the modified configuration
Viewing Available Flavors
Section titled “Viewing Available Flavors”List defined flavors:
emb config print | grep -A 22 "^flavors:"flavors: staging: patches: - op: replace path: /env/NODE_ENV value: staging - op: replace path: /env/LOG_LEVEL value: info production: patches: - op: replace path: /env/NODE_ENV value: production - op: replace path: /env/LOG_LEVEL value: warn - op: replace path: /defaults/docker/target value: production - op: add path: /defaults/docker/platform value: ${env:DOCKER_PLATFORM:-linux/amd64}Base vs Flavored Configuration
Section titled “Base vs Flavored Configuration”Base Configuration
Section titled “Base Configuration”emb config print | grep -A 3 "^env:"env: DOCKER_TAG: ${env:DOCKER_TAG:-latest} NODE_ENV: ${env:NODE_ENV:-development} LOG_LEVEL: ${env:LOG_LEVEL:-debug}With Production Flavor
Section titled “With Production Flavor”emb config print --flavor production | grep -A 3 "^env:"env: DOCKER_TAG: ${env:DOCKER_TAG:-latest} NODE_ENV: production LOG_LEVEL: warnNotice how NODE_ENV and LOG_LEVEL changed from templates to fixed production values!
When to Use Flavors
Section titled “When to Use Flavors”Flavors are ideal for:
- Environment differences - dev/staging/production settings
- Feature flags - enabling/disabling features per environment
- Resource sizing - different memory limits, replicas
- Docker targets - development vs production builds
Component-Level Flavors
Section titled “Component-Level Flavors”Components can also define flavors in their Embfiles:
cat api/Embfile.yml | head -15description: Production-ready API with multi-stage builds
resources: image: type: docker/image publish: true params: target: development
tasks: test: description: Run tests pre: - lint script: npm testWhen both project and component define the same flavor, both sets of patches are applied (project first, then component).
Next Step
Section titled “Next Step”Continue to JSON Patch to learn about the patch operations in detail.