Custom Layering
If Lono built-in layering does not work for your needs, you can customize layering.
Custom layering is an advanced use case. It is generally recommended to stick to the Lono conventions, which is already quite powerful, and others won’t have to learn the customization.
Structure
To fully customize layering, you redefine the Lono::Layering
module. Here’s a starter structure:
config/inits/layering.rb
Lono::Layering.module_eval do
# def pre_layers
# []
# end
#
# def main_layers
# super
# end
#
# def post_layers
# []
# end
end
Note: Make sure to use module_eval
or require lono/layering
first. This ensures that the existing Lono Layering definition is first loaded and then you can add your own customizations. You can also use the ActiveSupport.on_load(:lono_layering)
hook instead if you prefer not use module_eval
. Example:
config/inits/layering.rb
ActiveSupport.on_load(:lono_layering) do
module Lono::Layering
# ...
end
end
Interface Methods
There are 3 main interface methods designed to be overridden:
- pre_layers: Layers processed before the main layer. Defaults to an empty Array.
- main_layers: The main layers processed as described by the Lono docs. This includes the base, env, region, and, account layers.
- post_layers: Layers processed after the main layer. Defaults to an empty Array.
You can choose the methods to override.
Example
Let’s override the pre_layers
method as an example:
config/inits/layering.rb
Lono::Layering.module_eval do
def pre_layers
[
"teams/#{ENV['TEAM']}",
]
end
end
The pre_layer
adds a layer using the TEAM
env var. For example:
config/blueprints/demo/params/teams/backend.env
team_scoped_config="team_scoped_config_value"
$ TEAM=backend lono build demo
Also see Debugging Layering.