Skip to content

Commit d86ab7d

Browse files
author
Eric Hayes
authored
Merge branch 'master' into master
2 parents 299d66f + c510185 commit d86ab7d

File tree

112 files changed

+7108
-690
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

112 files changed

+7108
-690
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,8 @@ Gemfile.lock
33
deployment/
44
coverage/
55
.version
6+
.metadata/
7+
RemoteSystemsTempFiles/
8+
codedeploy-local.log*
9+
codedeploy-local.*.log
10+
deployment/

.rspec

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
--color
2+
--format documentation

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
language: ruby
22
rvm:
3-
- 2.0.0
3+
- 2.3.0
44
after_success: coveralls
55
notifications:
66
email:

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ The integration test creates the following
3030
It terminates the test ec2 instance and deletes the CodeDeploy application at the end of each test run.
3131
It also terminates any test ec2 instances before starting up the test.
3232

33-
Update the features/AwsCredentials.yml file with AWS access key and secret key. The access key should have permission to create the above mentioned resources. You can also change the default region and ami id if you want. To run the integration test execute
34-
33+
Update the features/AwsCredentials.yml file with AWS access key, secret key, and optionally your session token. The access key should have permission to create the above mentioned resources. You can also change the default region and ami id if you want. To run the integration test execute
34+
3535
```
3636
rake test-integration
3737
```

Rakefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
require 'rake'
22
require 'rake/testtask'
3+
require 'rspec/core/rake_task'
34
require 'rubygems'
45

56
# Run all units tests in test/
@@ -14,6 +15,10 @@ end
1415
task :default => [:version_tracking, :test]
1516
task :release => [:version_tracking, :test]
1617

18+
desc "Run unit tests in spec/"
19+
RSpec::Core::RakeTask.new(:spec)
20+
task :test => :spec
21+
1722
begin
1823
require 'cucumber'
1924
require 'cucumber/rake/task'
@@ -41,7 +46,7 @@ def getAgentTrackingInfo
4146
begin
4247
commit_id = `git rev-parse HEAD`.chop!
4348
tracking = "COMMIT_#{commit_id}"
44-
rescue
49+
rescue
4550
tracking = "UNKNOWN_VERSION"
4651
end
4752
end

bin/codedeploy-agent

Lines changed: 17 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,88 +1,27 @@
1-
# 1.9 adds realpath to resolve symlinks; 1.8 doesn't
2-
# have this method, so we add it so we get resolved symlinks
3-
# and compatibility
4-
unless File.respond_to? :realpath
5-
class File #:nodoc:
6-
def self.realpath path
7-
return realpath(File.readlink(path)) if symlink?(path)
8-
path
9-
end
10-
end
11-
end
12-
13-
# Set the environment variables for ruby libs and vendor provided gems
14-
# This is required so that the agent can run without requiring an init script
15-
# if installed as a gem
16-
17-
agent_dir = File.join(File.dirname(__FILE__), "..")
18-
$:.unshift "#{agent_dir}/lib"
19-
20-
require 'instance_agent'
21-
require 'gli'
1+
#!/usr/bin/env ruby
222

23-
include GLI::App
3+
$:.unshift File.join(File.dirname(File.expand_path('..', __FILE__)), 'lib')
244

25-
program_desc 'AWS CodeDeploy Agent'
5+
ruby_versions = ["2.4", "2.3", "2.2", "2.1", "2.0"]
6+
actual_ruby_version = RUBY_VERSION.split('.').map{|s|s.to_i}
7+
left_bound = '2.0.0'.split('.').map{|s|s.to_i}
8+
ruby_bin = nil
269

27-
conf_default_dir = "/etc/codedeploy-agent/conf/codedeployagent.yml"
28-
conf_repo_dir = "#{agent_dir}/conf/codedeployagent.yml"
29-
desc 'Path to agent config file'
30-
if File.file?(conf_default_dir)
31-
default_value conf_default_dir
10+
if (actual_ruby_version <=> left_bound) > -1
11+
ruby_bin = "ruby"
3212
else
33-
default_value conf_repo_dir
34-
end
35-
arg_name "conf_dir"
36-
flag [:config_file,:config_file]
37-
38-
desc 'start the AWS CodeDeploy agent'
39-
command :start do |c|
40-
c.action do |global_options,options,args|
41-
InstanceAgent::Runner::Master.start
42-
end
43-
end
44-
45-
desc 'stop the AWS CodeDeploy agent'
46-
command :stop do |c|
47-
c.action do |global_options,options,args|
48-
InstanceAgent::Runner::Master.stop
49-
if pid = InstanceAgent::Runner::Master.status
50-
raise 'AWS CodeDeploy agent is still running'
13+
ruby_versions.each do |i|
14+
ruby_dir = "/usr/bin/ruby#{i}"
15+
if File.file?(ruby_dir)
16+
ruby_bin = ruby_dir
17+
break
5118
end
5219
end
5320
end
5421

