module Luban::Deployment::Service::Configurator::Base

Public Instance Methods

available_profile_templates(format: "erb") click to toggle source
# File lib/luban/deployment/cli/service/configurator.rb, line 21
def available_profile_templates(format: "erb")
  return @available_profile_templates unless @available_profile_templates.nil?
  templates = []
  [profile_templates_path, stage_profile_templates_path].each do |path|
    Dir.chdir(path) { templates |= Dir["**/*.#{format}"] } if path.directory?
  end
  @available_profile_templates = templates
end
default_templates() click to toggle source
# File lib/luban/deployment/cli/service/configurator.rb, line 42
def default_templates; task.opts.default_templates; end
exclude_template?(template) click to toggle source
# File lib/luban/deployment/cli/service/configurator.rb, line 40
def exclude_template?(template); false; end
excluded_profile_templates(format: "erb") click to toggle source
# File lib/luban/deployment/cli/service/configurator.rb, line 35
def excluded_profile_templates(format: "erb")
  @excluded_profile_templates ||= 
    available_profile_templates(format: format).select { |t| exclude_template?(t) }
end
init_profile() click to toggle source
# File lib/luban/deployment/cli/service/configurator.rb, line 44
def init_profile
  return if default_templates.empty?
  puts "  Initializing #{service_name} profile"
  assure_dirs(profile_templates_path, stage_profile_path)
  upload_profile_templates(default_templates)
end
profile_templates(format: "erb") click to toggle source
# File lib/luban/deployment/cli/service/configurator.rb, line 30
def profile_templates(format: "erb")
  @profile_templates ||= 
    available_profile_templates(format: format).reject { |t| exclude_template?(t) }
end
profile_templates_path() click to toggle source
# File lib/luban/deployment/cli/service/configurator.rb, line 11
def profile_templates_path
  @profile_templates_path ||= 
    config_finder[:application].profile_templates_path.join(profile_name)
end
stage_profile_path() click to toggle source
# File lib/luban/deployment/cli/service/configurator.rb, line 6
def stage_profile_path
  @stage_profile_path ||= 
    config_finder[:application].stage_profile_path.join(profile_name)
end
stage_profile_templates_path() click to toggle source
# File lib/luban/deployment/cli/service/configurator.rb, line 16
def stage_profile_templates_path
  @stage_profile_templates_path ||= 
    config_finder[:application].stage_profile_templates_path.join(profile_name)
end
update_profile() click to toggle source
# File lib/luban/deployment/cli/service/configurator.rb, line 51
def update_profile
  assure_dirs(stage_profile_path)
  render_profile
  cleanup_profile
end

Protected Instance Methods

cleanup_profile() click to toggle source
# File lib/luban/deployment/cli/service/configurator.rb, line 116
def cleanup_profile
  excluded_profile_templates.each do |template_file|
    profile_file = stage_profile_path.join(template_file).sub_ext('')
    rm(profile_file) if file?(profile_file)
  end
end
init() click to toggle source
Calls superclass method
# File lib/luban/deployment/cli/service/configurator.rb, line 59
def init
  super
  if dockerized?
    init_docker_workdir
    init_docker_entrypoint
    init_docker_command
  end
end
init_docker_command() click to toggle source
# File lib/luban/deployment/cli/service/configurator.rb, line 73
def init_docker_command; end
init_docker_entrypoint() click to toggle source
# File lib/luban/deployment/cli/service/configurator.rb, line 72
def init_docker_entrypoint; end
init_docker_workdir() click to toggle source
# File lib/luban/deployment/cli/service/configurator.rb, line 68
def init_docker_workdir
  docker_workdir app_path
end
render_profile() click to toggle source
# File lib/luban/deployment/cli/service/configurator.rb, line 104
def render_profile
  profile_templates.each { |template_file| render_profile_by_template(template_file) }
end
render_profile_by_template(template_file) click to toggle source
# File lib/luban/deployment/cli/service/configurator.rb, line 108
def render_profile_by_template(template_file)
  profile_file = stage_profile_path.join(template_file).sub_ext('')
  assure_dirs(profile_file.dirname)
  upload_by_template(file_to_upload: profile_file,
                     template_file: find_template_file(File.join(profile_name, template_file)),
                     auto_revision: true)
end
upload_profile_templates(templates, dirs: Pathname.new(''), depth: 2) click to toggle source
# File lib/luban/deployment/cli/service/configurator.rb, line 75
def upload_profile_templates(templates, dirs: Pathname.new(''), depth: 2)
  indent = '  ' * depth
  templates.each do |src_path|
    basename = src_path.basename
    print indent + "- #{basename}"

    if directory?(src_path)
      [profile_templates_path, stage_profile_path].each do |p|
        assure_dirs(p.join(dirs).join(basename))
      end
      puts
      upload_profile_templates(src_path.children, dirs: dirs.join(basename), depth: depth + 1)
      next
    end

    dst_path = if src_path.extname == '.erb'
                 profile_templates_path
               else
                 stage_profile_path
               end.join(dirs).join(basename)
    if file?(dst_path)
      puts " [skipped]"
    else
      upload!(src_path, dst_path)
      puts " [created]"
    end
  end
end