Class: Deployer::RubyDeployer

Inherits:
BaseDeployer show all
Defined in:
lib/deployer/ruby_deployer.rb

Instance Attribute Summary collapse

Attributes inherited from BaseDeployer

#options, #stage, #stage_path

Instance Method Summary collapse

Constructor Details

#initialize(processor_names, options) ⇒ RubyDeployer

Returns a new instance of RubyDeployer.



4
5
6
7
# File 'lib/deployer/ruby_deployer.rb', line 4

def initialize(processor_names, options)
  super(options)
  @processor_names = processor_names
end

Instance Attribute Details

#processor_namesObject

Returns the value of attribute processor_names.



2
3
4
# File 'lib/deployer/ruby_deployer.rb', line 2

def processor_names
  @processor_names
end

Instance Method Details

#deploy!Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/deployer/ruby_deployer.rb', line 9

def deploy!
  puts "deploying to #{stage.name} via #{deploy_via}".light_blue.on_blue

  Deployer::Executor.new(stage, verbose: verbose?) do |executor|
    create_base_dirs(executor)

    update_cached_copy(executor)

    # fetch processor_names unless they have been passed as an argument to the initializer
    processor_names_to_deploy = resolve_processor_names(executor, options)
    processor_names_to_deploy.sort(& ruby_sorter).each do |processor_name|
      puts
      puts "Deploying #{processor_name}".light_blue.on_blue
      log_deployment(executor, "Deploying #{processor_name} via #{deploy_via} from #{cached_copy_dir}")

      # stop old one
      cmd = inspector_command('stop', processor_name)
      executor.execute(cmd, abort_on_error: false, comment: "Request to stop component")

      # unzip package
      target = deploy_dir('ruby')
      source = cached_copy_dir('ruby',"#{processor_name}.zip")
      executor.execute("rm -rf #{processor_dir(processor_name)} && unzip -o -d #{target} #{source}")

      # copy config
      executor.execute("if [[ -d #{config_source_dir(processor_name)} ]] ; then cp -r #{config_source_dir(processor_name)}/* #{processor_dir(processor_name)}; fi")

      # remove log dir if it exists
      executor.execute("if [[ -d #{processor_dir(processor_name, 'logs')} ]] ; then rm -rf #{processor_dir(processor_name, 'logs')}; fi")

      # symlink log dir
      executor.execute("ln -s #{logs_dir} #{processor_dir(processor_name, 'logs')}")

      # symlink pids dir
      executor.execute("ln -s #{pids_dir} #{processor_dir(processor_name, 'pids')}")

      # install gems
      executor.execute("cd #{processor_dir(processor_name)} && bundle install --without test")

      # start new one
      cmd = inspector_command('start', processor_name)
      executor.execute(cmd, abort_on_error: false, comment: "Request to stop component")
    end
  end
end