eventhub-command 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,85 +1,85 @@
1
- class Deployer::MuleDeployer < Deployer::BaseDeployer
2
- attr_reader :adapter_names
3
-
4
- def initialize(adapter_names, options)
5
- super(options)
6
- @adapter_names = adapter_names
7
- end
8
-
9
- def adapter_cached_copy(adapter_name)
10
- cached_copy_dir('mule', "#{adapter_name}.zip")
11
- end
12
-
13
- def config_source_dir(adapter_name)
14
- super('mule', adapter_name)
15
- end
16
-
17
- def deploy!
18
- puts "deploying to #{stage.name} via #{deploy_via}".light_blue.on_blue
19
-
20
- Deployer::Executor.new(stage, verbose: verbose?) do |executor|
21
- create_base_dirs(executor)
22
-
23
- # update
24
- update_cached_copy(executor)
25
-
26
- adapter_names_to_deploy = resolve_adapter_names(executor, options)
27
-
28
- adapter_names_to_deploy.each do |adapter_name|
29
- puts
30
- puts "Deploying #{adapter_name}".light_blue.on_blue
31
- log_deployment(executor, "Deploying #{adapter_name} via #{deploy_via} from #{cached_copy_dir}")
32
- # make a copy of the zip files to merge them with config
33
- cached_copy_source = adapter_cached_copy(adapter_name)
34
- configuration_target = File.join(base_dir, 'mule', "#{adapter_name}.zip")
35
- executor.execute("cp #{cached_copy_source} #{configuration_target}")
36
-
37
- # copy config
38
- config_source = config_source_dir(adapter_name)
39
- executor.execute("if [[ -d #{config_source} ]] ; then cd #{config_source} ; zip -r #{configuration_target} . ; fi")
40
-
41
- # deploy
42
- executor.execute("cp #{adapter_cached_copy(adapter_name)} $MULE_HOME/apps")
43
- end
44
- end
45
- end
46
-
47
-
48
- private
49
-
50
- def resolve_adapter_names(executor, options)
51
- available = remote_ls(executor, options, cached_copy_dir('mule', '*.zip')).map do |name|
52
- File.basename(name, '.zip')
53
- end
54
-
55
- fetched = Array(adapter_names).map do |name|
56
- if name.include?('*') # resolve pattern on remote machine
57
- remote_ls(executor, options, cached_copy_dir('mule', "#{name}.zip"))
58
- else
59
- name
60
- end
61
- end
62
- if fetched.empty? # then fetch all
63
- fetched = available
64
- end
65
-
66
- fetched = fetched.flatten.map do |name|
67
- File.basename(name, '.zip')
68
- end
69
-
70
- verify_deployment_list!(fetched, available)
71
-
72
- fetched
73
- end
74
-
75
- def update_cached_copy(executor)
76
- if via_scp?
77
- source = Eh::Settings.current.releases_dir('mule', '*.zip')
78
- target_dir = cached_copy_dir('mule')
79
- executor.execute("rm -rf #{target_dir}/*.zip && mkdir -p #{target_dir}")
80
- executor.upload(source, target_dir)
81
- else
82
- update_scm(executor)
83
- end
84
- end
85
- end
1
+ class Deployer::MuleDeployer < Deployer::BaseDeployer
2
+ attr_reader :adapter_names
3
+
4
+ def initialize(adapter_names, options)
5
+ super(options)
6
+ @adapter_names = adapter_names
7
+ end
8
+
9
+ def adapter_cached_copy(adapter_name)
10
+ cached_copy_dir('mule', "#{adapter_name}.zip")
11
+ end
12
+
13
+ def config_source_dir(adapter_name)
14
+ super('mule', adapter_name)
15
+ end
16
+
17
+ def deploy!
18
+ puts "deploying to #{stage.name} via #{deploy_via}".light_blue.on_blue
19
+
20
+ Deployer::Executor.new(stage, verbose: verbose?) do |executor|
21
+ create_base_dirs(executor)
22
+
23
+ # update
24
+ update_cached_copy(executor)
25
+
26
+ adapter_names_to_deploy = resolve_adapter_names(executor, options)
27
+
28
+ adapter_names_to_deploy.each do |adapter_name|
29
+ puts
30
+ puts "Deploying #{adapter_name}".light_blue.on_blue
31
+ log_deployment(executor, "Deploying #{adapter_name} via #{deploy_via} from #{cached_copy_dir}")
32
+ # make a copy of the zip files to merge them with config
33
+ cached_copy_source = adapter_cached_copy(adapter_name)
34
+ configuration_target = File.join(base_dir, 'mule', "#{adapter_name}.zip")
35
+ executor.execute("cp #{cached_copy_source} #{configuration_target}")
36
+
37
+ # copy config
38
+ config_source = config_source_dir(adapter_name)
39
+ executor.execute("if [[ -d #{config_source} ]] ; then cd #{config_source} ; zip -r #{configuration_target} . ; fi")
40
+
41
+ # deploy
42
+ executor.execute("cp #{adapter_cached_copy(adapter_name)} $MULE_HOME/apps")
43
+ end
44
+ end
45
+ end
46
+
47
+
48
+ private
49
+
50
+ def resolve_adapter_names(executor, options)
51
+ available = remote_ls(executor, options, cached_copy_dir('mule', '*.zip')).map do |name|
52
+ File.basename(name, '.zip')
53
+ end
54
+
55
+ fetched = Array(adapter_names).map do |name|
56
+ if name.include?('*') # resolve pattern on remote machine
57
+ remote_ls(executor, options, cached_copy_dir('mule', "#{name}.zip"))
58
+ else
59
+ name
60
+ end
61
+ end
62
+ if fetched.empty? # then fetch all
63
+ fetched = available
64
+ end
65
+
66
+ fetched = fetched.flatten.map do |name|
67
+ File.basename(name, '.zip')
68
+ end
69
+
70
+ verify_deployment_list!(fetched, available)
71
+
72
+ fetched
73
+ end
74
+
75
+ def update_cached_copy(executor)
76
+ if via_scp?
77
+ source = Eh::Settings.current.releases_dir('mule', '*.zip')
78
+ target_dir = cached_copy_dir('mule')
79
+ executor.execute("rm -rf #{target_dir}/*.zip && mkdir -p #{target_dir}")
80
+ executor.upload(source, target_dir)
81
+ else
82
+ update_scm(executor)
83
+ end
84
+ end
85
+ end
@@ -1,37 +1,37 @@
1
- class Net::SSH::Connection::Session
2
-
3
- def exec_sc!(command)
4
- stdout_data,stderr_data = "",""
5
- exit_code, exit_signal = nil,nil
6
- self.open_channel do |channel|
7
- channel.exec(command) do |_, success|
8
- raise "Command \"#{command}\" was unable to execute" unless success
9
-
10
- channel.on_data do |_, data|
11
- stdout_data += data
12
- end
13
-
14
- channel.on_extended_data do |_, _, data|
15
- stderr_data += data
16
- end
17
-
18
- channel.on_request("exit-status") do |_, data|
19
- exit_code = data.read_long
20
- end
21
-
22
- channel.on_request("exit-signal") do |_, data|
23
- exit_signal = data.read_long
24
- end
25
- end
26
- end
27
- self.loop
28
- raise stderr_data unless exit_code == 0
29
-
30
- {
31
- stdout: stdout_data,
32
- stderr: stderr_data,
33
- exit_code: exit_code,
34
- exit_signal: exit_signal
35
- }
36
- end
37
- end
1
+ class Net::SSH::Connection::Session
2
+
3
+ def exec_sc!(command)
4
+ stdout_data,stderr_data = "",""
5
+ exit_code, exit_signal = nil,nil
6
+ self.open_channel do |channel|
7
+ channel.exec(command) do |_, success|
8
+ raise "Command \"#{command}\" was unable to execute" unless success
9
+
10
+ channel.on_data do |_, data|
11
+ stdout_data += data
12
+ end
13
+
14
+ channel.on_extended_data do |_, _, data|
15
+ stderr_data += data
16
+ end
17
+
18
+ channel.on_request("exit-status") do |_, data|
19
+ exit_code = data.read_long
20
+ end
21
+
22
+ channel.on_request("exit-signal") do |_, data|
23
+ exit_signal = data.read_long
24
+ end
25
+ end
26
+ end
27
+ self.loop
28
+ raise stderr_data unless exit_code == 0
29
+
30
+ {
31
+ stdout: stdout_data,
32
+ stderr: stderr_data,
33
+ exit_code: exit_code,
34
+ exit_signal: exit_signal
35
+ }
36
+ end
37
+ end
@@ -1,111 +1,111 @@
1
- class Deployer::RubyDeployer < Deployer::BaseDeployer
2
- attr_accessor :processor_names
3
-
4
- def initialize(processor_names, options)
5
- super(options)
6
- @processor_names = processor_names
7
- end
8
-
9
- def deploy!
10
- puts "deploying to #{stage.name} via #{deploy_via}".light_blue.on_blue
11
-
12
- Deployer::Executor.new(stage, verbose: verbose?) do |executor|
13
- create_base_dirs(executor)
14
-
15
-
16
- update_cached_copy(executor)
17
-
18
-
19
- # fetch processor_names unless they have been passed as an argument to the initializer
20
- processor_names_to_deploy = resolve_processor_names(executor, options)
21
- processor_names_to_deploy.each do |processor_name|
22
- puts
23
- puts "Deploying #{processor_name}".light_blue.on_blue
24
- log_deployment(executor, "Deploying #{processor_name} via #{deploy_via} from #{cached_copy_dir}")
25
- # stop old one
26
- executor.execute("kill -s TERM $(cat #{File.join(pids_dir, processor_name)}.pid)", abort_on_error: false, comment: "This is not sooo important")
27
-
28
- # unzip package
29
- target = deploy_dir('ruby')
30
- source = cached_copy_dir('ruby',"#{processor_name}.zip")
31
- executor.execute("rm -rf #{processor_dir(processor_name)} && unzip -o -d #{target} #{source}")
32
-
33
- # copy config
34
- executor.execute("if [[ -d #{config_source_dir(processor_name)} ]] ; then cp -r #{config_source_dir(processor_name)}/* #{processor_dir(processor_name)}; fi")
35
-
36
- # symlink log dir
37
- executor.execute("ln -s #{logs_dir} #{processor_dir(processor_name, 'logs')}")
38
-
39
- # symlink pids dir
40
- executor.execute("ln -s #{pids_dir} #{processor_dir(processor_name, 'pids')}")
41
-
42
- # install gems
43
- executor.execute("cd #{processor_dir(processor_name)} && bundle install --without test")
44
-
45
- # start new one
46
- executor.execute("cd #{processor_dir(processor_name)} && bundle exec ruby #{processor_name}.rb -d -e $EH_ENV")
47
- end
48
- end
49
- end
50
-
51
- private
52
-
53
- def update_cached_copy(executor)
54
- if via_scp?
55
- source = Eh::Settings.current.releases_dir('ruby', '*.zip')
56
- target_dir = File.join(cached_copy_dir, 'ruby')
57
- executor.execute("rm -rf #{target_dir}/*.zip && mkdir -p #{target_dir}")
58
- executor.upload(source, target_dir)
59
- else
60
- update_scm(executor)
61
- end
62
- end
63
-
64
- def logs_dir
65
- File.join(base_dir, 'shared', 'logs')
66
- end
67
-
68
- def pids_dir
69
- File.join(base_dir, 'shared', 'pids')
70
- end
71
-
72
- def deploy_dir(*extra_paths)
73
- File.join(base_dir, *extra_paths)
74
- end
75
-
76
- def processor_dir(*extra_paths)
77
- File.join(deploy_dir, 'ruby', *extra_paths)
78
- end
79
-
80
- def config_source_dir(processor_name)
81
- super('ruby', processor_name)
82
- end
83
-
84
- # Detect what processors to deploy
85
- #
86
- def resolve_processor_names(executor, options)
87
- available = remote_ls(executor, options, File.join(cached_copy_dir, 'ruby', '*.zip')).map do |name|
88
- File.basename(name, '.zip')
89
- end
90
-
91
- fetched = Array(processor_names).map do |name|
92
- if name.include?('*') # resolve pattern on remote machine
93
- remote_ls(executor, options, File.join(cached_copy_dir, 'ruby', "#{name}.zip"))
94
- else
95
- name
96
- end
97
- end
98
- if fetched.empty? # then fetch all
99
- fetched = available
100
- end
101
-
102
- fetched = fetched.flatten.map do |name|
103
- File.basename(name, '.zip')
104
- end
105
-
106
- verify_deployment_list!(fetched, available)
107
-
108
- fetched
109
- end
110
-
111
- end
1
+ class Deployer::RubyDeployer < Deployer::BaseDeployer
2
+ attr_accessor :processor_names
3
+
4
+ def initialize(processor_names, options)
5
+ super(options)
6
+ @processor_names = processor_names
7
+ end
8
+
9
+ def deploy!
10
+ puts "deploying to #{stage.name} via #{deploy_via}".light_blue.on_blue
11
+
12
+ Deployer::Executor.new(stage, verbose: verbose?) do |executor|
13
+ create_base_dirs(executor)
14
+
15
+
16
+ update_cached_copy(executor)
17
+
18
+
19
+ # fetch processor_names unless they have been passed as an argument to the initializer
20
+ processor_names_to_deploy = resolve_processor_names(executor, options)
21
+ processor_names_to_deploy.each do |processor_name|
22
+ puts
23
+ puts "Deploying #{processor_name}".light_blue.on_blue
24
+ log_deployment(executor, "Deploying #{processor_name} via #{deploy_via} from #{cached_copy_dir}")
25
+ # stop old one
26
+ executor.execute("kill -s TERM $(cat #{File.join(pids_dir, processor_name)}.pid)", abort_on_error: false, comment: "This is not sooo important")
27
+
28
+ # unzip package
29
+ target = deploy_dir('ruby')
30
+ source = cached_copy_dir('ruby',"#{processor_name}.zip")
31
+ executor.execute("rm -rf #{processor_dir(processor_name)} && unzip -o -d #{target} #{source}")
32
+
33
+ # copy config
34
+ executor.execute("if [[ -d #{config_source_dir(processor_name)} ]] ; then cp -r #{config_source_dir(processor_name)}/* #{processor_dir(processor_name)}; fi")
35
+
36
+ # symlink log dir
37
+ executor.execute("ln -s #{logs_dir} #{processor_dir(processor_name, 'logs')}")
38
+
39
+ # symlink pids dir
40
+ executor.execute("ln -s #{pids_dir} #{processor_dir(processor_name, 'pids')}")
41
+
42
+ # install gems
43
+ executor.execute("cd #{processor_dir(processor_name)} && bundle install --without test")
44
+
45
+ # start new one
46
+ executor.execute("cd #{processor_dir(processor_name)} && bundle exec ruby #{processor_name}.rb -d -e $EH_ENV")
47
+ end
48
+ end
49
+ end
50
+
51
+ private
52
+
53
+ def update_cached_copy(executor)
54
+ if via_scp?
55
+ source = Eh::Settings.current.releases_dir('ruby', '*.zip')
56
+ target_dir = File.join(cached_copy_dir, 'ruby')
57
+ executor.execute("rm -rf #{target_dir}/*.zip && mkdir -p #{target_dir}")
58
+ executor.upload(source, target_dir)
59
+ else
60
+ update_scm(executor)
61
+ end
62
+ end
63
+
64
+ def logs_dir
65
+ File.join(shared_dir, 'logs')
66
+ end
67
+
68
+ def pids_dir
69
+ File.join(shared_dir, 'pids')
70
+ end
71
+
72
+ def deploy_dir(*extra_paths)
73
+ File.join(base_dir, *extra_paths)
74
+ end
75
+
76
+ def processor_dir(*extra_paths)
77
+ File.join(deploy_dir, 'ruby', *extra_paths)
78
+ end
79
+
80
+ def config_source_dir(processor_name)
81
+ super('ruby', processor_name)
82
+ end
83
+
84
+ # Detect what processors to deploy
85
+ #
86
+ def resolve_processor_names(executor, options)
87
+ available = remote_ls(executor, options, File.join(cached_copy_dir, 'ruby', '*.zip')).map do |name|
88
+ File.basename(name, '.zip')
89
+ end
90
+
91
+ fetched = Array(processor_names).map do |name|
92
+ if name.include?('*') # resolve pattern on remote machine
93
+ remote_ls(executor, options, File.join(cached_copy_dir, 'ruby', "#{name}.zip"))
94
+ else
95
+ name
96
+ end
97
+ end
98
+ if fetched.empty? # then fetch all
99
+ fetched = available
100
+ end
101
+
102
+ fetched = fetched.flatten.map do |name|
103
+ File.basename(name, '.zip')
104
+ end
105
+
106
+ verify_deployment_list!(fetched, available)
107
+
108
+ fetched
109
+ end
110
+
111
+ end
@@ -1,27 +1,27 @@
1
- class Deployer::Stage
2
- attr_reader :name, :hosts
3
-
4
- def initialize(name)
5
- @name = name
6
- @hosts = []
7
- end
8
-
9
- def host(host, port, user)
10
- @hosts << {
11
- host: host,
12
- port: port,
13
- user: user
14
- }
15
- end
16
-
17
- def self.load(file)
18
- data = YAML.load_file(file)
19
- data.map do |name, config|
20
- stage = Deployer::Stage.new(name)
21
- config['hosts'].each do |host|
22
- stage.host(host['host'], host['port'], host['user'])
23
- end
24
- stage
25
- end.first
26
- end
27
- end
1
+ class Deployer::Stage
2
+ attr_reader :name, :hosts
3
+
4
+ def initialize(name)
5
+ @name = name
6
+ @hosts = []
7
+ end
8
+
9
+ def host(host, port, user)
10
+ @hosts << {
11
+ host: host,
12
+ port: port,
13
+ user: user
14
+ }
15
+ end
16
+
17
+ def self.load(file)
18
+ data = YAML.load_file(file)
19
+ data.map do |name, config|
20
+ stage = Deployer::Stage.new(name)
21
+ config['hosts'].each do |host|
22
+ stage.host(host['host'], host['port'], host['user'])
23
+ end
24
+ stage
25
+ end.first
26
+ end
27
+ end
data/lib/deployer.rb CHANGED
@@ -1,11 +1,11 @@
1
- module Deployer
2
- end
3
-
4
- require_relative 'deployer/executor'
5
- require_relative 'deployer/net_ssh_extension'
6
- require_relative 'deployer/stage'
7
-
8
- require_relative 'deployer/base_deployer'
9
- require_relative 'deployer/mule_deployer'
10
- require_relative 'deployer/ruby_deployer'
11
- require_relative 'deployer/config_deployer'
1
+ module Deployer
2
+ end
3
+
4
+ require_relative 'deployer/executor'
5
+ require_relative 'deployer/net_ssh_extension'
6
+ require_relative 'deployer/stage'
7
+
8
+ require_relative 'deployer/base_deployer'
9
+ require_relative 'deployer/mule_deployer'
10
+ require_relative 'deployer/ruby_deployer'
11
+ require_relative 'deployer/config_deployer'
@@ -1,51 +1,51 @@
1
- desc 'Copies the config directory of a given processor to remote'
2
- command :copy_config do |c|
3
- c.flag([:s, :source], :desc => "Source config directory", :default_value => Eh::Settings.current.source_config_dir, :long_desc => "A local directory containing subfolders for each of the processors")
4
- c.flag([:p, :processors], :desc => "Specify what processors' configs to copy", :type => Array, :long_desc => "You can specify multiple processors by providing a comma-separated list.")
5
-
6
- c.action do |global_options, options, args|
7
- source_config_dir = options['s']
8
- repository_deployment_dir = File.join(Eh::Settings.current.repository_root_dir, "branches", "master", "src", "deployment")
9
-
10
- processor_names = Dir["#{source_config_dir}/*"].map do |dir|
11
- File.basename(dir)
12
- end
13
-
14
- included_processor_names = processor_names
15
-
16
- # only include processors specified by -p option, if option is given
17
- if options['p']
18
- included_processor_names = included_processor_names.select do |processor_name|
19
- options['p'].include?(processor_name)
20
- end
21
- end
22
-
23
- # make sure we have at least one processor
24
- if included_processor_names.empty?
25
- raise "There are no processor configs to copy. Either there is nothing in #{source_config_dir} or the processor(s) specified with -p don't exist."
26
- end
27
-
28
- included_processor_names.each do |processor_name|
29
- processor_config_source_dir = File.join(source_config_dir, processor_name)
30
-
31
- cmd = "cd #{repository_deployment_dir} && COPY_FROM_DIR=#{processor_config_source_dir} bundle exec cap event_hub:scp_copy_config"
32
-
33
- puts "Will copy config files from #{processor_config_source_dir} to remote."
34
- puts "WARNING: This will overwrite any existing files with the same name!"
35
- puts "Do you really want to do this?"
36
- input = STDIN.gets.chomp
37
-
38
- unless ['y', 'Y'].include?(input)
39
- raise "Not confirmed. Stop."
40
- end
41
-
42
- puts "Command: #{cmd}" if global_options['v']
43
-
44
- Bundler.with_clean_env do
45
- system cmd
46
- end
47
- end
48
-
49
- puts "Done."
50
- end
51
- end
1
+ desc 'Copies the config directory of a given processor to remote'
2
+ command :copy_config do |c|
3
+ c.flag([:s, :source], :desc => "Source config directory", :default_value => Eh::Settings.current.source_config_dir, :long_desc => "A local directory containing subfolders for each of the processors")
4
+ c.flag([:p, :processors], :desc => "Specify what processors' configs to copy", :type => Array, :long_desc => "You can specify multiple processors by providing a comma-separated list.")
5
+
6
+ c.action do |global_options, options, args|
7
+ source_config_dir = options['s']
8
+ repository_deployment_dir = File.join(Eh::Settings.current.repository_root_dir, "branches", "master", "src", "deployment")
9
+
10
+ processor_names = Dir["#{source_config_dir}/*"].map do |dir|
11
+ File.basename(dir)
12
+ end
13
+
14
+ included_processor_names = processor_names
15
+
16
+ # only include processors specified by -p option, if option is given
17
+ if options['p']
18
+ included_processor_names = included_processor_names.select do |processor_name|
19
+ options['p'].include?(processor_name)
20
+ end
21
+ end
22
+
23
+ # make sure we have at least one processor
24
+ if included_processor_names.empty?
25
+ raise "There are no processor configs to copy. Either there is nothing in #{source_config_dir} or the processor(s) specified with -p don't exist."
26
+ end
27
+
28
+ included_processor_names.each do |processor_name|
29
+ processor_config_source_dir = File.join(source_config_dir, processor_name)
30
+
31
+ cmd = "cd #{repository_deployment_dir} && COPY_FROM_DIR=#{processor_config_source_dir} bundle exec cap event_hub:scp_copy_config"
32
+
33
+ puts "Will copy config files from #{processor_config_source_dir} to remote."
34
+ puts "WARNING: This will overwrite any existing files with the same name!"
35
+ puts "Do you really want to do this?"
36
+ input = STDIN.gets.chomp
37
+
38
+ unless ['y', 'Y'].include?(input)
39
+ raise "Not confirmed. Stop."
40
+ end
41
+
42
+ puts "Command: #{cmd}" if global_options['v']
43
+
44
+ Bundler.with_clean_env do
45
+ system cmd
46
+ end
47
+ end
48
+
49
+ puts "Done."
50
+ end
51
+ end