55-
desc 'restart the AWS CodeDeploy agent'
56-
command :restart do |c|
57-
c.action do |global_options,options,args|
58-
InstanceAgent::Runner::Master.restart
59-
end
60-
end
61-
62-
desc 'Report running status of the AWS CodeDeploy agent'
63-
command :status do |c|
64-
c.action do |global_options,options,args|
65-
if pid = InstanceAgent::Runner::Master.status
66-
puts "The AWS CodeDeploy agent is running as PID #{pid}"
67-
else
68-
raise 'No AWS CodeDeploy agent running'
69-
end
70-
end
71-
end
72-
73-
pre do |global,command,options,args|
74-
InstanceAgent::Config.config.keys.each do |config_key|
75-
InstanceAgent::Config.config(config_key => global[config_key]) if global[config_key].present?
76-
end
77-
78-
InstanceAgent::Platform.util = InstanceAgent::LinuxUtil
79-
80-
InstanceAgent::Config.load_config
81-
true
82-
end
83-
84-
on_error do |exception|
85-
true
22+
if ruby_bin
23+
exec("#{ruby_bin} #{File.join(File.expand_path(File.dirname(__FILE__)), "../lib/codedeploy-agent.rb")} #{ARGV.join(' ')}")
8624
end
8725

88-
exit run(ARGV)
26+
STDERR.puts "No supported ruby version found. Code Deploy Host Agent supports Ruby version 2.0.x and greater."
27+
exit(1)

bin/codedeploy-agent-wrapper

Lines changed: 0 additions & 26 deletions
This file was deleted.

