aws-codedeploy-agent 0.0.1

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.
Files changed (84) hide show
  1. data/.gitignore +2 -0
  2. data/CHANGES.md +3 -0
  3. data/Gemfile +13 -0
  4. data/LICENSE +177 -0
  5. data/NOTICE +2 -0
  6. data/README.md +16 -0
  7. data/aws-codedeploy-agent.gemspec +39 -0
  8. data/bin/codedeploy-agent +78 -0
  9. data/bin/codedeploy-install +15 -0
  10. data/bin/codedeploy-uninstall +13 -0
  11. data/certs/host-agent-deployment-signer-ca-chain.pem +76 -0
  12. data/conf/codedeployagent.yml +9 -0
  13. data/init.d/codedeploy-agent +61 -0
  14. data/lib/core_ext.rb +71 -0
  15. data/lib/instance_agent.rb +35 -0
  16. data/lib/instance_agent/agent/base.rb +34 -0
  17. data/lib/instance_agent/codedeploy_plugin/application_specification/ace_info.rb +133 -0
  18. data/lib/instance_agent/codedeploy_plugin/application_specification/acl_info.rb +163 -0
  19. data/lib/instance_agent/codedeploy_plugin/application_specification/application_specification.rb +142 -0
  20. data/lib/instance_agent/codedeploy_plugin/application_specification/context_info.rb +23 -0
  21. data/lib/instance_agent/codedeploy_plugin/application_specification/file_info.rb +23 -0
  22. data/lib/instance_agent/codedeploy_plugin/application_specification/linux_permission_info.rb +121 -0
  23. data/lib/instance_agent/codedeploy_plugin/application_specification/mode_info.rb +66 -0
  24. data/lib/instance_agent/codedeploy_plugin/application_specification/range_info.rb +134 -0
  25. data/lib/instance_agent/codedeploy_plugin/application_specification/script_info.rb +27 -0
  26. data/lib/instance_agent/codedeploy_plugin/codedeploy_control.rb +72 -0
  27. data/lib/instance_agent/codedeploy_plugin/command_executor.rb +357 -0
  28. data/lib/instance_agent/codedeploy_plugin/command_poller.rb +146 -0
  29. data/lib/instance_agent/codedeploy_plugin/deployment_specification.rb +150 -0
  30. data/lib/instance_agent/codedeploy_plugin/hook_executor.rb +206 -0
  31. data/lib/instance_agent/codedeploy_plugin/install_instruction.rb +374 -0
  32. data/lib/instance_agent/codedeploy_plugin/installer.rb +143 -0
  33. data/lib/instance_agent/codedeploy_plugin/request_helper.rb +28 -0
  34. data/lib/instance_agent/config.rb +43 -0
  35. data/lib/instance_agent/log.rb +3 -0
  36. data/lib/instance_agent/platform.rb +17 -0
  37. data/lib/instance_agent/platform/linux_util.rb +57 -0
  38. data/lib/instance_agent/runner/child.rb +57 -0
  39. data/lib/instance_agent/runner/master.rb +103 -0
  40. data/lib/instance_metadata.rb +47 -0
  41. data/test/certificate_helper.rb +120 -0
  42. data/test/helpers/instance_agent_helper.rb +25 -0
  43. data/test/instance_agent/agent/base_test.rb +49 -0
  44. data/test/instance_agent/codedeploy_plugin/application_specification_test.rb +1710 -0
  45. data/test/instance_agent/codedeploy_plugin/codedeploy_control_test.rb +51 -0
  46. data/test/instance_agent/codedeploy_plugin/command_executor_test.rb +513 -0
  47. data/test/instance_agent/codedeploy_plugin/command_poller_test.rb +459 -0
  48. data/test/instance_agent/codedeploy_plugin/deployment_specification_test.rb +335 -0
  49. data/test/instance_agent/codedeploy_plugin/hook_executor_test.rb +250 -0
  50. data/test/instance_agent/codedeploy_plugin/install_instruction_test.rb +566 -0
  51. data/test/instance_agent/codedeploy_plugin/installer_test.rb +519 -0
  52. data/test/instance_agent/codedeploy_plugin/request_helper_test.rb +37 -0
  53. data/test/instance_agent/config_test.rb +64 -0
  54. data/test/instance_agent/runner/child_test.rb +87 -0
  55. data/test/instance_metadata_test.rb +97 -0
  56. data/test/test_helper.rb +16 -0
  57. data/vendor/gems/.codedeploy-commands-1.0.0.created.rid +1 -0
  58. data/vendor/gems/codedeploy-commands/apis/CodeDeployCommand.api.json +372 -0
  59. data/vendor/gems/codedeploy-commands/codedeploy-commands-1.0.0.gemspec +28 -0
  60. data/vendor/gems/codedeploy-commands/lib/aws/codedeploy_commands.rb +18 -0
  61. data/vendor/gems/codedeploy-commands/lib/aws/plugins/certificate_authority.rb +12 -0
  62. data/vendor/gems/codedeploy-commands/lib/aws/plugins/deploy_control_endpoint.rb +22 -0
  63. data/vendor/gems/process_manager/README.md +1 -0
  64. data/vendor/gems/process_manager/lib/blank.rb +153 -0
  65. data/vendor/gems/process_manager/lib/core_ext.rb +73 -0
  66. data/vendor/gems/process_manager/lib/process_manager.rb +49 -0
  67. data/vendor/gems/process_manager/lib/process_manager/child.rb +119 -0
  68. data/vendor/gems/process_manager/lib/process_manager/config.rb +112 -0
  69. data/vendor/gems/process_manager/lib/process_manager/log.rb +107 -0
  70. data/vendor/gems/process_manager/lib/process_manager/master.rb +322 -0
  71. data/vendor/gems/process_manager/process_manager-0.0.13.gemspec +42 -0
  72. data/vendor/specifications/aws-sdk-core-2.0.5.gemspec +39 -0
  73. data/vendor/specifications/builder-3.2.2.gemspec +29 -0
  74. data/vendor/specifications/codedeploy-commands-1.0.0.gemspec +28 -0
  75. data/vendor/specifications/gli-2.5.6.gemspec +51 -0
  76. data/vendor/specifications/jamespath-0.5.1.gemspec +35 -0
  77. data/vendor/specifications/little-plugger-1.1.3.gemspec +32 -0
  78. data/vendor/specifications/logging-1.8.1.gemspec +44 -0
  79. data/vendor/specifications/multi_json-1.7.7.gemspec +30 -0
  80. data/vendor/specifications/multi_json-1.8.4.gemspec +30 -0
  81. data/vendor/specifications/multi_xml-0.5.5.gemspec +30 -0
  82. data/vendor/specifications/process_manager-0.0.13.gemspec +42 -0
  83. data/vendor/specifications/simple_pid-0.2.1.gemspec +28 -0
  84. metadata +377 -0
