Xec Recipes Cookbook
Welcome to the Xec Recipes Cookbook - a collection of adaptable recipes for common automation tasks using Xec's universal command execution system.
๐ Recipe Categories
๐ Deployment
Deployment strategies and explicit acceptance checks
Node.js Application Deployment - Deploy Node.js applications with a reviewed transition
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 - Inspect sources and verify centralized delivery
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 deterministic test fixtures
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
JavaScript and TypeScript examples are checked against Xec's public types. Commands that use remote services, databases or cloud providers also require the named tools, credentials and application-owned scripts. Type checking does not establish a production deployment or restore guarantee: run each recipe's acceptance checks in the intended environment.
Getting Started
Choose a recipe that matches your use case
Copy the configuration to your
.xec/config.yamlAdapt 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 โ Database Setup
MongoDB โ Database Setup
Redis โ Database Setup
๐ก Common Patterns
Parallel Execution
const hosts = ['web-1.example.com', 'web-2.example.com'];
const results = await $.parallel.map(hosts,
host => $.ssh({ host, username: 'observer' })`hostname`,
{ maxConcurrency: 2 });
for (const result of results.results) {
if (result instanceof Error) throw result;
console.log(result.stdout.trim());
}Error Handling
const result = await $`node --version`.nothrow();
if (!result.ok) throw new Error(`Runtime probe failed: ${result.cause}`);
console.log(result.stdout.trim());Progress Tracking
import { Pipeline } from '@xec-sh/ops';
const result = await Pipeline.create('validate')
.step('runtime', { run: 'node --version' })
.step('package-manager', { run: 'npm --version', dependsOn: ['runtime'] })
.run({}, { onEvent: event => { console.log(event); } });
if (result.status !== 'success') throw new Error(`Validation ${result.status}`);Connection Reuse
const server = $.ssh({ host: 'staging.example.com', username: 'observer' });
await server`hostname`;
await server`uptime`;๐ 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
The cookbook groups recipes into deployment, maintenance, development and integration. The examples use shared Xec execution, configuration and lifecycle APIs; application-specific schemas and service policies remain explicit inputs.
๐ฆ Recipe Maturity
Choose acceptance criteria for the actual target: a successful process exit, healthy container, reachable HTTP endpoint and validated application data are separate guarantees. Adapt and test the selected recipe before enabling automated production changes. Preserve a recovery path appropriate to the data and service being changed.
๐ 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
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.