Profiles Overview
Profiles enable you to manage different configurations for various environments (development, staging, production) or scenarios. They provide a clean way to override base configuration values without duplicating entire configuration files.
What Are Profiles?β
Profiles are named configuration sets that can:
- Override global variables
- Modify target configurations
- Set environment-specific values
- Inherit from other profiles
- Be activated via command-line or environment variables
Basic Profile Structureβ
profiles:
development:
vars:
environment: dev
debug: true
logLevel: debug
production:
vars:
environment: prod
debug: false
logLevel: error
Profile Activationβ
Command-Lineβ
# Use specific profile
xec --profile production run deploy
# Short form
xec -p staging run test
Environment Variableβ
# Set profile via environment
export XEC_PROFILE=production
xec run deploy
Configuration Defaultβ
# .xec/config.yaml
defaultProfile: development
profiles:
development:
# ...
Variable Overridesβ
Profiles can override any variables defined in the main configuration:
# Base configuration
vars:
appName: myapp
version: "1.0.0"
replicas: 1
profiles:
production:
vars:
replicas: 3 # Override replicas
version: stable # Override version
# appName inherited as "myapp"
Target Overridesβ
Modify target configurations per environment:
# Base targets
targets:
hosts:
app-server:
host: localhost
port: 2222
profiles:
production:
targets:
hosts:
app-server:
host: prod.example.com
port: 22
username: deploy
Profile Inheritanceβ
Profiles can extend other profiles:
profiles:
base:
vars:
region: us-east-1
monitoring: enabled
staging:
extends: base
vars:
environment: staging
replicas: 2
production:
extends: base
vars:
environment: production
replicas: 5
highAvailability: true
Multiple Inheritanceβ
profiles:
security:
vars:
encryption: true
auditLog: enabled
performance:
vars:
caching: true
compression: true
production:
extends: [security, performance]
vars:
environment: production
Environment Variables in Profilesβ
Set environment variables for command execution:
profiles:
development:
env:
NODE_ENV: development
DEBUG: "*"
API_URL: http://localhost:3000
production:
env:
NODE_ENV: production
DEBUG: ""
API_URL: https://api.example.com
Conditional Configurationβ
Profile-Specific Tasksβ
tasks:
deploy:
command: |
if [ "${profile}" = "production" ]; then
./deploy-prod.sh
else
./deploy-dev.sh
fi
Profile Detection in Scriptsβ
tasks:
smart-deploy:
script: |
const profile = xec.profile;
if (profile === 'production') {
await xec.run('production-checks');
}
await xec.run('deploy');
Profile Filesβ
Organize profiles in separate files:
# .xec/config.yaml
profiles:
$import:
- profiles/dev.yaml
- profiles/staging.yaml
- profiles/prod.yaml
# .xec/profiles/prod.yaml
extends: base
vars:
environment: production
replicas: 5
targets:
hosts:
web:
host: prod-web.example.com
Dynamic Profile Selectionβ
Based on Git Branchβ
tasks:
auto-deploy:
script: |
const branch = await $`git branch --show-current`;
const profile = branch === 'main' ? 'production' : 'staging';
await xec.useProfile(profile);
await xec.run('deploy');
Based on Environmentβ
tasks:
smart-profile:
script: |
const profile = process.env.CI
? 'ci'
: process.env.USER === 'developer'
? 'development'
: 'production';
await xec.useProfile(profile);
Profile Validationβ
Ensure profile configurations are valid:
# Validate specific profile
xec config validate --profile production
# List available profiles
xec config profiles
# Show profile configuration
xec config show --profile staging
Common Patternsβ
Development Profileβ
profiles:
development:
vars:
environment: dev
debug: true
logLevel: debug
replicas: 1
cache: false
targets:
hosts:
app:
host: localhost
port: 2222
containers:
db:
image: postgres:15
ports: ["5432:5432"]
env:
NODE_ENV: development
DEBUG: "*"
Staging Profileβ
profiles:
staging:
extends: development
vars:
environment: staging
debug: false
logLevel: info
replicas: 2
cache: true
targets:
hosts:
app:
host: staging.example.com
port: 22
Production Profileβ
profiles:
production:
vars:
environment: prod
debug: false
logLevel: error
replicas: 5
cache: true
monitoring: enabled
alerting: enabled
targets:
hosts:
app:
host: prod.example.com
username: deploy
privateKey: ~/.ssh/prod_key
kubernetes:
context: production-cluster
namespace: production
env:
NODE_ENV: production
LOG_LEVEL: error
Region-Specific Profilesβ
profiles:
us-east:
vars:
region: us-east-1
availability_zones:
- us-east-1a
- us-east-1b
targets:
hosts:
api:
host: api-us-east.example.com
eu-west:
vars:
region: eu-west-1
availability_zones:
- eu-west-1a
- eu-west-1b
targets:
hosts:
api:
host: api-eu-west.example.com
Feature Flagsβ
profiles:
feature-x-enabled:
vars:
features:
x: true
y: false
feature-y-enabled:
vars:
features:
x: false
y: true
all-features:
vars:
features:
x: true
y: true
Profile Compositionβ
Base Profilesβ
profiles:
# Security baseline
secure:
vars:
tls: true
authentication: required
encryption: aes256
# Performance baseline
fast:
vars:
caching: true
compression: gzip
connectionPool: 10
# Combine baselines
production:
extends: [secure, fast]
vars:
environment: production
Layered Profilesβ
profiles:
# Infrastructure layer
aws:
vars:
cloud: aws
region: us-east-1
# Application layer
api:
vars:
service: api
port: 3000
# Combined profile
aws-api-prod:
extends: [aws, api]
vars:
environment: production
Profile Priorityβ
Configuration sources are merged in this order:
- Base configuration
- Imported configurations
- Profile inheritance chain
- Active profile
- Environment variables
- Command-line arguments
# Base
vars:
value: "base"
profiles:
parent:
vars:
value: "parent"
child:
extends: parent
vars:
value: "child" # This wins when child profile is active
Testing with Profilesβ
profiles:
test:
vars:
environment: test
database: test_db
mockServices: true
targets:
containers:
test-db:
image: postgres:15
env:
POSTGRES_DB: test_db
env:
NODE_ENV: test
MOCK_EXTERNAL_APIS: true
CI/CD Profilesβ
profiles:
ci:
vars:
environment: ci
parallel: true
failFast: true
env:
CI: true
TERM: dumb
NO_COLOR: true
Best Practicesβ
1. Use Descriptive Namesβ
# Good
profiles:
production-us-east:
staging-eu-west:
development-local:
# Bad
profiles:
p1:
s2:
d3:
2. Inherit Common Settingsβ
profiles:
base:
vars:
company: acme
team: platform
production:
extends: base
vars:
environment: production
3. Keep Secrets Separateβ
profiles:
production:
vars:
apiKey: ${secrets.prod_api_key} # Good
# apiKey: "sk-12345" # Bad
4. Document Profilesβ
profiles:
production:
description: |
Production environment profile.
Requires: VPN connection, prod credentials
Region: us-east-1
vars:
environment: production
5. Validate Profile Changesβ
# Before switching profiles
xec config validate --profile new-profile
xec run smoke-test --profile new-profile --dry-run
Troubleshootingβ
Profile Not Foundβ
# List available profiles
xec config profiles
# Check profile name
xec config show --profile correct-name
Variable Not Overriddenβ
# Check inheritance chain
profiles:
child:
extends: parent # Check parent profile
vars:
myVar: value # Ensure correct path
Circular Inheritanceβ
# Avoid circular references
profiles:
a:
extends: b # Error if b extends a
b:
extends: a
See Alsoβ
- Configuration Command - Profile management
- Variables - Variable system
- Environment Variables - Environment configuration