@@ -0,0 +1,28 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = "codedeploy-commands"
5
+ s.version = "1.0.0"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Amazon Web Services"]
9
+ s.date = "2014-11-04"
10
+ s.description = "Provides client libraries for CodeDeploy Command."
11
+ s.files = ["lib/aws/codedeploy_commands.rb", "lib/aws/plugins/deploy_control_endpoint.rb", "lib/aws/plugins/certificate_authority.rb", "apis/CodeDeployCommand.api.json"]
12
+ s.licenses = ["Apache 2.0"]
13
+ s.require_paths = ["lib"]
14
+ s.rubygems_version = "1.8.23"
15
+ s.summary = "Deploy Control Ruby SDK"
16
+
17
+ if s.respond_to? :specification_version then
18
+ s.specification_version = 3
19
+
20
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
21
+ s.add_runtime_dependency(%q<aws-sdk-core>, ["= 2.0.5"])
22
+ else
23
+ s.add_dependency(%q<aws-sdk-core>, ["= 2.0.5"])
24
+ end
25
+ else
26
+ s.add_dependency(%q<aws-sdk-core>, ["= 2.0.5"])
27
+ end
28
+ end
@@ -0,0 +1,18 @@
1
+ gem_root = File.dirname(File.dirname(File.dirname(__FILE__)))
2
+
3
+ require 'aws-sdk-core'
4
+ require "#{gem_root}/lib/aws/plugins/certificate_authority"
5
+ require "#{gem_root}/lib/aws/plugins/deploy_control_endpoint"
6
+
7
+ version = '1.0.0'
8
+
9
+ bundled_apis = Dir.glob(File.join(gem_root, 'apis', '*.json')).group_by do |path|
10
+ File.basename(path).split('.').first
11
+ end
12
+
13
+ bundled_apis.each do |svc_class_name, api_versions|
14
+ svc_class = Aws.add_service(svc_class_name, api: JSON.parse(File.read(api_versions.first), max_nesting: false))
15
+ svc_class.const_set(:VERSION, version)
16
+ Aws::CodeDeployCommand::Client.add_plugin(Aws::Plugins::CertificateAuthority)
17
+ Aws::CodeDeployCommand::Client.add_plugin(Aws::Plugins::DeployControlEndpoint)
18
+ end
@@ -0,0 +1,12 @@
1
+ require 'aws-sdk-core'
2
+
3
+ module Aws
4
+ module Plugins
5
+ class CertificateAuthority < Seahorse::Client::Plugin
6
+
7
+ option(:ssl_ca_bundle) { ENV['AWS_SSL_CA_BUNDLE'] }
8
+ option(:ssl_ca_directory) { ENV['AWS_SSL_CA_DIRECTORY'] }
9
+
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,22 @@
1
+ require 'aws-sdk-core'
2
+
3
+ module Aws
4
+ module Plugins
5
+ class DeployControlEndpoint < Seahorse::Client::Plugin
6
+ option(:endpoint) do |cfg|
7
+ url = ENV['AWS_DEPLOY_CONTROL_ENDPOINT']
8
+ if url.nil?
9
+ case cfg.region
10
+ when "us-east-1"
11
+ url = "https://codedeploy-commands.us-east-1.amazonaws.com"
12
+ when "us-west-2"
13
+ url = "https://codedeploy-commands.us-west-2.amazonaws.com"
14
+ else
15
+ raise "Not able to find an endpoint. Unknown region."
16
+ end
17
+ end
18
+ url
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1 @@
1
+ process_manager
@@ -0,0 +1,153 @@
1
+ #Copyright (c) 2005-2014 David Heinemeier Hansson
2
+
3
+ #Permission is hereby granted, free of charge, to any person obtaining
4
+ #a copy of this software and associated documentation files (the
5
+ #"Software"), to deal in the Software without restriction, including
6
+ #without limitation the rights to use, copy, modify, merge, publish,
7
+ #distribute, sublicense, and/or sell copies of the Software, and to
8
+ #permit persons to whom the Software is furnished to do so, subject to
9
+ #the following conditions:
10
+
11
+ #The above copyright notice and this permission notice shall be
12
+ #included in all copies or substantial portions of the Software.
13
+
14
+ #THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ #EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ #MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ #NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ #LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ #OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ #WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+
23
+ # Taken from ActiveSupport core_ext/object/blank
24
+
25
+ class Object
26
+ # An object is blank if it's false, empty, or a whitespace string.
27
+ # For example, '', ' ', +nil+, [], and {} are all blank.
28
+ #
29
+ # This simplifies
30
+ #
31
+ # address.nil? || address.empty?
32
+ #
33
+ # to
34
+ #
35
+ # address.blank?
36
+ #
37
+ # @return [true, false]
38
+ def blank?
39
+ respond_to?(:empty?) ? !!empty? : !self
40
+ end
41
+
42
+ # An object is present if it's not blank.
43
+ #
44
+ # @return [true, false]
45
+ def present?
46
+ !blank?
47
+ end
48
+
49
+ # Returns the receiver if it's present otherwise returns +nil+.
50
+ # <tt>object.presence</tt> is equivalent to
51
+ #
52
+ # object.present? ? object : nil
53
+ #
54
+ # For example, something like
55
+ #
56
+ # state = params[:state] if params[:state].present?
57
+ # country = params[:country] if params[:country].present?
58
+ # region = state || country || 'US'
59
+ #
60
+ # becomes
61
+ #
62
+ # region = params[:state].presence || params[:country].presence || 'US'
63
+ #
64
+ # @return [Object]
65
+ def presence
66
+ self if present?
67
+ end
68
+ end
69
+
70
+ class NilClass
71
+ # +nil+ is blank:
72
+ #
73
+ # nil.blank? # => true
74
+ #
75
+ # @return [true]
76
+ def blank?
77
+ true
78
+ end
79
+ end
80
+
81
+ class FalseClass
82
+ # +false+ is blank:
83
+ #
84
+ # false.blank? # => true
85
+ #
86
+ # @return [true]
87
+ def blank?
88
+ true
89
+ end
90
+ end
91
+
92
+ class TrueClass
93
+ # +true+ is not blank:
94
+ #
95
+ # true.blank? # => false
96
+ #
97
+ # @return [false]
98
+ def blank?
99
+ false
100
+ end
101
+ end
102
+
103
+ class Array
104
+ # An array is blank if it's empty:
105
+ #
106
+ # [].blank? # => true
107
+ # [1,2,3].blank? # => false
108
+ #
109
+ # @return [true, false]
110
+ alias_method :blank?, :empty?
111
+ end
112
+
113
+ class Hash
114
+ # A hash is blank if it's empty:
115
+ #
116
+ # {}.blank? # => true
117
+ # { key: 'value' }.blank? # => false
118
+ #
119
+ # @return [true, false]
120
+ alias_method :blank?, :empty?
121
+ end
122
+
123
+ class String
124
+ BLANK_RE = /\A[[:space:]]*\z/
125
+
126
+ # A string is blank if it's empty or contains whitespaces only:
127
+ #
128
+ # ''.blank? # => true
129
+ # ' '.blank? # => true
130
+ # "\t\n\r".blank? # => true
131
+ # ' blah '.blank? # => false
132
+ #
133
+ # Unicode whitespace is supported:
134
+ #
135
+ # "\u00a0".blank? # => true
136
+ #
137
+ # @return [true, false]
138
+ def blank?
139
+ BLANK_RE === self
140
+ end
141
+ end
142
+
143
+ class Numeric #:nodoc:
144
+ # No number is blank:
145
+ #
146
+ # 1.blank? # => false
147
+ # 0.blank? # => false
148
+ #
149
+ # @return [false]
150
+ def blank?
151
+ false
152
+ end
153
+ end
@@ -0,0 +1,73 @@
1
+ #Copyright (c) 2005-2014 David Heinemeier Hansson
2
+
3
+ #Permission is hereby granted, free of charge, to any person obtaining
4
+ #a copy of this software and associated documentation files (the
5
+ #"Software"), to deal in the Software without restriction, including
6
+ #without limitation the rights to use, copy, modify, merge, publish,
7
+ #distribute, sublicense, and/or sell copies of the Software, and to
8
+ #permit persons to whom the Software is furnished to do so, subject to
9
+ #the following conditions:
10
+
11
+ #The above copyright notice and this permission notice shall be
12
+ #included in all copies or substantial portions of the Software.
13
+
14
+ #THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ #EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ #MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ #NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ #LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ #OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ #WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ # taken from ActiveSupport core_ext
23
+
24
+ # encoding: UTF-8
25
+ # Ruby 1.8.7 does not have a 'key' method on Hash
26
+ unless Hash.new.respond_to?(:key)
27
+ class Hash
28
+ def key(value)
29
+ matching = select{|k,v| v == value}
30
+ if matching && matching[0]
31
+ matching[0][0]
32
+ else
33
+ nil
34
+ end
35
+ end
36
+ end
37
+ end
38
+
39
+ unless Hash.new.respond_to?(:symbolize_keys!)
40
+ class Hash
41
+ def symbolize_keys!
42
+ keys.each do |key|
43
+ self[(key.to_sym rescue key) || key] = delete(key)
44
+ end
45
+ self
46
+ end
47
+
48
+ def symbolize_keys
49
+ dup.symbolize_keys!
50
+ end
51
+ end
52
+ end
53
+
54
+ unless String.new.respond_to?(:demodulize)
55
+ class String
56
+ def demodulize
57
+ path = self.to_s
58
+ if i = path.rindex('::')
59
+ path[(i+2)..-1]
60
+ else
61
+ path
62
+ end
63
+ end
64
+ end
65
+ end
66
+
67
+ module Kernel
68
+ def singleton_class
69
+ class << self
70
+ self
71
+ end
72
+ end unless respond_to?(:singleton_class)
73
+ end
@@ -0,0 +1,49 @@
1
+ # encoding: UTF-8
2
+ require 'socket'
3
+ require 'etc'
4
+
5
+ unless defined?(ProcessManager)
6
+ $: << File.expand_path(File.dirname(__FILE__) + '/lib')
7
+ require_relative 'core_ext'
8
+ require 'process_manager/config'
9
+ require 'process_manager/log'
10
+ require 'process_manager/master'
11
+ require 'process_manager/child'
12
+
13
+ module ProcessManager
14
+ VERSION = '0.0.13'
15
+
16
+ def self.process_running?(pid)
17
+ begin
18
+ Process.kill(0, Integer(pid))
19
+ return true
20
+ rescue Errno::EPERM # changed uid
21
+ return false
22
+ rescue Errno::ESRCH # deceased or zombied
23
+ return false
24
+ rescue
25
+ puts "ERROR: couldn't check the status of process #{pid}"
26
+ return false
27
+ end
28
+ end
29
+
30
+ def self.set_program_name(name)
31
+ $PROGRAM_NAME = "#{ProcessManager::Config.config[:program_name]}: #{name}"
32
+ end
33
+
34
+ def self.on_error(&block)
35
+ @@_error_callbacks ||= []
36
+ @@_error_callbacks << block
37
+ nil
38
+ end
39
+
40
+ def self.on_error_callbacks
41
+ @@_error_callbacks ||= []
42
+ end
43
+
44
+ def self.reset_on_error_callbacks
45
+ @@_error_callbacks = []
46
+ end
47
+
48
+ end
49
+ end
@@ -0,0 +1,119 @@
1
+ # encoding: UTF-8
2
+ module ProcessManager
3
+ module Daemon
4
+ class Child
5
+
6
+ attr_accessor :times_run, :master_pid, :index
7
+
8
+ # each child gets the PID of the master
9
+ # the child checks regularly if the master is alive and terminates itself if not
10
+ def initialize(index, master_pid)
11
+ @index = index
12
+ @master_pid = master_pid
13
+ @times_run = 0
14
+
15
+ ProcessManager.set_program_name(description)
16
+ end
17
+
18
+ def start
19
+ trap_signals
20
+ prepare_run_with_error_handling
21
+
22
+ loop do
23
+ if run_limit_met?
24
+ ProcessManager::Log.info "#{description}: ran #{times_run} - shutting down"
25
+ exit
26
+ elsif should_stop?
27
+ ProcessManager::Log.info "#{description}: shutting down"
28
+ exit
29
+ else # the main loop
30
+ if master_alive?
31
+
32
+ # the actual main running method
33
+ run_with_error_handling
34
+ increase_run_counter
35
+ else
36
+ ProcessManager::Log.info "#{description}: Master #{master_pid} not alive - shutting down"
37
+ exit
38
+ end
39
+ end
40
+
41
+ sleep ProcessManager::Config.config[:wait_between_runs].to_i
42
+ end
43
+ end
44
+
45
+ def increase_run_counter
46
+ @times_run += 1
47
+ end
48
+
49
+ def run_limit_met?
50
+ limit = ProcessManager::Config.config[:max_runs_per_worker].to_i
51
+ return false if limit == 0
52
+ times_run >= limit
53
+ end
54
+
55
+ def with_error_handling
56
+ yield
57
+ rescue Exception => e
58
+ ProcessManager::Log.error "#{description}: error during start: #{e.class} - #{e} - #{e.backtrace.join("\n")}"
59
+ exit 1
60
+ end
61
+
62
+ def prepare_run_with_error_handling
63
+ with_error_handling do
64
+ prepare_run
65
+ end
66
+ end
67
+
68
+ def run_with_error_handling
69
+ with_error_handling do
70
+ run
71
+ end
72
+ end
73
+
74
+ # please override
75
+ def run
76
+ ProcessManager::Log.info "Hello from #{description}"
77
+ end
78
+
79
+ # please override
80
+ def prepare_run
81
+ end
82
+
83
+ def stop
84
+ @should_stop = true
85
+ ProcessManager.set_program_name("#{description} - shutting down")
86
+ end
87
+
88
+ def should_stop?
89
+ @should_stop
90
+ end
91
+
92
+ def master_alive?
93
+ ProcessManager.process_running?(master_pid)
94
+ end
95
+
96
+ # please override
97
+ def description
98
+ "child #{position} (#{$$}) of master #{master_pid}"
99
+ end
100
+
101
+ def position
102
+ "#{index + 1}/#{ProcessManager::Config.config[:children]}"
103
+ end
104
+
105
+ def trap_signals
106
+ [:INT, :QUIT, :TERM].each do |sig|
107
+ trap(sig) do
108
+ ProcessManager::Log.info "#{description}: Received #{sig} - setting internal shutting down flag and possibly finishing last run"
109
+ stop
110
+ end
111
+ end
112
+
113
+ # make sure we do not handle children like the master process
114
+ trap(:CHLD, 'DEFAULT')
115
+ end
116
+
117
+ end
118
+ end
119
+ end