Scaffolding a Repository with Git
Rendering files is half of a golden path. The other half is everything around it: fetching a specific version of the template, recording which version and which answers produced the service, creating the repository, and registering the result in the catalog. Backstage does this with a chain of scaffolder actions (fetch:template → publish:github → catalog:register, see Software Templates); Copier and cookiecutter do the fetch and render on a laptop. This lesson builds the same chain with Git and a shell script, so you can see every step.
The template is a repository with releases
A golden path is software. It lives in its own repository, has tests, and is released with tags. Services are created from a tag, never from whatever main happens to contain, so "which template does this service have?" always has a precise answer.
golden-go-service/ # the platform team's template repository
├── render.sh # the renderer from the previous lesson
└── skeleton/ # files with ${{ values.* }} placeholders
├── .github/workflows/ci.yaml
├── README.md
├── catalog-info.yaml
└── deploy/values.yamlNotice the CI file: it doesn't contain the pipeline. It calls a reusable workflow owned by the platform team (acme/platform-workflows/.github/workflows/go-service.yaml@v3; reusable workflows are covered in CI/CD). That's a second, complementary way to ship a golden path: the logic that should change for everyone at once lives in a shared, versioned workflow, and the service repository holds only a few lines that pick a version. The same goes for a shared Helm library chart.
Scaffolding a service
The session creates the template repository with a v1.0.0 tag, then runs new-service.sh, the script a portal's "Create" button would run. It clones the tag, renders the skeleton with the answers, writes .golden-path.yaml (template, version, answers) into the new service, and makes the first commit:
# ---- the platform team's template repository ----
mkdir -p golden-go-service/skeleton/.github/workflows golden-go-service/skeleton/deploy && cd golden-go-service
cat > render.sh <<'EOF'
#!/bin/bash
# usage: render.sh <skeleton-dir> <answers.yaml> <out-dir>
set -euo pipefail
yq -o=props "$2" | sed -E 's/^([^ ]+) = (.*)$/s|\\$\\{\\{ values.\1 \\}\\}|\2|g/' > "$3.sed"
(cd "$1" && find . -type f) | sort | while read -r f; do
out="$3/$(echo "$f" | sed -E -f "$3.sed")"
mkdir -p "$(dirname "$out")" && sed -E -f "$3.sed" "$1/$f" > "$out"
done
rm "$3.sed"
EOF
chmod +x render.sh
cat > skeleton/README.md <<'EOF'
# ${{ values.name }}
Owned by ${{ values.owner }}. Created from the go-service golden path.
EOF
cat > skeleton/catalog-info.yaml <<'EOF'
apiVersion: backstage.io/v1alpha1
kind: Component
metadata:
name: ${{ values.name }}
spec:
type: service
owner: ${{ values.owner }}
lifecycle: experimental
EOF
cat > skeleton/.github/workflows/ci.yaml <<'EOF'
name: ci
on: [push]
jobs:
build:
uses: acme/platform-workflows/.github/workflows/go-service.yaml@v3
with:
image: ghcr.io/acme/${{ values.name }}
tag: ${{ github.sha }}
EOF
cat > skeleton/deploy/values.yaml <<'EOF'
image: ghcr.io/acme/${{ values.name }}
replicaCount: 2
resources:
requests: {cpu: 50m, memory: 64Mi}
EOF
git init -q && git add . && git commit -qm "go-service golden path" && git tag v1.0.0
cd ..
# ---- the scaffolder: what a "Create" button runs ----
cat > new-service.sh <<'EOF'
#!/bin/bash
# usage: new-service.sh <name> <owner> [template-version]
set -euo pipefail
name=$1 owner=$2 version=${3:-v1.0.0}
tpl=$(mktemp -d)
git clone -q --depth 1 --branch "$version" "file://$PWD/golden-go-service" "$tpl"
printf 'name: %s\nowner: %s\n' "$name" "$owner" > "$tpl/answers.yaml"
"$tpl/render.sh" "$tpl/skeleton" "$tpl/answers.yaml" "$name"
# remember where the service came from, for later template updates
{ echo "template: golden-go-service"; echo "version: $version"; echo "answers:"; sed 's/^/ /' "$tpl/answers.yaml"; } > "$name/.golden-path.yaml"
rm -rf "$tpl"
git -C "$name" init -q
git -C "$name" add .
git -C "$name" commit -qm "Scaffold $name from golden-go-service $version"
echo "created $name"
EOF
chmod +x new-service.sh
./new-service.sh shortlinks team-growth
tree -a --noreport -I .git shortlinks
cat shortlinks/.golden-path.yaml
git -C shortlinks log --oneline
grep -n 'tag:\|image:' shortlinks/.github/workflows/ci.yamlcreated shortlinks
shortlinks
├── .github
│ └── workflows
│ └── ci.yaml
├── .golden-path.yaml
├── README.md
├── catalog-info.yaml
└── deploy
└── values.yaml
template: golden-go-service
version: v1.0.0
answers:
name: shortlinks
owner: team-growth
ae2edac Scaffold shortlinks from golden-go-service v1.0.0
7: image: ghcr.io/acme/shortlinks
8: tag: ${{ github.sha }}
Three details in that output matter:
${{ github.sha }}survived. The renderer only replaces${{ values.* }}, so GitHub Actions expressions in the skeleton pass through untouched. (In a Backstage skeleton, where every${{ }}is Nunjucks, you'd wrap them in{% raw %}…{% endraw %}.).golden-path.yamlis the service's birth certificate. It records the template version and the answers, so the platform can later re-render the same service from a newer template and offer the difference as an update. Copier writes the same thing to.copier-answers.yml; in a Backstage skeleton you can put the template's name and version intocatalog-info.yamlas an annotation, so the catalog knows it too.--depth 1 --branch v1.0.0fetches exactly the tagged release, nothing else.
Publishing and registering
In a real platform the last steps of the script would be:
gh repo create acme/shortlinks --private --source shortlinks --push # or the GitLab API
curl -s -X POST "$BACKSTAGE_URL/api/catalog/locations" \
-H "Authorization: Bearer $BACKSTAGE_TOKEN" -H 'Content-Type: application/json' \
-d '{"type": "url", "target": "https://github.com/acme/shortlinks/blob/main/catalog-info.yaml"}'Plus the things a new repository needs that a file can't express: branch protection, the team as code owners, repository secrets or OIDC trust for CI, and an entry in the GitOps repository so the service gets a namespace and an Argo CD Application. Doing all of that by API, in the same run, is what turns a file generator into a golden path. The Mini Project covers the GitOps part.
Where the scaffolder runs
| Option | Runs | Good for | Watch out for |
|---|---|---|---|
| Backstage scaffolder | in the Backstage backend, triggered from the portal form | the default once you have a portal; results link to the catalog | the backend needs tokens to create repos: protect them like CI secrets |
CI job (workflow_dispatch) |
a pipeline with inputs | no portal yet; the run log is the audit trail | the form is GitHub's, with fewer input types |
CLI (Copier, cookiecutter, a platform new tool) |
the developer's laptop | offline work, quick experiments | nobody records that the service was created; registration is manual |
Test yourself
Why should services be scaffolded from a tagged release of the template rather than from its main branch?
- Tags are faster to clone
- So every service records exactly which template version it came from, which makes updates and audits precise
- Git requires it
- main is read-only
What does the service's .golden-path.yaml enable?
- Faster builds
- Re-rendering the service from a newer template version with the same answers, to offer an update
- Backstage login
- Nothing; it is documentation
The skeleton's CI file only calls acme/platform-workflows/...@v3. What is the advantage?
- None
- Pipeline logic changes for every service by releasing a new workflow version, while each repo still pins the version it uses
- It hides the pipeline from developers
- It avoids YAML