Skip to content

Cuttlefish for node_package users

Charlie Voiselle edited this page Oct 5, 2016 · 5 revisions

https://github.com/basho/node_package has built-in optional support for cuttlefish. To integrate cuttlefish into your node_package application, you will need to perform the following steps:

  • Add Cuttlefish to rebar.config
  • Enable the Cuttlefish rebar plugin
  • Inform reltool.config about schema files
  • Enable Cuttlefish in vars.config

rebar.config

You'll need to add cuttlefish as a dependency, which will look something like this:

{cuttlefish, ".*", {git, "git://github.com/basho/cuttlefish", {branch, "master"}}}

and you'll also need to teach it about the cuttlefish_rebar_plugin, like this:

{plugin_dir, "deps/cuttlefish/src"}.
{plugins, [cuttlefish_rebar_plugin]}.

reltool.config

You'll need to tell reltool.config about any schema files you want included. You'll also need to tell reltool.config the priority of those files. Add them to your {overlay, [...]} section, like this:

%% Cuttlefish Schema Files have a priority order. 
%% Anything in a file prefixed with 00- will override
%% anything in a file with a higher numbered prefix.
{template, "files/riak.schema", "lib/00-riak.schema"},
{template, "../deps/<dependency_name>/priv/<schema_name>.schema", "lib/02-<dependency>.schema"},
{template, "files/vm.args", "etc/vm.args"},

The priority is defined as "alphabetical order". which means, if the file is named A.schema, everything in it overrides things in B.schema if there's a conflict. As the reltool.config author, you can determine schema priority by renaming schema files in the template tuple.

Why would you do this? Say we provided a riak_core.schema (and we plan to!), say you like all our setting names for your riak_core application, except one. You could override that one in your own schema! Freedom! Choices! Options! See what I do for you?

vars.config

Everything you've done until now will be for naught if you don't add cuttlefish to your vars.config. Here's how!

{cuttlefish,         "on"}.
{cuttlefish_conf,    "<whatever_you_want_your_default_config_file_to_be_called>.conf"}.

That's it! Truth be told, it could be {cuttlefish, "anything!"}, as all we're checking is that this is not undefined.

Switching to Cuttlefish

Say you're using app.config, like everyone is... when your first cuttlefish compliant version ships, it won't blow away existing app.configs, and if an app.config is present, cuttlefish will short circuit and just use that.