KumoConfig Build status Code Climate

A utility for resolving environment configuration.

Installation

This gem is automatically installed in the kumo container, so any apply-env or deploy scripts have access to it.

Add this line to your application's Gemfile:

gem 'kumo_config'

And then execute:

$ bundle

Or install it yourself as:

$ gem install kumo_config

Usage

Basic Usage

The basic usage will give you an EnvironmentConfig based on the paths you specify.

config_path: Where environments' configuration files live, e.g. production.yml, staging.yml, production_secrets.yml, staging_secrets.yml template_path: Where the CloudFormation template lives - TODO: THIS BELONGS IN KUMO_KEISEI, NOT HERE params_template_file_path: The location of the template for submitting paramters to CloudFormation. AGAIN, THIS DOES NOT BELONG HERE injected_config: A Hash containing any configuration you want to inject at runtime rather than loading from a file. For example, you might want to pull some settings from a VPC.

EnvironmentConfig.new(
  config_path: File.join('/app', 'env', 'config'),
  template_path: File.join('/app', 'env', 'cloudformation', 'redbubble.json'),
  params_template_file_path: File.join('/app', 'env', 'cloudformation', 'redbubble.yml.erb')
  injected_config: { key: 'value' }
)

Configuration Hierarchy

Configuration will be loaded from the following sources:

  1. common.yml and common_secrets.yml if they exist.
  2. {environment}.yml and {environment}_secrets.yml or development.yml and development_secrets.yml if environment specific config does not exist.

Injecting Configuration

You can also inject configuration at run time by adding it to the object provided to the apply! call:

stack_config = {
  config_path: File.join('/app', 'env', 'config'),
  template_path: File.join('/app', 'env', 'cloudformation', 'myapp.json'),
  injected_config: {
    'Seed' => random_seed,
  }
}
stack.apply!(stack_config)

Getting the configuration and secrets without an apply!

If you need to inspect the configuration without applying a stack, call config:

stack_config = {
  config_path: File.join('/app', 'env', 'config'),
  template_path: File.join('/app', 'env', 'cloudformation', 'myapp.json'),
  injected_config: {
    'Seed' => random_seed,
  }
}
marshalled_config = stack.config(stack_config)
marshalled_secrets = stack.plain_text_secrets(stack_config)

if marshalled_config['DB_HOST'].start_with? '192.' then
  passwd = marshalled_secrets['DB_PASS']
  ...
end

Dependencies

Ruby Versions

This gem is tested with Ruby (MRI) versions 1.9.3 and 2.2.3.

Release

  1. Upgrade version in VERSION
  2. Run ./script/release-gem

Contributing

  1. Fork it ( https://github.com/[my-github-username]/kumo_config/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Automated AWS Integration Tests - TODO: REVISE

You can test the Cloudformation responsibilities of this gem by extending the integration tests at spec/integration.

To run these tests you need a properly configured AWS environment (with AWS_DEFAULT_REGION, AWS_ACCESS_KEY and AWS_SECRET_ACCESS_KEY set) and then run ./script/integration_test.sh.

If you run this within a Buildkite job then you will have a stack named "kumokeisei-test-$buildnumber" created and torn down for each integration test context. If you run this outside of a Buildkite job then the stack will be named "kumokeisei-test-$username".

Manual testing with Kumo Tools container

Changes to the gem can be manually tested end to end in a project that uses the gem (i.e. http-wala).

  1. First start the dev-tools container: kumo tools debug non-production
  2. gem install specific_install
  3. Re-install the gem: gem specific_install https://github.com/redbubble/kumo_keisei_gem.git -b <your_branch>
  4. Fire up a console: irb
  5. Require the gem: require "kumo_keisei"
  6. Interact with the gem's classes. KumoKeisei::Stack.new(...).apply!