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/cloud/aws_base.rb,
lib/kiel/cloud/right_aws.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.
Currently there are two different ways to access the AWS API: RightAWS and the aws-sdk gem.
For an introduction in german please visit robitzki.de/blog/Continuous_Deployment_Part_1
- 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
- .default_setup_name(step) ⇒ Object
-
.defaults ⇒ Object
returns the global defaults that are applied to every call to Kiel::image.
-
.image(steps, options = {}) ⇒ Object
defines the
steps
necessary to build an image by constructing Rake::Tasks that depend on each other. - .reset_defaults ⇒ Object
-
.set_defaults(defs) ⇒ Object
set the global defaults that are applied to Kiel::image.
Class Method Details
.default_setup_name(step) ⇒ Object
137 138 139 |
# File 'lib/kiel.rb', line 137 def self.default_setup_name step step[ :scm_name ] == '*' ? "#{step[ :name ]}.rb" : [ step[ :scm_name ] ].flatten.first end |
.defaults ⇒ Object
returns the global defaults that are applied to every call to Kiel::image
281 282 283 284 |
# File 'lib/kiel.rb', line 281 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 toname.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 toname.rb
in the current directory. For the first element this defaults to ‘*’, which is a special notation for the latest version of the repository.It’s possible for :scm_name to be an array of file names. This results in an execution of the step, when every any of the listed file changed.
- :setup_name
-
The name of the script to be executed. This defaults to :scm_name if given and not ‘*’ or to :name + ‘.rb’. If :scm_name is an array, :setup_name defaults to the first element of the array.
So :scm_name => [ ‘run_bundler.rb’, ‘Gemfile’, ‘Gemfile.lock’ ] would default to execute ‘run_bundler.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
. If the given object respond_to?( :call ), the construction can be further deferred until the first time, a call to AWS is issued.
Example:
Kiel::image [ 'a', 'b', 'c' ], cloud: Kiel::Cloud::RightAWS.new( credentials: secrets )
Kiel::image [ 'a', 'b', 'c' ], cloud: lambda{ Kiel::Cloud::RightAWS.new credentials: secrets }
The first version constructs the cloud provider before calling the image(), the second version just passes a lambda that will defer the construction until the cloud provider is actual needed. The later version is especial useful in rakefiles.
- :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>' }.
253 254 255 256 257 258 259 260 261 262 263 264 265 |
# File 'lib/kiel.rb', line 253 def self.image steps, = {} ( ) implemenation = Implementation.new defaults().merge( ) steps = steps steps = implemenation.add_versions steps while !steps.empty? do step, *steps = *steps implemenation.create_task step.dup, steps.dup end end |
.reset_defaults ⇒ Object
276 277 278 |
# File 'lib/kiel.rb', line 276 def self.reset_defaults @@defaults = nil end |
.set_defaults(defs) ⇒ Object
set the global defaults that are applied to Kiel::image
270 271 272 273 274 |
# File 'lib/kiel.rb', line 270 def self.set_defaults defs defs @@defaults ||= DEFAULT_OPTIONS.dup @@defaults.merge! defs end |