Class: Deployer::GoDeployer

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

Instance Attribute Summary collapse

Attributes inherited from BaseDeployer

#options, #stage, #stage_path

Instance Method Summary collapse

Constructor Details

#initialize(processor_names, options) ⇒ GoDeployer

Returns a new instance of GoDeployer.



4
5
6
7
# File 'lib/deployer/go_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/go_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
54
55
56
57
58
59
60
61
# File 'lib/deployer/go_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(& go_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
      if processor_name != 'inspector'
        cmd = inspector_command('stop', processor_name)
        executor.execute(cmd, abort_on_error: false, comment: "Request to stop component")
      else
        executor.execute("kill -s TERM $(cat #{File.join(pids_dir, processor_name)}.pid)", abort_on_error: false, comment: "This is not sooo important")
      end

      # unzip package
      target = deploy_dir('go')
      source = cached_copy_dir('go',"#{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')}")

      # start new one
      if processor_name == 'inspector'
        # default start
        executor.execute("cd #{processor_dir(processor_name)} && ./#{processor_name} -d -e $EH_ENV")
      else
        # startig go via inspector
        cmd = inspector_command('start', processor_name)
        executor.execute(cmd, abort_on_error: false, comment: "Request to start component")
      end
    end
  end
end