Module: Kiel

Defined in:
lib/kiel.rb,
lib/kiel/scm/git.rb,
lib/kiel/scm/mock.rb,
lib/kiel/cloud/aws.rb,
lib/kiel/cloud/mock.rb,
lib/kiel/setup/mock.rb,
lib/kiel/setup/capistrano.rb,
lib/kiel/setup/capistrano_executer.rb

Overview

Kiel tries to make the task to create cloud images easier by braking the whole installation into smaller, reproducible tasks. Each step is versioned by a version control system like git or subversion. Each installation step is described by a file containing a capistrano script. Kiel assumes that there is a specific order in which the steps have to be executed.

The purpose of splitting the installation of a machine image into smaller tasks is to save time when debugging the installation and save time, when little changes have to be made to the installation.

If one step fails, all subsequent installation steps might fail too. But when one step succeeds, that step can be used as base for all subsequence steps.

License

Distributes under the MIT license

Defined Under Namespace

Modules: Cloud, SCM, Setup Classes: Implementation

Constant Summary collapse

RECOGNIZED_STEP_OPTIONS =

[ :name, :task, :scm_name, :setup_name, :description ]
DEFAULT_OPTIONS =
{}
RECOGNIZED_OPTIONS =
[ :scm, :cloud, :setup, :base_image, :root_dir ]
OPTIONS =
YAML.load STDIN
TAGS =
OPTIONS[ :tags ]

Class Method Summary collapse

Class Method Details

.defaultsObject

returns the global defaults that are applied to every call to Kiel::image



245
246
247
248
# File 'lib/kiel.rb', line 245

def self.defaults
    @@defaults ||= DEFAULT_OPTIONS.dup
    @@defaults
end

.image(steps, options = {}) ⇒ Object

defines the steps necessary to build an image by constructing Rake::Tasks that depend on each other. The dependencies are defined in the order the steps are given. Every step depends on all other steps following that step in the list of given steps.

Each step produces a new machine image, by starting a server in the cloud with the previous image, adding a defined set of installation instructions and than saving the resulting image for the next step.

Every step is defined by hash with the following keys:

:name

The name of the step. The name is used to name a tag in the resulting image. The value of the tag is the source code version of the sources of that step. By default name is expanded to name.rb in the current directory.

:task

The name of the Rake::Task to be created for that step. If not given, the name is used.

:scm_name

The name that is passed to the source code management to determine the version of the description of the step. If not given, name is expanded to name.rb in the current directory. For the first element this defaults to ‘*’, which is a special notation for the latest version of the repository.

:setup_name

The name of the script to be executed. This defaults to :scm_name if given and not ‘*’ or to :name + ‘.rb’

:description

Optional description for the task to be created.

A step can be given by just one string or symbol, both following lines will result in the same images created.

Kiel::image [ :stepA, :stepB ] 
Kiel::image [ { :name => 'stepA', :task => 'stepA', :scm_name => '*', :setup_name ='stepA.rb' }, 
              { :name => 'stepB', :task => 'stepB', :scm_name => 'stepB.rb' } ]

options is a set of configurations that can be used to override global options set by Kiel::set_defaults. Possible options are:

:scm

An instance of the source code management used to retrieve version informations. By default this will be an instance of Kiel::SCM::Git.

:setup

An instance of the device used to execute steps to execute the installations steps. By default this will be an instance of Kiel::Setup::Capistrano.

:cloud

An instance of the cloud provider to lookup images and to access cloud instances. By default this will be an instance of Kiel::Cloud::AWS

:base_image

A cloud image id that is used as base for the very first step. This is the right most argument in the list of steps.

:root_dir

Root directory, where all file names are bassed on. If the options is not given, the current directory is used

Example:

Kiel::image [ 'application', 'base' ], setup: Kiel::Setup::Capistrano.new, base_image: 'ami-6d555119'

Will assume that every new version in the repository should lead to a new image based on an base image. The layout of the base image is defined by base.rb and the base images is only recreated when the version of base.rb changes. The base image is build by starting a cloud image with the id ‘ami-6d555119’. To setup the base-image, base.rb is executed by a newly created Kiel::Setup::Capistrano instance. The resulting base image will be stored with the tags:

{ 'image_type' => 'base', 'base' => '<version of base.rb>' }.

An application image is build by starting a cloud server with the base image and executing the steps provided by application.rb. The application image is then stored with the following tags:

{ 'iamge_type' => 'application', 'application' => '<version of the overall repository>, 'base' => '<version of base.rb>' }.


217
218
219
220
221
222
223
224
225
226
227
228
229
# File 'lib/kiel.rb', line 217

def self.image steps, options = {} 
    check_options( options ) 
    
    implemenation = Implementation.new defaults().merge( options )
    steps = expand_steps steps
    steps = implemenation.add_versions steps
    
    while !steps.empty? do
        step, *steps = *steps

        implemenation.create_task step.dup, steps.dup
    end
end

.reset_defaultsObject



240
241
242
# File 'lib/kiel.rb', line 240

def self.reset_defaults
    @@defaults = nil
end

.set_defaults(defs) ⇒ Object

set the global defaults that are applied to Kiel::image



234
235
236
237
238
# File 'lib/kiel.rb', line 234

def self.set_defaults defs
    check_options defs
    @@defaults ||= DEFAULT_OPTIONS.dup
    @@defaults.merge! defs
end