Copier + Jinja template-repository design skill: reference architecture, implementation workflow, validation checklist, and a full worked example template (questionnaire, extensions, resolvers, wrapper-first .scripts). Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
3.4 KiB
3.4 KiB
name, description
| name | description |
|---|---|
| template-engine-copier | Design and implement a Copier + Jinja based template repository, following the proven patterns used in iac-tmpl-aws-projects and iac-tmpl-aws-organizations. |
template-engine-copier
Use this skill when you need to create, refactor, or standardize a repository that acts as a Copier template engine for downstream projects.
This skill is based on real patterns from:
iac-tmpl-aws-projects/iac-tmpl-aws-organizations/
and is meant to guide creation of repositories that have:
- clear questionnaire-driven inputs,
- deterministic Jinja rendering,
- conditional folder/file generation,
- safe bootstrapping and re-render workflows.
It now also includes a concrete scaffold you can copy from:
example/
Goal
Deliver a template repository where operators can run one command like:
task copier:bootstrap-one -- --copier-target-dir "../target-repo" --copier-params-file "./copier-answers.yaml"
and get a rendered repository with predictable structure and preserved answer history.
Read in this order
instructions/01-reference-architecture.mdinstructions/02-implementation-workflow.mdinstructions/03-validation-checklist.mdexample/README.mdandexample/
Canonical architecture (from analyzed repos)
<template-repo>/
.copier/
copier.yaml
questionnaire/*.yml
extensions/
context_hook_extension/ # optional but recommended for complex templates
resolvers/
.scripts/
copier/
Taskfile.yml
api/bootstrap-one.sh
lib/
--env-vars-reader.sh
--index.sh
--index-api.sh
-bootstrap-one.sh
answers/
--index-api.sh
-new-ensure-existance.sh
-previous-pull-and-merge.sh
-params-pull-and-merge.sh
base/
loggers/
Taskfile.yml
{{ _copier_conf.answers_file }}.jinja
{{ '.tmp-gitlab-ci.yml' }}.jinja
src/**/*.jinja
Non-negotiable conventions
- Keep Copier source-of-truth in
.copier/copier.yaml. - Keep questions separated under
.copier/questionnaire/*.ymland include via!include. - Use
.jinjasuffix and render both file contents and file/folder names. - For dynamic instance folders, support
[INDEX]expansion pattern via context hook. - Keep operational entrypoint wrapper-first:
Taskfile -> api -> lib. - Merge answers in this order:
- previous target answers,
- explicit params file,
- final merged file used for
copier copy --data-file ....
Anti-patterns to avoid
- Putting all logic directly into one giant Jinja file.
- Copying templates without answer merge strategy (breaks update flows).
- Embedding one-off shell logic directly in Taskfile instead of API/lib wrappers.
- Using ad-hoc variable names instead of stable normalized
flat.*style for complex conditions. - Ignoring render-time safety for generated CI files (e.g., temp naming + controlled rename).
What to copy first (practical)
When building a new template repo, copy these parts first from example/:
.copier/copier.yaml.copier/questionnaire/0100-template.yml.copier/extensions/context_hook_extension/hook.py.copier/extensions/resolvers/resolve_safe_identifier.py.scripts/copier/(all files)Taskfile.yml{{ _copier_conf.answers_file }}.jinja{{ '.tmp-gitlab-ci.yml' }}.jinja
Then adapt src/**/*.jinja for your domain-specific resources.