This guide explains the main config architecture that supports centralized configuration with distributed workflow definitions.
The main config architecture introduces a hierarchical configuration system that separates global settings from workflow-specific configurations. This enables:
- Centralized defaults in a main config file
- Distributed workflows in source repositories
- Reusable components for transformations, strategies, and excludes
- Clear ownership of workflow configurations
Main Config (Central)
├── Global Defaults
└── Workflow Config References
├── Local Workflow Configs (same repo)
├── Remote Workflow Configs (source repos)
└── Inline Workflows (simple cases)
└── Individual Workflows
Settings are applied in order of specificity (most specific wins):
- Individual Workflow settings (highest priority)
- Workflow Config defaults
- Main Config defaults
- System defaults (lowest priority)
Location: Specified in env.yaml as MAIN_CONFIG_FILE
Purpose: Central configuration with global defaults and workflow references
# main-config.yaml
defaults:
commit_strategy:
type: "pull_request"
auto_merge: false
exclude:
- "**/.env"
- "**/node_modules/**"
workflow_configs:
- source: "repo"
repo: "mongodb/docs-sample-apps"
path: ".copier/workflows.yaml"Location: In source repositories (e.g., .copier/workflows.yaml)
Purpose: Define workflows for a specific source repository
# .copier/workflows.yaml
defaults:
commit_strategy:
type: "pull_request"
workflows:
- name: "mflix-java"
source:
repo: "mongodb/docs-sample-apps"
branch: "main"
destination:
repo: "mongodb/sample-app-java-mflix"
branch: "main"
transformations:
- move: { from: "mflix/client", to: "client" }Location: In source repositories (e.g., .copier/transformations/)
Purpose: Extract common configurations for reuse
# .copier/transformations/mflix-java.yaml
- move: { from: "mflix/client", to: "client" }
- move: { from: "mflix/server/java-spring", to: "server" }Add to your env.yaml:
env_variables:
# Main config settings
MAIN_CONFIG_FILE: "main-config.yaml"
USE_MAIN_CONFIG: "true"
# Config repository
CONFIG_REPO_OWNER: "mongodb"
CONFIG_REPO_NAME: "code-copier-config"
CONFIG_REPO_BRANCH: "main"Create main-config.yaml in your config repository:
defaults:
commit_strategy:
type: "pull_request"
auto_merge: false
exclude:
- "**/.env"
- "**/.env.*"
workflow_configs:
- source: "repo"
repo: "mongodb/docs-sample-apps"
branch: "main"
path: ".copier/workflows.yaml"Create .copier/workflows.yaml in your source repository:
workflows:
- name: "my-workflow"
source:
repo: "mongodb/docs-sample-apps"
branch: "main"
destination:
repo: "mongodb/my-destination"
branch: "main"
transformations:
- move: { from: "src", to: "dest" }- Deploy the updated configuration
- Trigger a webhook event (merge a PR in source repo)
- Verify workflows execute correctly
Recommended directory structure:
Config Repo (mongodb/code-copier-config):
main-config.yaml
workflows/
mflix-workflows.yaml
university-workflows.yaml
Source Repo (mongodb/docs-sample-apps):
.copier/
workflows.yaml
transformations/
mflix-java.yaml
mflix-nodejs.yaml
strategies/
mflix-pr-strategy.yaml
common/
mflix-excludes.yaml
- Centralized: Use
source: "local"for workflows managed by central team - Distributed: Use
source: "repo"for workflows managed by source repo teams - Simple: Use
source: "inline"for one-off or simple workflows
Extract common configurations:
- Transformations: When multiple workflows use similar file mappings
- Strategies: When multiple workflows use the same PR format
- Excludes: When multiple workflows exclude the same patterns
Set sensible defaults at each level:
- Main config: Organization-wide defaults
- Workflow config: Source repo defaults
- Individual workflow: Workflow-specific overrides
- Test workflow configs in source repo PRs
- Use
DRY_RUN=truefor testing without side effects - Validate configurations before deploying
See the example files in this directory:
main-config-example.yaml- Complete main config examplesource-repo-workflows-example.yaml- Workflow config in source reporeusable-components/- Examples of reusable componentstransformations-example.yamlstrategy-example.yamlexcludes-example.yaml
# Local file in config repo
- source: "local"
path: "workflows/my-workflows.yaml"
# Remote file in source repo
- source: "repo"
repo: "owner/repo"
branch: "main"
path: ".copier/workflows.yaml"
# Inline workflows
- source: "inline"
workflows:
- name: "my-workflow"
# ... workflow definition ...You can use $ref to reference external files for transformations, commit_strategy, and exclude patterns:
# Reference transformations
transformations:
$ref: "transformations/mflix-java.yaml"
# Reference strategy
commit_strategy:
$ref: "strategies/mflix-pr-strategy.yaml"
# Reference excludes
exclude:
$ref: "common/mflix-excludes.yaml"Benefits:
- Share common configurations across multiple workflows
- Keep workflow configs clean and focused
- Organize related files in a logical directory structure
Path Resolution:
- Relative paths are resolved relative to the workflow config file
- Example: If your workflow config is at
.copier/workflows.yaml, thentransformations/mflix-java.yamlresolves to.copier/transformations/mflix-java.yaml
- Check
MAIN_CONFIG_FILEis set correctly - Verify
USE_MAIN_CONFIG=true - Check file exists in config repository
- Review logs for parsing errors
- Verify workflow source repo matches webhook repo
- Check workflow config is referenced in main config
- Validate workflow config syntax
- Review logs for validation errors
- Ensure GitHub App has access to all repos
- Verify installation IDs are correct
- Check app permissions
For questions or issues:
- Check the example configurations
- Review the logs for error messages
- Validate your configuration syntax
- Test with
DRY_RUN=true