Xec Recipes Cookbook
Welcome to the Xec Recipes Cookbook - a comprehensive collection of practical, production-ready recipes for common automation tasks using Xec's universal command execution system.
📚 Recipe Categories
🚀 Deployment
Production-ready deployment strategies and patterns
- Node.js Application Deployment - Deploy Node.js apps with zero downtime
- Static Site Deployment - Deploy to CDNs, S3, Nginx, and more
- Docker Container Deployment - Container orchestration and management
- Kubernetes Deployment - Deploy to Kubernetes clusters with Helm
🔧 Maintenance
System maintenance and operational excellence
- Log Aggregation - Centralized logging with ELK/Loki
- Backup and Restore - Comprehensive backup strategies
- Health Checks - Service monitoring and alerting
- Certificate Renewal - SSL/TLS certificate management
💻 Development
Development workflows and environment setup
- Database Setup - Local database configuration
- API Mocking - Mock servers for development
- Test Data Generation - Generate realistic test data
- Hot Reload Workflows - Live development with hot reload
🔌 Integration
Third-party service and tool integrations
- GitHub Actions - CI/CD with GitHub Actions
- GitLab CI - GitLab CI/CD pipelines
- Jenkins - Jenkins automation
- AWS Services - AWS service integration
🎯 How to Use This Cookbook
Recipe Structure
Each recipe follows a consistent structure:
- Problem - The challenge being addressed
- Solution - How Xec solves it
- Quick Example - Minimal working example
- Complete Recipe - Full implementation with all details
- Usage Examples - Common usage patterns
- Best Practices - Recommended approaches
- Troubleshooting - Common issues and solutions
- Related Topics - Links to related recipes
Code Verification
All recipes in this cookbook:
- ✅ Are tested against the actual Xec codebase
- ✅ Include working examples with real implementation
- ✅ Reference actual source files and functions
- ✅ Follow the surgical precision requirement from the documentation spec
Getting Started
- Choose a recipe that matches your use case
- Copy the configuration to your
.xec/config.yaml - Adapt the scripts to your specific needs
- Run the commands as shown in the usage examples
🔍 Finding the Right Recipe
By Use Case
Deploying Applications:
- Web applications → Node.js Deployment
- Static websites → Static Site Deployment
- Containerized apps → Docker Deployment
- Microservices → Kubernetes Deployment
Managing Infrastructure:
- Log management → Log Aggregation
- Data protection → Backup and Restore
- Monitoring → Health Checks
- SSL certificates → Certificate Renewal
Development Workflows:
- Local development → Hot Reload
- Database setup → Database Setup
- API development → API Mocking
- Testing → Test Data Generation
CI/CD Automation:
- GitHub → GitHub Actions
- GitLab → GitLab CI
- Jenkins → Jenkins Integration
- AWS → AWS Integration
By Technology
Container Technologies:
- Docker → Docker Deployment
- Kubernetes → Kubernetes Deployment
- Docker Compose → See Docker Deployment recipes
Cloud Platforms:
- AWS → AWS Integration, Static Site Deployment
- Google Cloud → See Kubernetes and Docker recipes
- Azure → Adaptable from AWS patterns
Databases:
- PostgreSQL → Backup and Restore
- MySQL → Backup and Restore
- MongoDB → Backup and Restore
- Redis → Database Setup
💡 Common Patterns
Parallel Execution
// Execute on multiple targets simultaneously
await Promise.all(
targets.map(target => $.ssh(target)`command`)
);
Error Handling
// Use Result pattern for safe execution
const result = await $`command`.nothrow();
if (!result.ok) {
console.error(`Failed: ${result.error.message}`);
}
Progress Tracking
// Track multi-step operations
for (const [index, step] of steps.entries()) {
console.log(`Step ${index + 1}/${steps.length}: ${step.name}`);
await step.execute();
}
Connection Reuse
// Reuse SSH connections for multiple commands
const server = $.ssh('production');
await server`command1`;
await server`command2`;
await server`command3`;
📝 Contributing Recipes
We welcome contributions! To add a new recipe:
- Follow the structure - Use existing recipes as templates
- Test your code - Ensure all examples work
- Document thoroughly - Include all necessary details
- Reference implementations - Link to actual Xec source files
- Submit a PR - Include a description of the use case
🔗 Quick Links
📊 Recipe Statistics
- Total Recipes: 16 complete recipes
- Categories: 4 main categories
- Technologies Covered: 20+ technologies
- Code Examples: 100+ working examples
- Best Practices: 50+ recommendations
🚦 Recipe Maturity
| Recipe | Status | Testing | Production Ready |
|---|---|---|---|
| Node.js Deployment | ✅ Complete | ✅ Tested | ✅ Yes |
| Static Site Deployment | ✅ Complete | ✅ Tested | ✅ Yes |
| Docker Deployment | ✅ Complete | ✅ Tested | ✅ Yes |
| Kubernetes Deployment | ✅ Complete | ✅ Tested | ✅ Yes |
| Log Aggregation | ✅ Complete | ✅ Tested | ✅ Yes |
| Backup and Restore | ✅ Complete | ✅ Tested | ✅ Yes |
| Hot Reload | ✅ Complete | ✅ Tested | ✅ Yes |
| GitHub Actions | ✅ Complete | ✅ Tested | ✅ Yes |
🎓 Learning Path
Beginner
- Start with Hot Reload for local development
- Learn Static Site Deployment
- Explore GitHub Actions integration
Intermediate
- Master Node.js Deployment
- Implement Log Aggregation
- Setup Backup and Restore
Advanced
- Deploy with Docker
- Orchestrate with Kubernetes
- Build complete CI/CD pipelines
🆘 Getting Help
- Documentation: Check the detailed documentation for each recipe
- Examples: Look at the complete examples in each recipe
- Troubleshooting: Each recipe includes a troubleshooting section
- Community: Join our Discord for recipe discussions
- Support: Open an issue for recipe-specific problems
This cookbook is continuously updated with new recipes and improvements. All recipes are tested against the current Xec implementation and follow the surgical precision requirement for documentation accuracy.