File: //proc/8235/cwd/opt/codedeploy-agent/bin/codedeploy-local
#!/usr/bin/env ruby
$:.unshift File.join(File.dirname(File.expand_path('..', __FILE__)), 'lib')
Gem.use_paths(nil, Gem.path << "/opt/codedeploy-agent/vendor")
Gem.use_paths(nil, Gem.path << File.join(File.dirname(File.expand_path('..', __FILE__)), 'vendor'))
require 'docopt'
require 'aws/codedeploy/local/deployer'
require 'instance_agent'
require 'instance_agent/config'
# Initialize the deployer first to initialize the configuration values so they can be used as part of the help message
begin
AWS::CodeDeploy::Local::Deployer.new
rescue
# If we fail to initialize all the configuration values correctly just grab the default location for the config for the help message
InstanceAgent::Config.config[:root_dir] = AWS::CodeDeploy::Local::Deployer::CONF_DEFAULT_LOCATION
end
doc = <<DOCOPT
AWS CodeDeploy Developer Utility
***********************************
Description
***********
The AWS CodeDeploy Developer Utility is a tool you use to run test deployments on local development machines.
This tool lets you quickly validate the integrity of your AWS CodeDeploy application specification (AppSpec) files and deployable content.
To use the AWS CodeDeploy Developer Utility, you do not need to create an AWS CodeDeploy application or deployment group. If the deployable source content resides on the same local machine where you run a test deployment, you also do not need an AWS account.
For the simplest testing, you can run the codedeploy-local command, without specifying any options, in a directory that contains the AppSpec file and the deployable content.
For other test cases, you can choose from a number of options available with the tool. If you have an AWS account, you can test the deployment of content that is stored in a supported remote repository type (Amazon S3 bucket or GitHub repository).
Prerequisites and full documentation
****************************************
See "Use the AWS CodeDeploy Developer Utility to Validate a Deployment Package on a Local Machine" in the AWS CodeDeploy User Guide
Usage:
#{__FILE__} [options]
Synopsis
********
#{__FILE__}
[--bundle-location <value>]
[--type <value>]
[--file-exists-behavior <value>]
[--deployment-group <value>]
[--deployment-group-name <value>]
[--application-name <value>]
[--events <value>]
[--agent-configuration-file <value>]
Options
*******
-l, --bundle-location <value>
The location of the application revision bundle. If you do not specify a location, the tool uses the directory you are currently working in by default. [default: #{Dir.pwd}]
-t, --type <value>
The format of the application revision bundle. Supported types include tgz, tar, zip, and directory. If you do not specify a type, the tool uses directory by default. If you specify --type, you must also specify --bundle-location. [default: directory]
-b, --file-exists-behavior <value>
Indicates how files are handled that already exist in a deployment target location but weren't part of a previous successful deployment. Options include DISALLOW, OVERWRITE, RETAIN. [default: #{InstanceAgent::Plugins::CodeDeployPlugin::DeploymentSpecification::DEFAULT_FILE_EXISTS_BEHAVIOR}].
See also: "create-deployment" in the AWS CLI Reference for AWS CodeDeploy.
-g, --deployment-group <value>
The path to the folder that is the target location for the content to be deployed. If you do not specify a folder, the tool creates one named default-local-deployment-group inside your deployment root directory. For each local deployment you create, the tool creates a subdirectory inside this folder with names like d-98761234-local. Your configuration shows it would be placed in #{InstanceAgent::Config.config[:root_dir]}/<deployment-group>. You can use the :root_dir: variable in an agent configuration file to configure a custom deployment root folder. If you want to deploy to a location previously deployed to by AWS CodeDeploy, you must specify its deployment group ID, which you can look up by using the AWS CLI. [default: #{AWS::CodeDeploy::Local::Deployer::DEFAULT_DEPLOYMENT_GROUP_ID}].
See also: "get-deployment-group” in the AWS CLI Reference for AWS CodeDeploy.
-d, --deployment-group-name <value>
Indicates the deployment group name to be used during the CodeDeploy hook execution, can be accessed on the DEPLOYMENT_GROUP_NAME environment variable. If you do not specify a name, "LocalFleet" will be used.
-a, --application-name <value>
Indicates the application name to be used during the CodeDeploy hook execution, can be accessed on the APPLICATION_NAME environment variable. If you do not specify a name, the "bundle-location" will be used.
-e, --events <comma-separated-values>
A set of lifecycle event hooks you want to run, in order, instead of the events listed in the AppSpec file. Multiple hook names must be separated by commas. If you don't specify DownloadBundle and Install events in the --events list, they will run before all the event hooks you do specify. If you include DownloadBundle and Install in the --events list, they can be preceded only by events that normally run before them in AWS CodeDeploy deployments.
-c, --agent-configuration-file <value>
The location of a configuration file to use for the deployment, if you store it in a location other than the default. A configuration file specifies alternatives to other default values and behaviors for a deployment. By default, configuration files are stored as /etc/codedeploy-agent/conf/codedeployagent.yml (Amazon Linux, RHEL, or Ubuntu Server instances) or C:/ProgramData/Amazon/CodeDeploy/conf.yml (Windows Server).
-h, --help
Displays a summary of help content.
-v, --version
Displays the tool's version number.
Examples
********
#{__FILE__}
#{__FILE__} --bundle-location /path/to/local/bundle/directory
#{__FILE__} --bundle-location /path/to/local/bundle.tgz --type tgz --deployment-group my-deployment-group
#{__FILE__} --bundle-location /path/to/local/bundle/directory --type directory --deployment-group my-deployment-group
Deploy a bundle from Amazon S3
**************************
#{__FILE__} --bundle-location s3://mybucket/bundle.zip?versionId=1234&etag=47e8 --type zip
Deploy a bundle from a public GitHub repository
**************************************************
#{__FILE__} --bundle-location https://github.com/awslabs/aws-codedeploy-sample-tomcat --type zip
#{__FILE__} --bundle-location https://api.github.com/repos/awslabs/aws-codedeploy-sample-tomcat/zipball/master --type zip
Deploy a bundle specifying certain lifecycle events
************************************************************
#{__FILE__} --bundle-location /path/to/local/bundle.tar --type tar --deployment-group my-deployment-group --events ApplicationStop,DownloadBundle,Install,ApplicationStart
Stop a previously deployed application
****************************************
#{__FILE__} --bundle-location /path/to/local/bundle.tgz --type tgz --deployment-group 1234abcd-5dd1-4774-89c6-30b107ac5dcas --events ApplicationStop
Deploy using a specific deployment group ID
************************************************************************
#{__FILE__} --bundle-location C:/path/to/local/bundle/directory --deployment-group 1234abcd-5dd1-4774-89c6-30b107ac5dca
#{__FILE__} --bundle-location C:/path/to/local/bundle.zip --type zip --deployment-group 1234abcd-5dd1-4774-89c6-30b107ac5dca
DOCOPT
begin
args = Docopt::docopt(doc, version: '1.0')
AWS::CodeDeploy::Local::Deployer.new(args['--agent-configuration-file']).execute_events(args)
rescue Docopt::Exit => e
puts e.message
exit(false)
rescue AWS::CodeDeploy::Local::CLIValidator::ValidationError,InstanceMetadata::InstanceMetadataError,SystemCallError,ArgumentError => e
puts "ERROR: #{e.message}"
exit(false)
rescue Aws::Errors::MissingCredentialsError => e
puts "ERROR: We were unable to download content from the Amazon S3 bucket due to missing or invalid credentials. For information about specifying your AWS credentials, see https://aws.amazon.com/blogs/security/a-new-and-standardized-way-to-manage-credentials-in-the-aws-sdks"
exit(false)
rescue InstanceAgent::Plugins::CodeDeployPlugin::ScriptError => e
exit(false)
end
puts "AppSpec file valid. Local deployment successful"