feat: global recipe templates — run once per host, depend on per-domain#63
Draft
troglodyne-bot wants to merge 1 commit into
Draft
Conversation
Recipes can now define a $recipe.global.tt alongside their per-domain $recipe.tt. The global template is rendered into a separate make target (/etc/provisioner/state/_global/$module) that runs only once regardless of how many domains share the same host. Per-domain targets depend on their global counterpart when one exists. Adds has_global_template()/render_global() to Provisioner::Recipe. Updates new_config to collect global fragments and pass them to makefile.tt. Splits nginxproxy.tt into global (sysctl, worker_connections, global.conf, apache2 removal) and per-domain (vhost, ACME dir) parts as the canonical example of the pattern. Closes Troglodyne-Internet-Widgets#33 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
teodesian
reviewed
Jun 2, 2026
|
|
||
| =cut | ||
|
|
||
| sub has_global_template { |
Contributor
There was a problem hiding this comment.
more concisely written as
sub has_global_template {
my ($self) = @_;
return any { -f "$_/$self->{global_template}" } @{ $self->{template_dirs} };
}
Contributor
|
@troglodyne-bot rebase |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Add support for
$recipe.global.tttemplate files that render into host-scoped make targets, distinct from the per-domain$recipe.ttfragments that already exist.Why
When multiple domains share a host (via
_shared), global recipe steps — package installs, sysctl tuning, daemon config — ran once per domain. This created redundant operations and forced every template author to add their own idempotency guards for the host-global parts. Issue #33 asked for a clean structural split instead.How
Provisioner::Recipegainshas_global_template()(filesystem check across template dirs) andrender_global()(delegates torender_filewith the.global.ttname).new_configcollects global fragments in a parallel%global_fragmentshash and passes it — alongsideglobal_state_dir(/etc/provisioner/state/_global) — tomakefile.tt.makefile.ttemits global targets underglobal_state_dirwhen any exist. Per-domain targets gain an explicit dependency on their global counterpart ($state_dir/$module: $global_state_dir/$module) when one is present.nginxproxy.ttis split into the first real example: sysctl, worker_connections tuning, global.conf install, and apache2 removal move tonginxproxy.global.tt; only the vhost and ACME dir setup remain per-domain.Testing
t/global_templates.tcovershas_global_template(file present/absent, multi-dir search) and rendering paths; skips gracefully whenText::Xslateis absent from the test environment.nginxproxysplit serves as a live integration test when provisioning a shared-host nginx setup.🤖 Generated with Claude Code