Understanding Templates
Templates are the foundation of Migraine workflows. They are JSON-structured documents that define how a sequence of operations should be executed, what checks should be performed, and what actions are available. Templates make workflows reusable, shareable, and version-controlled.
Purpose
Templates solve several common development challenges:
- Standardizing repetitive tasks across teams
- Ensuring consistent environment setup
- Automating complex deployment procedures
- Maintaining reliable operation sequences
- Sharing best practices within organizations
Template Structure
A template consists of several key sections:
Core Components
1. Metadata
version
: Template specification versionname
: Human-readable namedescription
: Detailed explanation of the template's purpose
2. Pre-checks
Pre-checks validate requirements before workflow execution:
- Tool availability
- Environment setup
- Resource presence
- Permission checks
3. Steps
Steps define the main sequence of operations:
- Execute in order
- Each step must complete successfully
- Can use variables
- Should include descriptive comments
4. Actions
Actions are named, independent operations that can be:
- Executed individually
- Referenced by name
- Used for maintenance tasks
- Called as needed
5. Configuration
Configuration defines:
- Required variables
- Variable processing rules
- Storage preferences
- Runtime behavior
Variable System
Syntax
Variables use double curly braces: {{VARIABLE_NAME}}
Variable Rules
- Use UPPERCASE names for clarity
- Keep names descriptive but concise
- Use underscores for spaces
- Avoid special characters
Variable Processing
Variables can have processing rules:
Template Examples
1. Development Environment Setup
2. Deployment Workflow
Best Practices
1. Template Design
- Keep templates focused on a single purpose
- Break complex workflows into smaller templates
- Use clear, descriptive names
- Include thorough documentation
2. Command Structure
- Use absolute paths or variables for paths
- Include error handling in commands
- Add timeouts for long-running operations
- Use conditional checks where appropriate
3. Variable Management
- Document all required variables
- Provide default values when possible
- Use descriptive variable names
- Consider variable scope and security
4. Pre-checks
- Verify all required tools
- Check for required files and permissions
- Validate environment variables
- Test network connectivity if needed
5. Security Considerations
- Avoid storing sensitive data in templates
- Use environment variables for secrets
- Validate user input
- Check file permissions
Template Management
Creating Templates
Listing Templates
Deleting Templates
Common Issues and Solutions
-
Variable Not Found
- Check variable names match exactly
- Verify variable is defined in config
- Ensure variables are provided when running
-
Command Failures
- Check pre-requisites are installed
- Verify file permissions
- Check path variables are correct
-
Syntax Errors
- Validate JSON syntax
- Check for missing commas
- Verify bracket matching
Getting Started
A guide to getting started with Migraine.
Understanding Workflows
In Migraine, workflows and templates serve different but complementary purposes. While templates are the blueprints, workflows are the concrete instances created from these templates with specific configurations and variable values.