bin/codedeploy-local

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#!/usr/bin/env ruby
2+
3+
$:.unshift File.join(File.dirname(File.expand_path('..', __FILE__)), 'lib')
4+
require 'docopt'
5+
6+
require 'aws/codedeploy/local/deployer'
7+
8+
# Initialize the deployer first to initialize the configuration values so they can be used as part of the help message
9+
begin
10+
AWS::CodeDeploy::Local::Deployer.new
11+
rescue
12+
# If we fail to initialize all the configuration values correctly just grab the default location for the config for the help message
13+
InstanceAgent::Config.config[:root_dir] = AWS::CodeDeploy::Local::Deployer::CONF_DEFAULT_LOCATION
14+
end
15+
16+
doc = <<DOCOPT
17+
CodeDeploy Local Deployments.
18+
19+
Usage:
20+
#{__FILE__} [--bundle-location <location>] [--type <type>] [--application-folder <application-folder>|--deployment-group-id <deployment-group-id>] [--configuration-file <configuration-file>] [--event <event>]...
21+
#{__FILE__} -h | --help
22+
#{__FILE__} -v | --version
23+
24+
Options:
25+
-l, --bundle-location <location> Optional Bundle Location. The prefix and suffix determine whether this location is locally accessible or online (s3 or github). Defaults to current directory [default: #{Dir.pwd}]
26+
-t, --type <type> Optional Bundle type choice from tgz, tar, zip, or directory [default: directory]
27+
-g, --application-folder <application-folder> Optional application folder specifies the folder in which the local deployments will be executed [default: #{AWS::CodeDeploy::Local::Deployer::DEFAULT_DEPLOYMENT_GROUP_ID}]. Your configuration shows it would be placed in #{InstanceAgent::Config.config[:root_dir]}/<application-folder>. To configure a custom deployment-root folder see https://docs.aws.amazon.com/codedeploy/latest/userguide/reference-agent-configuration.html. If you want to target a previously deployed revision make sure to use the correct deployment group id by looking it up using the AWS CLI: https://docs.aws.amazon.com/cli/latest/reference/deploy/get-deployment-group.html
28+
-g, --deployment-group-id <deployment-group-id> Optional Deployment Group Id - an alternative to application-folder. The application-folder used during a CodeDeploy deployment is the deployment group's id. Only one can be specified.
29+
-e, --event <event> Optional set of override lifecycle events to run. Any number of lifecycle events can be provided one after another (order matters). If none specificed runs only default events found in the Appspec file using CodeDeploy's ordering. Please note if you don't specify DownloadBundle and Install events they will always precede all your custom events. Those events extract your local bundle / download it as well as install the revision in the correct location. The only events that can run before them are the ones that do so today. See https://docs.aws.amazon.com/codedeploy/latest/userguide/reference-appspec-file-structure-hooks.html
30+
-c, --configuration-file <configuration-file> Optional agent configuration file location which is by default set to /etc/codedeploy-agent/conf/codedeployagent.yml for linux hosts and C:/ProgramData/Amazon/CodeDeploy/conf.yml for Windows. See https://docs.aws.amazon.com/codedeploy/latest/userguide/reference-agent-configuration.html
31+
-h, --help Show this message.
32+
-v, --version Show version.
33+
34+
Examples:
35+
#{__FILE__}
36+
#{__FILE__} --bundle-location /path/to/local/bundle/dir
37+
#{__FILE__} --bundle-location s3://mybucket/bundle.tgz --type tgz
38+
#{__FILE__} --bundle-location /path/to/local/bundle.tgz --type tgz --application-folder local-deployments
39+
#{__FILE__} --bundle-location /path/to/local/bundle.zip --type zip --deployment-group-id 217ba5c8-5dd1-4774-89c6-30b107ac5dca
40+
#{__FILE__} --bundle-location s3://mybucket/bundle.zip?versionId=1234&etag=47e8 --type tgz
41+
#{__FILE__} --bundle-location https://api.github.com/repos/awslabs/aws-codedeploy-sample-tomcat/zipball/master --type zip
42+
#{__FILE__} --bundle-location /path/to/local/bundle.tgz --type tgz -e ApplicationStop -e DownloadBundle -e Install -e ApplicationStart -e HealthCheck -e CustomHook
43+
44+
Stop Previously Deployed Application:
45+
#{__FILE__} --bundle-location s3://mybucket/bundle.tgz --type tgz --deployment-group-id 217ba5c8-5dd1-4774-89c6-30b107ac5dca -e ApplicationStop
46+
#{__FILE__} --bundle-location /path/to/local/bundle.zip --type zip --deployment-group-id 217ba5c8-5dd1-4774-89c6-30b107ac5dca -e ApplicationStop
47+
48+
Specifying AWS Credentials:
49+
#{__FILE__} allows you to provide your aws access key, secret key, and region in multiple ways. It uses the AWS SDK.
50+
This means that if you're using an ec2 host with proper roles configured for the host with proper permissions you don't need to do anything else
51+
to give permission for this host to download your bundle from S3. See https://docs.aws.amazon.com/codedeploy/latest/userguide/getting-started-create-iam-instance-profile.html
52+
The AWS SDK also provides a few other ways to provide credentials. See https://docs.aws.amazon.com/sdkforruby/api/index.html
53+
54+
DOCOPT
55+
56+
begin
57+
args = Docopt::docopt(doc, version: '1.0')
58+
AWS::CodeDeploy::Local::Deployer.new(args['--configuration-file']).execute_events(args)
59+
rescue Docopt::Exit => e
60+
puts e.message
61+
exit(false)
62+
rescue AWS::CodeDeploy::Local::CLIValidator::ValidationError,InstanceAgent::Plugins::CodeDeployPlugin::ScriptError,InstanceMetadata::InstanceMetadataError,SystemCallError => e
63+
puts "ERROR: #{e.message}"
64+
exit(false)
65+
rescue Aws::Errors::MissingCredentialsError => e
66+
puts "ERROR: Unable to download from S3 without AWS Credentials set. Please see help message for how to set AWS Credentials (#{__FILE__} --help)"
67+
exit(false)
68+
end
69+
70+
puts "Successfully deployed your bundle locally"

bin/install

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,8 @@ EOF
230230
def get_s3_uri(region, bucket, key)
231231
if (region == 'us-east-1')
232232
URI.parse("https://#{bucket}.s3.amazonaws.com/#{key}")
233+
elsif (region.split("-")[0] == 'cn')
234+
URI.parse("https://#{bucket}.s3.#{region}.amazonaws.com.cn/#{key}")
233235
else
234236
URI.parse("https://#{bucket}.s3-#{region}.amazonaws.com/#{key}")
235237
end

0 commit comments

Comments
 (0)