Documentation/Xec Recipes Cookbook

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

๐Ÿ”ง Maintenance

System maintenance and operational excellence

๐Ÿ’ป Development

Development workflows and environment setup

๐Ÿ”Œ Integration

Third-party service and tool integrations

๐ŸŽฏ How to Use This Cookbook

Recipe Structure

Each recipe follows a consistent structure:

  1. Problem - The challenge being addressed

  2. Solution - How Xec solves it

  3. Quick Example - Minimal working example

  4. Complete Recipe - Full implementation with all details

  5. Usage Examples - Common usage patterns

  6. Best Practices - Recommended approaches

  7. Troubleshooting - Common issues and solutions

  8. 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

  1. Choose a recipe that matches your use case

  2. Copy the configuration to your .xec/config.yaml

  3. Adapt the scripts to your specific needs

  4. Run the commands as shown in the usage examples

๐Ÿ” Finding the Right Recipe

By Use Case

Deploying Applications:

Managing Infrastructure:

Development Workflows:

CI/CD Automation:

By Technology

Container Technologies:

Cloud Platforms:

Databases:

๐Ÿ’ก 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:

  1. Follow the structure - Use existing recipes as templates

  2. Test your code - Ensure all examples work

  3. Document thoroughly - Include all necessary details

  4. Reference implementations - Link to actual Xec source files

  5. Submit a PR - Include a description of the use case

๐Ÿ“Š 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

  1. Start with Hot Reload for local development

  2. Learn Static Site Deployment

  3. Explore GitHub Actions integration

Intermediate

  1. Master Node.js Deployment

  2. Implement Log Aggregation

  3. Setup Backup and Restore

Advanced

  1. Deploy with Docker

  2. Orchestrate with Kubernetes

  3. 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.

MADE FOR BUILDERS.Static pages. Local search. Built with Lumen + Prism.