class R10K::Action::Deploy::Environment

Public Class Methods

new(opts, argv, settings = {}) click to toggle source
Calls superclass method R10K::Action::Base.new
# File lib/r10k/action/deploy/environment.rb, line 16
def initialize(opts, argv, settings = {})
  @purge = true
  super
  @argv = @argv.map { |arg| arg.gsub(/\W/,'_') }
end

Public Instance Methods

call() click to toggle source
# File lib/r10k/action/deploy/environment.rb, line 22
def call
  @visit_ok = true

  expect_config!
  deployment = R10K::Deployment.new(@settings)
  check_write_lock!(@settings)

  deployment.accept(self)
  @visit_ok
end

Private Instance Methods

allowed_initialize_opts() click to toggle source
# File lib/r10k/action/deploy/environment.rb, line 123
def allowed_initialize_opts
  super.merge(puppetfile: :self, cachedir: :self, purge: true)
end
undeployable_environment_names(environments, expected_names) click to toggle source
# File lib/r10k/action/deploy/environment.rb, line 114
def undeployable_environment_names(environments, expected_names)
  if expected_names.empty?
    []
  else
    known_names = environments.map(&:dirname)
    expected_names - known_names
  end
end
visit_deployment(deployment) { || ... } click to toggle source
# File lib/r10k/action/deploy/environment.rb, line 37
def visit_deployment(deployment)
  # Ensure that everything can be preloaded. If we cannot preload all
  # sources then we can't fully enumerate all environments which
  # could be dangerous. If this fails then an exception will be raised
  # and execution will be halted.
  deployment.preload!
  deployment.validate!

  undeployable = undeployable_environment_names(deployment.environments, @argv)
  if !undeployable.empty?
    @visit_ok = false
    logger.error "Environment(s) \'#{undeployable.join(", ")}\' cannot be found in any source and will not be deployed."
  end

  yield

  deployment.purge! if @purge

ensure
  if (postcmd = @settings[:postrun])
    subproc = R10K::Util::Subprocess.new(postcmd)
    subproc.logger = logger
    subproc.execute
  end
end
visit_environment(environment) { || ... } click to toggle source
# File lib/r10k/action/deploy/environment.rb, line 67
def visit_environment(environment)
  if !(@argv.empty? || @argv.any? { |name| environment.dirname == name })
    logger.debug1("Environment #{environment.dirname} does not match environment name filter, skipping")
    return
  end

  started_at = Time.new

  status = environment.status
  logger.info "Deploying environment #{environment.path}"

  environment.sync
  logger.info "Environment #{environment.dirname} is now at #{environment.signature}"

  if status == :absent || @puppetfile
    if status == :absent
      logger.debug("Environment #{environment.dirname} is new, updating all modules")
    end

    yield
  end

  write_environment_info!(environment, started_at)
end
visit_module(mod) click to toggle source
# File lib/r10k/action/deploy/environment.rb, line 98
def visit_module(mod)
  logger.info "Deploying module #{mod.path}"
  mod.sync
end
visit_puppetfile(puppetfile) { || ... } click to toggle source
# File lib/r10k/action/deploy/environment.rb, line 92
def visit_puppetfile(puppetfile)
  puppetfile.load
  yield
  puppetfile.purge!
end
visit_source(source) { || ... } click to toggle source
# File lib/r10k/action/deploy/environment.rb, line 63
def visit_source(source)
  yield
end
write_environment_info!(environment, started_at) click to toggle source
# File lib/r10k/action/deploy/environment.rb, line 103
def write_environment_info!(environment, started_at)
  File.open("#{environment.path}/.r10k-deploy.json", 'w') do |f|
    deploy_info = environment.info.merge({
      :started_at => started_at,
      :finished_at => Time.new,
    })

    f.puts(JSON.pretty_generate(deploy_info))
  end
end