Configuration Overview
Xec's configuration system provides a powerful, declarative way to define your infrastructure, automation tasks, and execution environments. Using a simple YAML format, you can describe complex workflows, manage multiple environments, and automate repetitive tasks across diverse infrastructure.
Philosophyβ
Xec's configuration follows several key principles:
1. Declarative Over Imperativeβ
Define what you want to achieve, not how to achieve it. Xec handles the implementation details.
# Declarative: Define the desired state
tasks:
deploy:
description: Deploy application to production
target: production-servers
steps:
- command: docker-compose up -d
2. Convention Over Configurationβ
Sensible defaults minimize boilerplate while allowing customization when needed.
# Minimal configuration - uses conventions
targets:
hosts:
web-server:
host: web.example.com
# Port defaults to 22, username to current user
3. Composabilityβ
Build complex configurations from simple, reusable components.
# Compose configurations through profiles
profiles:
production:
extends: base
vars:
environment: production
replicas: 3
4. Progressive Disclosureβ
Start simple, add complexity only when needed.
# Simple start
tasks:
backup: rsync -av /data /backup
# Add complexity as needed
tasks:
backup:
description: Backup data with retention
schedule: "0 2 * * *"
steps:
- command: rsync -av /data /backup/$(date +%Y%m%d)
- command: find /backup -mtime +7 -delete
Configuration Hierarchyβ
Xec loads and merges configurations from multiple sources in a specific order:
- Built-in Defaults - Xec's internal defaults
- Global Configuration -
~/.xec/config.yaml
- Project Configuration -
.xec/config.yaml
in project root - Environment Variables -
XEC_*
prefixed variables - Profile Configuration - Profile-specific overrides
- Command-line Arguments - Runtime overrides
Later sources override earlier ones, allowing flexible customization at different levels.
File Structureβ
A typical Xec project configuration looks like:
.xec/
βββ config.yaml # Main configuration file
βββ profiles/ # Environment-specific profiles
β βββ dev.yaml
β βββ staging.yaml
β βββ production.yaml
βββ tasks/ # Task definitions (can be imported)
β βββ deploy.yaml
β βββ maintenance.yaml
βββ scripts/ # Custom scripts
β βββ health-check.js
βββ commands/ # Custom commands
βββ backup.js
Key Conceptsβ
Targetsβ
Execution environments where commands run:
- Local - Your development machine
- SSH Hosts - Remote servers via SSH
- Docker Containers - Containerized environments
- Kubernetes Pods - Cloud-native workloads
Tasksβ
Reusable automation workflows with:
- Multi-step execution
- Parameter support
- Error handling
- Conditional logic
- Parallel execution
Profilesβ
Environment-specific configurations:
- Development settings
- Staging configurations
- Production parameters
- Custom environments
Variablesβ
Dynamic values that can be:
- Interpolated in strings
- Shared across configurations
- Overridden at different levels
- Sourced from environment
Quick Start Exampleβ
Here's a complete configuration showcasing key features:
# .xec/config.yaml
version: "1.0"
name: my-app
description: My application deployment configuration
# Global variables
vars:
app_name: myapp
version: "1.0.0"
# Define execution targets
targets:
hosts:
web:
host: web.example.com
username: deploy
db:
host: db.example.com
username: admin
# Define reusable tasks
tasks:
deploy:
description: Deploy application
target: web
steps:
- command: docker pull ${app_name}:${version}
- command: docker stop ${app_name} || true
- command: docker run -d --name ${app_name} ${app_name}:${version}
backup:
description: Backup database
target: db
command: pg_dump mydb > /backup/mydb-$(date +%Y%m%d).sql
# Command defaults
commands:
logs:
tail: 100
follow: true
# Environment profiles
profiles:
production:
vars:
version: "stable"
targets:
hosts:
web:
host: prod-web.example.com
Configuration Validationβ
Xec validates your configuration at multiple levels:
- Schema Validation - Structure and types
- Reference Validation - Target and task references
- Variable Validation - Variable interpolation
- Semantic Validation - Logical consistency
Run validation explicitly:
xec config validate
Best Practicesβ
1. Keep Secrets Secureβ
Never store secrets directly in configuration files:
# Bad - exposed secret
password: "mysecretpass"
# Good - use secret management
password: ${secrets.db_password}
2. Use Version Controlβ
Track configuration changes:
git add .xec/config.yaml
git commit -m "Add production deployment configuration"
3. Organize by Environmentβ
Separate environment-specific settings:
# .xec/profiles/production.yaml
vars:
replicas: 3
debug: false
# .xec/profiles/development.yaml
vars:
replicas: 1
debug: true
4. Document Complex Tasksβ
Add descriptions and comments:
tasks:
complex-deployment:
description: |
Performs blue-green deployment with health checks.
Requires: docker, nginx
Duration: ~5 minutes
steps:
# Step 1: Health check
- command: curl -f http://localhost/health
name: "Verify current deployment"
5. Leverage Compositionβ
Build complex configurations from simple components:
# Base configuration
tasks:
base-setup:
steps:
- command: apt-get update
- command: apt-get install -y curl git
# Extended configuration
tasks:
app-setup:
steps:
- task: base-setup
- command: npm install
Next Stepsβ
- Configuration File Structure - Deep dive into config.yaml
- Defining Targets - Configure execution environments
- Creating Tasks - Build automation workflows
- Using Profiles - Manage multiple environments
- Variable Management - Dynamic configuration values
See Alsoβ
- CLI Commands - Configuration management commands
- Best Practices - Configuration patterns
- Troubleshooting - Common issues and solutions