Skip to content

Instantly share code, notes, and snippets.

@holyjak
Created January 9, 2018 09:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save holyjak/3796133332cf317fe6acadbf77311445 to your computer and use it in GitHub Desktop.
Save holyjak/3796133332cf317fe6acadbf77311445 to your computer and use it in GitHub Desktop.
Patch Travis CI CodeDeploy support to correctly register revisions
# Modified Travis-CI deployment tool (dpl) provider for AWS CodeDeploy
# that does also correctly register the revision
require 'dpl/cli'
require 'dpl/provider'
require 'dpl/provider/code_deploy'
require 'time'
module DPL
class Provider
class CodeDeployWithRegister < DPL::Provider::CodeDeploy
experimental 'AWS Code Deploy With Register'
def revision_version_info
s3api = ::Aws::S3::Client.new(code_deploy_options) # region, credentials same for all services
s3obj = s3api.get_object({
bucket: option(:bucket),
key: s3_key,
range: "bytes=0-1"
})
end
def s3_revision
s3info = revision_version_info
{
revision_type: 'S3',
s3_location: {
bucket: option(:bucket),
bundle_type: bundle_type,
key: s3_key,
version: s3info[:version_id],
e_tag: s3info[:etag]
}
}
end
def push_app
rev = revision()
if rev[:s3_location]
revInfo = rev[:s3_location]
log "Registering app revision with version=#{revInfo[:version]}, etag=#{revInfo[:e_tag]}"
end
code_deploy.register_application_revision({
revision: rev,
application_name: options[:application] || option(:application_name),
description: options[:description] || default_description
})
super
end
end
end
end
# EXPECTED ARGUMENTS:
# --bucket=..,
# key, application, deployment_group,
# optionally --region etc
args = [
"--provider=codedeploywithregister"].concat(ARGV)
DPL::CLI.run(args)
# To test this from the command line:
# ruby --bucket=my-bucket --key=myapp.zip --application=my-cd-app --deployment_group=my-cd-group-staging \
# --region=eu-west-1 --skip_cleanup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment