Using Flavors
Now that you understand flavors and JSON Patch, let’s see how to use them in practice.
The —flavor Flag
Section titled “The —flavor Flag”Most EMB commands accept the --flavor flag:
emb <command> --flavor productionThe flag comes after the command.
Building with Flavors
Section titled “Building with Flavors”Build production images:
emb resources build --flavor productionThis applies the production flavor, changing:
- Docker target from
developmenttoproduction - Environment variables as configured
Viewing Flavor Effects
Section titled “Viewing Flavor Effects”Compare base vs flavored configuration:
# Base configurationemb config print
# With production flavoremb config print --flavor productionCheck specific values using the defaults section:
emb config print | grep -A 3 "^defaults:"defaults: docker: tag: ${env:DOCKER_TAG} target: developmentemb config print --flavor production | grep -A 3 "^defaults:"defaults: docker: tag: ${env:DOCKER_TAG} target: productionRunning with Flavors
Section titled “Running with Flavors”Start services with production settings:
emb up --flavor productionThis:
- Applies the flavor patches
- Builds images with the production target
- Starts services with production environment variables
Flavor in CI/CD
Section titled “Flavor in CI/CD”Flavors are perfect for CI/CD pipelines:
# Development builds (default)emb resources buildemb up -dnpm test
# Staging deploymentemb resources build --flavor stagingdocker push myregistry/app:staging
# Production deploymentemb resources build --flavor productiondocker push myregistry/app:latestComponent-Level Flavor Patches
Section titled “Component-Level Flavor Patches”Components can add their own flavor patches:
cat api/Embfile.yml | grep -A 5 "^flavors:"flavors: production: patches: - op: replace path: /resources/image/params/target value: productionThis ensures the API uses the production Docker target when building with --flavor production.
Flavor Inheritance
Section titled “Flavor Inheritance”When both project and component define the same flavor:
- Project-level patches apply first
- Component-level patches apply second
This lets you:
- Set global defaults at project level
- Override specific components as needed
Summary
Section titled “Summary”You’ve completed the EMB tutorials! You now know how to:
- Hello World: Minimal configuration and auto-discovery
- Fullstack App: Tasks, environment variables, Docker Compose
- Microservices: Dependencies and build ordering
- Production Ready: Multi-stage builds and flavors
Next Steps
Section titled “Next Steps”- Check the Advanced documentation for executors, interactive tasks, and more
- Learn about Secrets Management for Vault integration
- Read the Reference for complete configuration options
Happy building!