aws-codedeploy-agent 0.0.4 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +5 -1
- data/.travis.yml +10 -0
- data/CHANGES.md +5 -0
- data/Gemfile +6 -3
- data/README.md +35 -0
- data/Rakefile +52 -0
- data/aws-codedeploy-agent.gemspec +5 -10
- data/conf/codedeployagent.yml +1 -0
- data/features/AwsCredentials.yml +4 -0
- data/features/agent.feature +11 -0
- data/features/aws_credentials.rb +35 -0
- data/features/step_definitions.rb +233 -0
- data/init.d/codedeploy-agent +11 -6
- data/lib/instance_agent.rb +1 -1
- data/lib/instance_agent/config.rb +3 -1
- data/lib/instance_agent/log.rb +18 -0
- data/lib/instance_agent/platform/linux_util.rb +27 -5
- data/lib/instance_agent/plugins/codedeploy/application_specification/application_specification.rb +2 -1
- data/lib/instance_agent/plugins/codedeploy/application_specification/file_info.rb +2 -2
- data/lib/instance_agent/plugins/codedeploy/application_specification/script_info.rb +3 -2
- data/lib/instance_agent/plugins/codedeploy/codedeploy_control.rb +15 -14
- data/lib/instance_agent/plugins/codedeploy/command_executor.rb +34 -6
- data/lib/instance_agent/plugins/codedeploy/command_poller.rb +12 -1
- data/lib/instance_agent/plugins/codedeploy/deployment_specification.rb +2 -12
- data/lib/instance_agent/plugins/codedeploy/hook_executor.rb +8 -4
- data/lib/instance_agent/plugins/codedeploy/install_instruction.rb +3 -1
- data/lib/instance_metadata.rb +1 -1
- data/test/instance_agent/config_test.rb +3 -1
- data/test/instance_agent/platform/linux_util_test.rb +35 -0
- data/test/instance_agent/plugins/codedeploy/application_specification_test.rb +7 -6
- data/test/instance_agent/plugins/codedeploy/command_executor_test.rb +13 -10
- data/test/instance_agent/plugins/codedeploy/command_poller_test.rb +28 -6
- data/test/instance_agent/plugins/codedeploy/deployment_specification_test.rb +9 -9
- data/test/instance_agent/plugins/codedeploy/hook_executor_test.rb +12 -4
- data/test/test_helper.rb +6 -1
- data/vendor/gems/codedeploy-commands/apis/CodeDeployCommand.api.json +1 -0
- data/vendor/gems/codedeploy-commands/lib/aws/codedeploy_commands.rb +2 -0
- data/vendor/gems/codedeploy-commands/lib/aws/plugins/deploy_agent_version.rb +31 -0
- data/vendor/gems/codedeploy-commands/lib/aws/plugins/deploy_control_endpoint.rb +1 -12
- data/vendor/gems/process_manager/lib/process_manager/master.rb +3 -3
- data/vendor/specifications/codedeploy-commands-1.0.0.gemspec +5 -5
- metadata +52 -149
- data/vendor/gems/codedeploy-commands/codedeploy-commands-1.0.0.gemspec +0 -28
- data/vendor/gems/process_manager/process_manager-0.0.13.gemspec +0 -42
- data/vendor/specifications/aws-sdk-core-2.0.42.gemspec +0 -37
- data/vendor/specifications/builder-3.2.2.gemspec +0 -29
- data/vendor/specifications/gli-2.5.6.gemspec +0 -51
- data/vendor/specifications/jmespath-1.0.1.gemspec +0 -29
- data/vendor/specifications/little-plugger-1.1.3.gemspec +0 -32
- data/vendor/specifications/logging-1.8.1.gemspec +0 -44
- data/vendor/specifications/multi_json-1.7.7.gemspec +0 -30
- data/vendor/specifications/multi_json-1.8.4.gemspec +0 -30
- data/vendor/specifications/multi_xml-0.5.5.gemspec +0 -30
- data/vendor/specifications/simple_pid-0.2.1.gemspec +0 -28
data/init.d/codedeploy-agent
CHANGED
@@ -17,24 +17,30 @@
|
|
17
17
|
# the deployment artifacts on to this instance.
|
18
18
|
### END INIT INFO
|
19
19
|
|
20
|
-
|
20
|
+
[ -f /etc/profile ] && [ "`stat --format '%U %G' /etc/profile`" == "root root" ] && source /etc/profile
|
21
21
|
|
22
22
|
BIN="codedeploy-agent"
|
23
23
|
|
24
24
|
start() {
|
25
25
|
echo -n $"Starting $BIN:"
|
26
|
-
nohup $BIN start >/dev/null </dev/null 2>&1
|
26
|
+
nohup $BIN start >/dev/null </dev/null 2>&1
|
27
27
|
exit $?
|
28
28
|
}
|
29
29
|
|
30
30
|
stop() {
|
31
31
|
echo -n $"Stopping $BIN:"
|
32
|
-
nohup $BIN stop >/dev/null </dev/null 2>&1
|
32
|
+
nohup $BIN stop >/dev/null </dev/null 2>&1
|
33
|
+
exit $?
|
34
|
+
}
|
35
|
+
|
36
|
+
restart() {
|
37
|
+
echo -n $"Restarting $BIN:"
|
38
|
+
nohup $BIN restart >/dev/null </dev/null 2>&1
|
33
39
|
exit $?
|
34
40
|
}
|
35
41
|
|
36
42
|
status() {
|
37
|
-
$BIN status
|
43
|
+
$BIN status
|
38
44
|
exit $?
|
39
45
|
}
|
40
46
|
|
@@ -46,8 +52,7 @@ case "$1" in
|
|
46
52
|
stop
|
47
53
|
;;
|
48
54
|
restart)
|
49
|
-
|
50
|
-
start
|
55
|
+
restart
|
51
56
|
;;
|
52
57
|
force-reload)
|
53
58
|
stop
|
data/lib/instance_agent.rb
CHANGED
@@ -31,7 +31,9 @@ module InstanceAgent
|
|
31
31
|
:wait_between_runs => 30,
|
32
32
|
:wait_after_error => 30,
|
33
33
|
:codedeploy_test_profile => 'prod',
|
34
|
-
:on_premises_config_file => '/etc/codedeploy-agent/conf/codedeploy.onpremises.yml'
|
34
|
+
:on_premises_config_file => '/etc/codedeploy-agent/conf/codedeploy.onpremises.yml',
|
35
|
+
:proxy_uri => nil,
|
36
|
+
:enable_deployments_log => true
|
35
37
|
})
|
36
38
|
end
|
37
39
|
|
data/lib/instance_agent/log.rb
CHANGED
@@ -1,3 +1,21 @@
|
|
1
1
|
require 'process_manager/log'
|
2
|
+
require 'singleton'
|
2
3
|
|
3
4
|
InstanceAgent::Log = ProcessManager::Log
|
5
|
+
|
6
|
+
class InstanceAgent::DeploymentLog
|
7
|
+
include Singleton
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
deployment_logs_dir = File.join(InstanceAgent::Config.config[:root_dir], 'deployment-logs')
|
11
|
+
FileUtils.mkdir_p(deployment_logs_dir) unless File.exists? deployment_logs_dir
|
12
|
+
@deployment_log ||= Logger.new(File.join(deployment_logs_dir, "#{InstanceAgent::Config.config[:program_name]}-deployments.log"), 8, 64 * 1024 * 1024)
|
13
|
+
@deployment_log.formatter = proc do |severity, datetime, progname, msg|
|
14
|
+
"[#{datetime.strftime('%Y-%m-%d %H:%M:%S.%L')}] #{msg}\n"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def log(message)
|
19
|
+
@deployment_log.info(message)
|
20
|
+
end
|
21
|
+
end
|
@@ -8,12 +8,30 @@ module InstanceAgent
|
|
8
8
|
['linux']
|
9
9
|
end
|
10
10
|
|
11
|
-
def self.prepare_script_command(script,
|
12
|
-
|
13
|
-
|
14
|
-
|
11
|
+
def self.prepare_script_command(script, absolute_cmd_path)
|
12
|
+
runas = !!script.runas
|
13
|
+
sudo = !!script.sudo
|
14
|
+
|
15
|
+
if runas && sudo
|
16
|
+
return 'sudo su ' + script.runas + ' -c ' + absolute_cmd_path
|
17
|
+
end
|
18
|
+
|
19
|
+
if runas && !sudo
|
20
|
+
return 'su ' + script.runas + ' -c ' + absolute_cmd_path
|
21
|
+
end
|
22
|
+
|
23
|
+
if !runas && sudo
|
24
|
+
return 'sudo ' + absolute_cmd_path
|
15
25
|
end
|
16
|
-
|
26
|
+
|
27
|
+
# If neither sudo or runas is specified, execute the
|
28
|
+
# command as the code deploy agent user
|
29
|
+
absolute_cmd_path
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.quit()
|
33
|
+
# Send kill signal to parent and exit
|
34
|
+
Process.kill('TERM', Process.ppid)
|
17
35
|
end
|
18
36
|
|
19
37
|
def self.script_executable?(path)
|
@@ -33,6 +51,10 @@ module InstanceAgent
|
|
33
51
|
def self.supports_process_groups?()
|
34
52
|
true
|
35
53
|
end
|
54
|
+
|
55
|
+
def self.codedeploy_version_file
|
56
|
+
File.join(ProcessManager::Config.config[:root_dir], '..')
|
57
|
+
end
|
36
58
|
|
37
59
|
private
|
38
60
|
def self.execute_tar_command(cmd)
|
data/lib/instance_agent/plugins/codedeploy/application_specification/application_specification.rb
CHANGED
@@ -60,6 +60,7 @@ module InstanceAgent
|
|
60
60
|
current_hook_scripts << InstanceAgent::Plugins::CodeDeployPlugin::ApplicationSpecification::ScriptInfo.new(script['location'].to_s.strip,
|
61
61
|
{
|
62
62
|
:runas => script.has_key?('runas') && !script['runas'].nil? ? script['runas'].to_s.strip : nil,
|
63
|
+
:sudo => script['sudo'],
|
63
64
|
:timeout => script['timeout']
|
64
65
|
})
|
65
66
|
else
|
@@ -140,4 +141,4 @@ module InstanceAgent
|
|
140
141
|
end
|
141
142
|
end
|
142
143
|
end
|
143
|
-
end
|
144
|
+
end
|
@@ -10,7 +10,7 @@ module InstanceAgent
|
|
10
10
|
if(source.nil?)
|
11
11
|
raise AppSpecValidationException, 'File needs to have a source'
|
12
12
|
elsif (destination.nil?)
|
13
|
-
raise AppSpecValidationException,
|
13
|
+
raise AppSpecValidationException, "File #{source} needs to have a destination"
|
14
14
|
end
|
15
15
|
@source = source
|
16
16
|
@destination = destination
|
@@ -20,4 +20,4 @@ module InstanceAgent
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|
23
|
-
end
|
23
|
+
end
|
@@ -5,7 +5,7 @@ module InstanceAgent
|
|
5
5
|
#Helper Class for storing data parsed from hook script maps
|
6
6
|
class ScriptInfo
|
7
7
|
|
8
|
-
attr_reader :location, :runas, :timeout
|
8
|
+
attr_reader :location, :runas, :sudo, :timeout
|
9
9
|
def initialize(location, opts = {})
|
10
10
|
location = location.to_s
|
11
11
|
if(location.empty?)
|
@@ -13,6 +13,7 @@ module InstanceAgent
|
|
13
13
|
end
|
14
14
|
@location = location
|
15
15
|
@runas = opts[:runas]
|
16
|
+
@sudo = opts[:sudo]
|
16
17
|
@timeout = opts[:timeout] || 3600
|
17
18
|
@timeout = @timeout.to_i
|
18
19
|
if(@timeout <= 0)
|
@@ -24,4 +25,4 @@ module InstanceAgent
|
|
24
25
|
end
|
25
26
|
end
|
26
27
|
end
|
27
|
-
end
|
28
|
+
end
|
@@ -22,6 +22,11 @@ module InstanceAgent
|
|
22
22
|
64 * 1024 * 1024),
|
23
23
|
:http_wire_trace => true})
|
24
24
|
end
|
25
|
+
|
26
|
+
if InstanceAgent::Config.config[:proxy_uri]
|
27
|
+
@options = options.update({
|
28
|
+
:http_proxy => URI(InstanceAgent::Config.config[:proxy_uri]) })
|
29
|
+
end
|
25
30
|
end
|
26
31
|
|
27
32
|
def validate_ssl_config
|
@@ -66,6 +71,15 @@ module InstanceAgent
|
|
66
71
|
client.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
67
72
|
client.ca_file = ENV['SSL_CERT_FILE']
|
68
73
|
|
74
|
+
if InstanceAgent::Config.config[:proxy_uri]
|
75
|
+
proxy_uri = URI(InstanceAgent::Config.config[:proxy_uri])
|
76
|
+
client.proxy_from_env = false # make sure proxy settings can be overridden
|
77
|
+
client.proxy_address = proxy_uri.host
|
78
|
+
client.proxy_port = proxy_uri.port
|
79
|
+
client.proxy_user = proxy_uri.user if proxy_uri.user
|
80
|
+
client.proxy_pass = proxy_uri.password if proxy_uri.password
|
81
|
+
end
|
82
|
+
|
69
83
|
client.verify_callback = lambda do |preverify_ok, cert_store|
|
70
84
|
return false unless preverify_ok
|
71
85
|
@cert = cert_store.chain[0]
|
@@ -78,20 +92,7 @@ module InstanceAgent
|
|
78
92
|
# Do minimal cert pinning
|
79
93
|
def verify_subject
|
80
94
|
InstanceAgent::Log.debug("#{self.class.to_s}: Actual certificate subject is '#{@cert.subject.to_s}'")
|
81
|
-
|
82
|
-
case @region
|
83
|
-
when 'us-east-1'
|
84
|
-
@cert.subject.to_s == "/C=US/ST=Washington/L=Seattle/O=Amazon.com, Inc./CN=codedeploy-commands.us-east-1.amazonaws.com"
|
85
|
-
when 'us-west-2'
|
86
|
-
@cert.subject.to_s == "/C=US/ST=Washington/L=Seattle/O=Amazon.com, Inc./CN=codedeploy-commands.us-west-2.amazonaws.com"
|
87
|
-
when 'eu-west-1'
|
88
|
-
@cert.subject.to_s == "/C=US/ST=Washington/L=Seattle/O=Amazon.com, Inc./CN=codedeploy-commands.eu-west-1.amazonaws.com"
|
89
|
-
when 'ap-southeast-2'
|
90
|
-
@cert.subject.to_s == "/C=US/ST=Washington/L=Seattle/O=Amazon.com, Inc./CN=codedeploy-commands.ap-southeast-2.amazonaws.com"
|
91
|
-
else
|
92
|
-
InstanceAgent::Log.debug("#{self.class.to_s}: Unsupported region '#{@region}'")
|
93
|
-
false
|
94
|
-
end
|
95
|
+
@cert.subject.to_s == "/C=US/ST=Washington/L=Seattle/O=Amazon.com, Inc./CN=codedeploy-commands."+@region+".amazonaws.com"
|
95
96
|
end
|
96
97
|
|
97
98
|
end
|
@@ -11,6 +11,7 @@ module InstanceAgent
|
|
11
11
|
module Plugins
|
12
12
|
module CodeDeployPlugin
|
13
13
|
ARCHIVES_TO_RETAIN = 5
|
14
|
+
|
14
15
|
class CommandExecutor
|
15
16
|
class << self
|
16
17
|
attr_reader :command_methods
|
@@ -26,6 +27,17 @@ module InstanceAgent
|
|
26
27
|
if(!@hook_mapping.nil?)
|
27
28
|
map
|
28
29
|
end
|
30
|
+
begin
|
31
|
+
max_revisions = ProcessManager::Config.config[:max_revisions]
|
32
|
+
@archives_to_retain = max_revisions.nil?? ARCHIVES_TO_RETAIN : Integer(max_revisions)
|
33
|
+
if @archives_to_retain < 0
|
34
|
+
raise ArgumentError
|
35
|
+
end
|
36
|
+
rescue ArgumentError
|
37
|
+
log(:error, "Invalid configuration :max_revision=#{max_revisions}")
|
38
|
+
Platform.util.quit()
|
39
|
+
end
|
40
|
+
log(:info, "Archives to retain is: #{@archives_to_retain}}")
|
29
41
|
end
|
30
42
|
|
31
43
|
def self.command(name, &blk)
|
@@ -115,6 +127,7 @@ module InstanceAgent
|
|
115
127
|
:application_name => deployment_spec.application_name,
|
116
128
|
:deployment_id => deployment_spec.deployment_id,
|
117
129
|
:deployment_group_name => deployment_spec.deployment_group_name,
|
130
|
+
:deployment_group_id => deployment_spec.deployment_group_id,
|
118
131
|
:deployment_root_dir => deployment_root_dir(deployment_spec),
|
119
132
|
:last_successful_deployment_dir => last_successful_deployment_dir(deployment_spec.deployment_group_id),
|
120
133
|
:app_spec_path => app_spec_path)
|
@@ -165,6 +178,11 @@ module InstanceAgent
|
|
165
178
|
def download_from_s3(deployment_spec, bucket, key, version, etag)
|
166
179
|
log(:debug, "Downloading artifact bundle from bucket '#{bucket}' and key '#{key}', version '#{version}', etag '#{etag}'")
|
167
180
|
region = ENV['AWS_REGION'] || InstanceMetadata.region
|
181
|
+
|
182
|
+
proxy_uri = nil
|
183
|
+
if InstanceAgent::Config.config[:proxy_uri]
|
184
|
+
proxy_uri = URI(InstanceAgent::Config.config[:proxy_uri])
|
185
|
+
end
|
168
186
|
|
169
187
|
if InstanceAgent::Config.config[:log_aws_wire]
|
170
188
|
s3 = Aws::S3::Client.new(
|
@@ -176,11 +194,15 @@ module InstanceAgent
|
|
176
194
|
File.join(InstanceAgent::Config.config[:log_dir], "#{InstanceAgent::Config.config[:program_name]}.aws_wire.log"),
|
177
195
|
16,
|
178
196
|
64 * 1024 * 1024),
|
179
|
-
:http_wire_trace => true
|
197
|
+
:http_wire_trace => true,
|
198
|
+
:signature_version => 'v4',
|
199
|
+
:http_proxy => proxy_uri)
|
180
200
|
else
|
181
201
|
s3 = Aws::S3::Client.new(
|
182
202
|
:region => region,
|
183
|
-
:ssl_ca_directory => ENV['AWS_SSL_CA_DIRECTORY']
|
203
|
+
:ssl_ca_directory => ENV['AWS_SSL_CA_DIRECTORY'],
|
204
|
+
:signature_version => 'v4',
|
205
|
+
:http_proxy => proxy_uri)
|
184
206
|
end
|
185
207
|
|
186
208
|
File.open(artifact_bundle(deployment_spec), 'wb') do |file|
|
@@ -316,16 +338,22 @@ module InstanceAgent
|
|
316
338
|
|
317
339
|
private
|
318
340
|
def cleanup_old_archives(deployment_group)
|
319
|
-
deployment_archives = Dir
|
320
|
-
|
341
|
+
deployment_archives = Dir.entries(File.join(ProcessManager::Config.config[:root_dir], deployment_group))
|
342
|
+
# remove . and ..
|
343
|
+
deployment_archives.delete(".")
|
344
|
+
deployment_archives.delete("..")
|
345
|
+
|
346
|
+
full_path_deployment_archives = deployment_archives.map{ |f| File.join(ProcessManager::Config.config[:root_dir], deployment_group, f)}
|
347
|
+
|
348
|
+
extra = full_path_deployment_archives.size - @archives_to_retain
|
321
349
|
return unless extra > 0
|
322
350
|
|
323
351
|
# Never remove the last successful deployment
|
324
352
|
last_success = last_successful_deployment_dir(deployment_group)
|
325
|
-
|
353
|
+
full_path_deployment_archives.delete(last_success)
|
326
354
|
|
327
355
|
# Sort oldest -> newest, take first `extra` elements
|
328
|
-
oldest_extra =
|
356
|
+
oldest_extra = full_path_deployment_archives.sort_by{ |f| File.mtime(f) }.take(extra)
|
329
357
|
|
330
358
|
# Absolute path takes care of relative root directories
|
331
359
|
directories = oldest_extra.map{ |f| File.absolute_path(f) }
|
@@ -8,6 +8,15 @@ module InstanceAgent
|
|
8
8
|
|
9
9
|
VERSION = "2013-04-23"
|
10
10
|
def initialize
|
11
|
+
test_profile = InstanceAgent::Config.config[:codedeploy_test_profile]
|
12
|
+
unless ["beta", "gamma"].include?(test_profile.downcase)
|
13
|
+
# Remove any user overrides set in the environment.
|
14
|
+
# The agent should always pull credentials from the EC2 instance
|
15
|
+
# profile or the credentials in the OnPremises config file.
|
16
|
+
ENV['AWS_ACCESS_KEY_ID'] = nil
|
17
|
+
ENV['AWS_SECRET_ACCESS_KEY'] = nil
|
18
|
+
ENV['AWS_CREDENTIAL_FILE'] = nil
|
19
|
+
end
|
11
20
|
CodeDeployPlugin::OnPremisesConfig.configure
|
12
21
|
region = ENV['AWS_REGION'] || InstanceMetadata.region
|
13
22
|
@host_identifier = ENV['AWS_HOST_IDENTIFIER'] || InstanceMetadata.host_identifier
|
@@ -135,7 +144,9 @@ module InstanceAgent
|
|
135
144
|
|
136
145
|
private
|
137
146
|
def gather_diagnostics_from_script_error(script_error)
|
138
|
-
script_error.to_json
|
147
|
+
return script_error.to_json
|
148
|
+
rescue Exception => e
|
149
|
+
return {'error_code' => "Unknown", 'script_name' => script_error.script_name, 'message' => "Attempting minimal diagnostics", 'log' => "Exception #{e.class} occured"}.to_json
|
139
150
|
end
|
140
151
|
|
141
152
|
private
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'openssl'
|
2
2
|
require 'instance_metadata'
|
3
|
+
require 'open-uri'
|
3
4
|
|
4
5
|
module InstanceAgent
|
5
6
|
module Plugins
|
@@ -132,18 +133,7 @@ module InstanceAgent
|
|
132
133
|
when 'beta', 'gamma'
|
133
134
|
cert.subject.to_s == "/C=US/ST=Washington/L=Seattle/O=Amazon.com, Inc./CN=codedeploy-signer-integ.amazonaws.com"
|
134
135
|
when 'prod'
|
135
|
-
|
136
|
-
when 'us-east-1'
|
137
|
-
cert.subject.to_s == "/C=US/ST=Washington/L=Seattle/O=Amazon.com, Inc./CN=codedeploy-signer-us-east-1.amazonaws.com"
|
138
|
-
when 'us-west-2'
|
139
|
-
cert.subject.to_s == "/C=US/ST=Washington/L=Seattle/O=Amazon.com, Inc./CN=codedeploy-signer-us-west-2.amazonaws.com"
|
140
|
-
when 'eu-west-1'
|
141
|
-
cert.subject.to_s == "/C=US/ST=Washington/L=Seattle/O=Amazon.com, Inc./CN=codedeploy-signer-eu-west-1.amazonaws.com"
|
142
|
-
when 'ap-southeast-2'
|
143
|
-
cert.subject.to_s == "/C=US/ST=Washington/L=Seattle/O=Amazon.com, Inc./CN=codedeploy-signer-ap-southeast-2.amazonaws.com"
|
144
|
-
else
|
145
|
-
raise "Unknown region '#{@region}'"
|
146
|
-
end
|
136
|
+
cert.subject.to_s == "/C=US/ST=Washington/L=Seattle/O=Amazon.com, Inc./CN=codedeploy-signer-"+@@region+".amazonaws.com"
|
147
137
|
else
|
148
138
|
raise "Unknown profile '#{Config.config()[:codedeploy_test_profile]}'"
|
149
139
|
end
|
@@ -52,6 +52,7 @@ module InstanceAgent
|
|
52
52
|
def to_json
|
53
53
|
log = @log.log || []
|
54
54
|
log = log.join("")
|
55
|
+
log.force_encoding("utf-8")
|
55
56
|
{'error_code' => @error_code, 'script_name' => @script_name, 'message' => message, 'log' => log}.to_json
|
56
57
|
end
|
57
58
|
end
|
@@ -72,6 +73,8 @@ module InstanceAgent
|
|
72
73
|
@deployment_id = arguments[:deployment_id]
|
73
74
|
@application_name = arguments[:application_name]
|
74
75
|
@deployment_group_name = arguments[:deployment_group_name]
|
76
|
+
@deployment_group_id = arguments[:deployment_group_id]
|
77
|
+
@current_deployment_root_dir = arguments[:deployment_root_dir]
|
75
78
|
select_correct_deployment_root_dir(arguments[:deployment_root_dir], arguments[:last_successful_deployment_dir])
|
76
79
|
return if @deployment_root_dir.nil?
|
77
80
|
@deployment_archive_dir = File.join(@deployment_root_dir, 'deployment-archive')
|
@@ -82,8 +85,8 @@ module InstanceAgent
|
|
82
85
|
@child_envs={'LIFECYCLE_EVENT' => @lifecycle_event.to_s,
|
83
86
|
'DEPLOYMENT_ID' => @deployment_id.to_s,
|
84
87
|
'APPLICATION_NAME' => @application_name,
|
85
|
-
'DEPLOYMENT_GROUP_NAME' => @deployment_group_name
|
86
|
-
|
88
|
+
'DEPLOYMENT_GROUP_NAME' => @deployment_group_name,
|
89
|
+
'DEPLOYMENT_GROUP_ID' => @deployment_group_id}
|
87
90
|
end
|
88
91
|
|
89
92
|
def execute
|
@@ -94,7 +97,7 @@ module InstanceAgent
|
|
94
97
|
log_script("LifecycleEvent - " + @lifecycle_event + "\n", script_log_file)
|
95
98
|
hooks.each do |script|
|
96
99
|
if(!File.exist?(script_absolute_path(script)))
|
97
|
-
raise ScriptError.new(ScriptError::SCRIPT_MISSING_CODE, script.location, @script_log), 'Script does not exist at specified location: ' + script
|
100
|
+
raise ScriptError.new(ScriptError::SCRIPT_MISSING_CODE, script.location, @script_log), 'Script does not exist at specified location: ' + File.expand_path(script_absolute_path(script))
|
98
101
|
elsif(!InstanceAgent::Platform.util.script_executable?(script_absolute_path(script)))
|
99
102
|
log :warn, 'Script at specified location: ' + script.location + ' is not executable. Trying to make it executable.'
|
100
103
|
begin
|
@@ -153,7 +156,7 @@ module InstanceAgent
|
|
153
156
|
|
154
157
|
private
|
155
158
|
def create_script_log_file_if_needed
|
156
|
-
script_log_file_location = File.join(@
|
159
|
+
script_log_file_location = File.join(@current_deployment_root_dir, 'logs/scripts.log')
|
157
160
|
if(!File.exists?(script_log_file_location))
|
158
161
|
unless File.directory?(File.dirname(script_log_file_location))
|
159
162
|
FileUtils.mkdir_p(File.dirname(script_log_file_location))
|
@@ -217,6 +220,7 @@ module InstanceAgent
|
|
217
220
|
@hook_logging_mutex.synchronize do
|
218
221
|
@script_log.append_to_log(message)
|
219
222
|
script_log_file.write(Time.now.to_s[0..-7] + ' ' + message)
|
223
|
+
InstanceAgent::DeploymentLog.instance.log("[#{@deployment_id}]#{message.strip}") if InstanceAgent::Config.config[:enable_deployments_log]
|
220
224
|
script_log_file.flush
|
221
225
|
end
|
222
226
|
end
|
@@ -205,7 +205,9 @@ module InstanceAgent
|
|
205
205
|
|
206
206
|
def execute
|
207
207
|
#If the file doesn't exist the command is ignored
|
208
|
-
if File.
|
208
|
+
if File.symlink?(@file_path)
|
209
|
+
FileUtils.rm(@file_path)
|
210
|
+
elsif File.exist?(@file_path)
|
209
211
|
if File.directory?(@file_path)
|
210
212
|
# TODO (AWSGLUE-713): handle the exception if the directory is non-empty;
|
211
213
|
# this might mean the customer has put files in this directory and we should
|
data/lib/instance_metadata.rb
CHANGED
@@ -6,7 +6,7 @@ class InstanceMetadata
|
|
6
6
|
|
7
7
|
IP_ADDRESS = '169.254.169.254'
|
8
8
|
PORT = 80
|
9
|
-
|
9
|
+
|
10
10
|
def self.host_identifier
|
11
11
|
doc = JSON.parse(http_get('/latest/dynamic/instance-identity/document').strip)
|
12
12
|
"arn:aws:ec2:#{doc['region']}:#{doc['accountId']}:instance/#{doc['instanceId']}"
|