Skip to content

Commit

Permalink
Converted blueprint to us flyweight pattern
Browse files Browse the repository at this point in the history
This change converts the blueprint hook to use the flyweight pattern to
only create one instance of the blueprint per environment. This
facilitates the genesis v3.1.0 release, which allows hooks to run only
once and cache the results for the duration of the genesis run, reducing
the time it takes to run genesis.

Also fixes missing os-conf.yml override in blueprint (that isn't being
used yet due to a bug in genesis v3.0.x releases).
  • Loading branch information
dennisjbell committed Oct 23, 2024
1 parent 95a5291 commit 21576e5
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions hooks/blueprint.pm
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,27 @@ use parent qw(Genesis::Hook::Blueprint);

use Genesis qw/bail info warning error in_array new_enough/;

my %blueprint_for_env = ();
sub init {
my $class = shift;

# Flyweight pattern: only create one instance of the blueprint per environment
my @args = @_;
if ({@_}->{env}) {
my $env_name = {@_}->{env}->name;;
return $blueprint_for_env{$env_name} if $blueprint_for_env{$env_name};
}

my $obj = $class->SUPER::init(@_);
$obj->{features} = [$obj->env->features];
$obj->{files} = [];
$obj->check_minimum_genesis_version('3.0.0-rc.1');
return $obj;
return $blueprint_for_env{$obj->env->name} = $obj;
}

sub perform {
my ($blueprint) = @_; # $blueprint is '$self'

$blueprint->{files} = [];
$blueprint->{ocfp_env_type} = '';
if ($blueprint->want_feature('ocfp')) {
$blueprint->{ocfp_env_type} = ($blueprint->env->name =~ /.*-mgmt.*/)
Expand Down Expand Up @@ -220,6 +229,7 @@ sub perform {
$blueprint->add_files(qw(
bosh-deployment/jumpbox-user.yml
overlay/addons/op-users.yml
overlay/releases/os-conf.yml
)) unless $blueprint->want_feature('skip-op-users');

for my $feature ($blueprint->features) {
Expand Down

0 comments on commit 21576e5

Please sign in to comment.