Drupal Recipes System Comprehensive Guide
Overviewβ
Drupal Recipes represent a fundamental shift in how Drupal sites are configured and deployed. Unlike traditional modules that are installed/uninstalled, recipes are applied once to configure existing Drupal installations, making them ideal for enterprise deployment strategies.
What Are Drupal Recipes?β
Core Conceptβ
Recipes automate module installation and configuration by creating scripts that can:
- Install modules and themes
- Apply configuration settings
- Set up default content
- Configure workflows and permissions
- Establish content types and fields
Key Differentiators from Modulesβ
- Not Installed: Recipes are applied, not installed
- One-Time Application: Applied once, then removed
- Configuration Focus: Primarily handles configuration, not ongoing functionality
- Deployment Tool: Designed for site setup and feature deployment
Technical Architectureβ
Core APIs (Drupal 10.3+)β
Recipe API (Drupal\Core\Recipe
)β
<?php
// Basic recipe structure
class RecipeManager {
public function applyRecipe(string $recipe_path): RecipeApplicationResult {
$recipe = Recipe::createFromDirectory($recipe_path);
// Validate recipe dependencies
$this->validateDependencies($recipe);
// Apply recipe components
$this->installModules($recipe->getModules());
$this->applyConfiguration($recipe->getConfiguration());
$this->createDefaultContent($recipe->getDefaultContent());
return new RecipeApplicationResult($recipe);
}
}
Config Action API (Drupal\Core\Config\Action
)β
<?php
// Dynamic configuration modification
class ConfigActionManager {
public function executeActions(array $actions): void {
foreach ($actions as $action) {
$this->configActionExecutor->execute(
$action['plugin'],
$action['config'],
$action['data']
);
}
}
}
Checkpoint API (Drupal\Core\Config\Checkpoint
)β
<?php
// Configuration snapshots and rollback
class CheckpointManager {
public function createCheckpoint(string $label): CheckpointInterface {
return $this->checkpointStorage->create([
'label' => $label,
'timestamp' => time(),
'configuration' => $this->exportCurrentConfig()
]);
}
public function rollbackToCheckpoint(CheckpointInterface $checkpoint): void {
$this->configImporter->importFromCheckpoint($checkpoint);
}
}
Default Content API (Drupal\Core\DefaultContent
)β
<?php
// YAML-based content provisioning
class DefaultContentManager {
public function importContent(string $content_path): void {
$content_files = $this->scanner->scan($content_path, '*.yml');
foreach ($content_files as $file) {
$content_data = Yaml::decode(file_get_contents($file));
$this->createEntity($content_data);
}
}
}
Recipe Structureβ
Standard Recipe Directory Layoutβ
my_recipe/
βββ recipe.yml # Recipe metadata and dependencies
βββ composer.json # Composer dependencies
βββ config/
β βββ install/ # Configuration to install
β β βββ core.entity_form_display.node.article.default.yml
β β βββ core.entity_view_display.node.article.default.yml
β βββ optional/ # Optional configuration
β βββ views.view.content.yml
βββ content/ # Default content (YAML format)
β βββ node/
β β βββ article.yml
β βββ user/
β βββ admin.yml
βββ modules/ # Custom modules (if needed)
βββ custom_feature/
Recipe Metadata (recipe.yml)β
name: 'Enterprise Content Management'
description: 'Complete content management setup for government agencies'
type: 'Site'
recipes:
- 'core/recipes/standard'
- 'contrib/recipes/workflow'
install:
- node
- taxonomy
- workflows
- content_moderation
- pathauto
config:
actions:
user.settings:
simpleAction:
- 'set user_register to visitors_admin_approval'
workflows.workflow.editorial:
createIfNotExists:
langcode: en
status: true
dependencies: {}
id: editorial
label: Editorial
type: content_moderation
Advanced Configuration Actionsβ
# Complex configuration modifications
config:
actions:
# Create content type if it doesn't exist
node.type.policy_document:
createIfNotExists:
type: policy_document
name: 'Policy Document'
description: 'Official government policy documents'
settings:
node:
preview_mode: 1
display_submitted: false
# Configure field storage
field.storage.node.field_classification:
simpleAction:
- 'set field_type to list_string'
- 'set settings.allowed_values to {public: Public, classified: Classified, secret: Secret}'
# Set up permissions
user.role.content_editor:
grantPermissions:
- 'create policy_document content'
- 'edit own policy_document content'
- 'use editorial transition create_new_draft'
Enterprise Recipe Developmentβ
Government Compliance Recipeβ
name: 'Government Compliance Suite'
description: 'FISMA and Section 508 compliance configuration'
type: 'Feature'
install:
- gov_compliance
- accessibility_checker
- audit_trail
- encrypt
- key
config:
actions:
gov_compliance.settings:
simpleAction:
- 'set fisma_level to moderate'
- 'set audit_logging to true'
- 'set encryption_required to true'
encrypt.profile.government:
createIfNotExists:
id: government
label: 'Government Encryption'
encryption_method: 'real_aes'
key_provider: 'file'
AI Platform Integration Recipeβ
name: 'LLM Platform Integration'
description: 'Complete AI integration for government agencies'
type: 'Site'
recipes:
- 'recipes/government_compliance'
install:
- llm
- ai_provider_ollama
- mcp_registry
- alternative_services
- api_normalizer
config:
actions:
llm.settings:
simpleAction:
- 'set default_provider to ollama'
- 'set ollama_endpoint to http://localhost:11434'
- 'set enable_audit_logging to true'
ai_provider_ollama.settings:
simpleAction:
- 'set default_model to llama3.2:7b'
- 'set timeout to 30'
- 'set max_tokens to 4096'
Enterprise Deployment Strategiesβ
Multi-Environment Recipe Strategyβ
#!/bin/bash
# Enterprise deployment script
# Development environment
drush recipe:apply recipes/base_platform
drush recipe:apply recipes/development_tools
# Staging environment
drush recipe:apply recipes/base_platform
drush recipe:apply recipes/staging_config
drush recipe:apply recipes/performance_monitoring
# Production environment
drush recipe:apply recipes/base_platform
drush recipe:apply recipes/production_config
drush recipe:apply recipes/security_hardening
drush recipe:apply recipes/government_compliance
Continuous Integration Recipe Pipelineβ
# .gitlab-ci.yml
stages:
- validate
- test
- deploy
validate_recipes:
stage: validate
script:
- drush recipe:validate recipes/government_platform
- drush recipe:validate recipes/security_hardening
test_recipe_application:
stage: test
script:
- ddev start
- drush si minimal -y
- drush recipe:apply recipes/government_platform
- drush pm:enable -y simpletest
- drush test-run --all
deploy_to_staging:
stage: deploy
script:
- drush @staging recipe:apply recipes/government_platform
- drush @staging cr
only:
- main
Recipe Management Toolsβ
Recipe Generator Integrationβ
# Interactive recipe creation
drush recipe:generate
# Output structure:
# What is the recipe name? Government AI Platform
# What is the recipe description? Complete AI integration for government
# What type of recipe is this? [Site/Feature] Site
# Which modules should be installed? llm, ai_provider_ollama, mcp_registry
# Generate default content? [y/N] y
Custom Recipe Generation Scriptβ
<?php
// Custom recipe generator for enterprise patterns
class EnterpriseRecipeGenerator {
public function generateGovernmentRecipe(array $options): string {
$recipe_data = [
'name' => $options['name'],
'description' => $options['description'],
'type' => 'Site',
'install' => $this->getGovernmentModules($options),
'config' => [
'actions' => $this->generateGovernmentConfig($options)
]
];
return Yaml::encode($recipe_data);
}
private function getGovernmentModules(array $options): array {
$base_modules = ['gov_compliance', 'audit_trail', 'encrypt'];
if ($options['ai_enabled']) {
$base_modules = array_merge($base_modules, [
'llm', 'ai_provider_ollama', 'mcp_registry'
]);
}
return $base_modules;
}
}
Security & Compliance Considerationsβ
Recipe Security Best Practicesβ
- Configuration Validation: Validate all configuration before application
- Dependency Checking: Verify all dependencies are secure and up-to-date
- Permission Auditing: Review all permission changes in recipes
- Content Sanitization: Sanitize all default content
Government Deployment Considerationsβ
# Security-focused recipe configuration
name: 'Secure Government Platform'
config:
actions:
system.site:
simpleAction:
- 'set page.403 to /access-denied'
- 'set page.404 to /page-not-found'
- 'set admin_compact_mode to true'
user.settings:
simpleAction:
- 'set password_strength to true'
- 'set password_reset_timeout to 86400'
- 'set user_register to admin_only'
system.performance:
simpleAction:
- 'set cache.page.max_age to 0' # Disable caching for secure sites
- 'set response.gzip to false' # Disable compression for secure sites
Integration with LLM Platformβ
AI-Enabled Recipe Templatesβ
# LLM Platform recipe with AI providers
name: 'AI-Powered Government Platform'
install:
- llm
- ai_provider_ollama
- ai_provider_anthropic
- mcp_registry
- alternative_services
config:
actions:
llm.provider.ollama:
createIfNotExists:
plugin: ollama
label: 'Local Ollama'
configuration:
endpoint: 'http://localhost:11434'
default_model: 'llama3.2:7b'
timeout: 30
mcp_registry.server.platform:
createIfNotExists:
name: 'LLM Platform Server'
transport: 'stdio'
command: 'node'
args: ['/path/to/mcp-server.js']
Best Practices & Recommendationsβ
Recipe Development Guidelinesβ
- Modular Design: Create focused, single-purpose recipes
- Dependency Management: Clearly define all dependencies
- Version Control: Tag and version recipes for reproducibility
- Testing: Comprehensive testing on clean Drupal installations
- Documentation: Document all configuration changes
Enterprise Recipe Strategyβ
- Base Platform Recipe: Core configuration for all sites
- Feature Recipes: Specific functionality (AI, compliance, etc.)
- Environment Recipes: Environment-specific configurations
- Custom Recipes: Organization-specific customizations
Performance Considerationsβ
- Use checkpoints for large recipe applications
- Apply recipes during maintenance windows
- Monitor resource usage during application
- Implement rollback procedures for failed applications
Drupal Recipes provide a powerful deployment strategy for enterprise Drupal applications, enabling consistent, repeatable site configurations that align with government and defense requirements.