GithubHelp home page GithubHelp logo

configulator's Introduction

Configulator : Generate Config Files

Build Status

Configurator allows you to maintain a single file with configuration values that can be used to generate other config files based on templates.

For instance, if you need to generate all of the config files for a Hadoop cluster and the files vary in type (xml, json, yaml, etc) but all rely on the same few configuration values, you can use configulator to generate those files.

Configulator is a tool that takes a single master input config file and some number of template files as input and then outputs the template files with the correct configuration values substituted. Additionally, there is a way of specifying default values, and then configulator will override on the necessary ones per environment.

See this blog post for the background on why this can be useful.

Installation

Add this line to your application's Gemfile:

gem 'configulator'

And then execute:

$ bundle

Or install it yourself as:

$ gem install configulator

Usage

Configulator can accept a master config file either in json or yaml. Here's an example config file:

mysql_host: 127.0.0.1
mysql_port: 5678
db_host: <%= mysql_host %>
db_port: <%= mysql_port %>
current_time: <%= Time.now %>

It specifies a mysql host and port, as well as a general db host and port that will simply use the values for mysql. Then, given an example config file that's nasty and written in XML:

<xml><config><host><%= db_host %></host></config></xml>

We can now convert the above file into one with db_host filled in either using code or the configulator command. Here's what the code looks like (assuming our master config is master.yml and our xml is xmlisbad.xml.tmpl):

require 'configulator'
converted = Configulator.from_yaml_file('master.yml').convert_file('xmlisbad.xml')
File.write 'xmlisbad.xml', converted

You can also access specific variables in the ruby code:

puts converted.db_host # => 127.0.0.1

Using the configulator command instead looks like this:

configulator master.yml xmlisbad.xml.tmpl > xmlisbad.xml

Environments

You have the option of setting default values in your master config file and then separate environment sections beneath that. For instance, here's a yaml config file with default values for some keys:

default:
    debug: INFO
    db_host: <%= mysql_host %>
    db_port: <%= mysql_port %>
production:
    mysql_host: 1.2.3.4
    mysql_port: 5678
development:
    mysql_host: 127.0.0.1
    mysql_port: 5678

We can spit out the production values like this (just passing in an extra argument to from_yaml_file):

require 'configulator'
converted = Configulator.from_yaml_file('master.yml', 'production').convert_file('xmlisbad.xml')
File.write 'xmlisbad.xml', converted

When db_host is used in the xml file, configulator will look for it first in the production section and then in the default (where it is found, then repeats process for mysql_host).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.