capistrano-payload 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,41 @@
1
+ !.gitignore
2
+ *.gem
3
+ *.rbc
4
+ *.sw[a-p]
5
+ *.tmproj
6
+ *.tmproject
7
+ *.un~
8
+ *~
9
+ .DS_Store
10
+ .Spotlight-V100
11
+ .Trashes
12
+ ._*
13
+ .bundle
14
+ .config
15
+ .directory
16
+ .elc
17
+ .redcar
18
+ .yardoc
19
+ /.emacs.desktop
20
+ /.emacs.desktop.lock
21
+ Desktop.ini
22
+ Gemfile.lock
23
+ Icon?
24
+ InstalledFiles
25
+ Session.vim
26
+ Thumbs.db
27
+ \#*\#
28
+ _yardoc
29
+ auto-save-list
30
+ coverage
31
+ doc/
32
+ lib/bundler/man
33
+ pkg
34
+ pkg/*
35
+ rdoc
36
+ spec/reports
37
+ test/tmp
38
+ test/version_tmp
39
+ tmp
40
+ tmtags
41
+ tramp
@@ -0,0 +1,54 @@
1
+
2
+ # Capistrano Payload
3
+
4
+ Capistrano plugin that delivers JSON-encoded deployment information via POST to the URL of your choice.
5
+
6
+ ## Installation
7
+
8
+ gem install capistrano-payload
9
+
10
+ ## Usage
11
+
12
+ Add payload plugin into your deploy.rb file:
13
+
14
+ require 'capistrano-payload'
15
+
16
+ Then configure URL:
17
+
18
+ set :payload_url, "http://your.awesome.url.com/payload"
19
+
20
+ To test if it works type:
21
+
22
+ cap payload:deploy
23
+
24
+ ## Payload structure
25
+
26
+ Plugin will sent JSON-encoded data via POST method.
27
+
28
+ Here is the sample payload:
29
+
30
+ {
31
+ "capistrano": {
32
+ "application": "APP_NAME",
33
+ "deployer": "sosedoff",
34
+ "timestamp": "2011-07-21 19:09:52 -0500",
35
+ "source": {
36
+ "branch": "master",
37
+ "revision": "b18ffa822c16c028765800d0c4d22bfd5e4f3bf9",
38
+ "repository": "git@github.com:repository.git"
39
+ },
40
+ "action": "deploy"
41
+ }
42
+ }
43
+
44
+ That's it. Ready to roll.
45
+
46
+ ## License
47
+
48
+ Copyright © 2011 Dan Sosedoff.
49
+
50
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
51
+
52
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
53
+
54
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/capistrano-payload/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.name = 'capistrano-payload'
6
+ gem.version = CapistranoPayload::VERSION.dup
7
+ gem.author = 'Dan Sosedoff'
8
+ gem.email = 'dan.sosedoff@gmail.com'
9
+ gem.homepage = 'https://github.com/sosedoff/capistrano-payload'
10
+ gem.summary = %q{JSON webhook on capistrano deployments}
11
+ gem.description = %q{Capistrano plugin that delivers JSON payload to the specified URL}
12
+
13
+ gem.files = `git ls-files`.split("\n")
14
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
15
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{|f| File.basename(f)}
16
+ gem.require_paths = ['lib']
17
+
18
+ gem.add_development_dependency 'rspec', '~> 2.6'
19
+
20
+ gem.add_runtime_dependency 'capistrano', '~> 2.6'
21
+ gem.add_runtime_dependency 'rest-client', '~> 1.6'
22
+ gem.add_runtime_dependency 'multi_json', '~> 1.0'
23
+ end
@@ -0,0 +1,2 @@
1
+ require 'capistrano-payload/payload'
2
+ require 'capistrano-payload/capistrano_integration'
@@ -0,0 +1,55 @@
1
+ require 'capistrano'
2
+
3
+ module CapistranoPayload
4
+ class CapistranoIntegration
5
+ def self.load_into(capistrano_config)
6
+ capistrano_config.load do
7
+ _cset(:payload_url) {
8
+ abort 'Payload URL required! set :payload_url'
9
+ }
10
+
11
+ _cset(:payload_format) { :json }
12
+
13
+ _cset(:payload_data) {
14
+ {
15
+ :application => fetch(:application),
16
+ :deployer => ENV['USER'] || ENV['USERNAME'] || 'n/a',
17
+ :timestamp => Time.now,
18
+ :source => {
19
+ :branch => fetch(:branch),
20
+ :revision => fetch(:real_revision),
21
+ :repository => fetch(:repository)
22
+ }
23
+ }
24
+ }
25
+
26
+ namespace :payload do
27
+ task :deploy, :roles => :app do
28
+ logger.debug("Sending deployment notification to #{fetch(:payload_url)}")
29
+ begin
30
+ CapistranoPayload::Payload.new('deploy', payload_data).deliver(fetch(:payload_url))
31
+ rescue DeliveryError => err
32
+ logger.debug("Payload delivery error: #{err.message}")
33
+ end
34
+ end
35
+
36
+ task :rollback, :roles => :app do
37
+ logger.debug("Sending rollback notification to #{fetch(:payload_url)}")
38
+ begin
39
+ CapistranoPayload::Payload.new('rollback', payload_data).deliver(fetch(:payload_url))
40
+ rescue DeliveryError => err
41
+ logger.debug("Payload delivery error: #{err.message}")
42
+ end
43
+ end
44
+ end
45
+
46
+ after :deploy, 'payload:deploy'
47
+ after :rollback, 'payload:rollback'
48
+ end
49
+ end
50
+ end
51
+ end
52
+
53
+ if Capistrano::Configuration.instance
54
+ CapistranoPayload::CapistranoIntegration.load_into(Capistrano::Configuration.instance)
55
+ end
@@ -0,0 +1,44 @@
1
+ require 'rest-client'
2
+ require 'multi_json'
3
+
4
+ module CapistranoPayload
5
+ class DeliveryError < StandardError ; end
6
+
7
+ class Payload
8
+ attr_reader :action
9
+ attr_reader :data
10
+ attr_reader :params
11
+
12
+ # Initialize a new Payload object
13
+ #
14
+ # action - Deployment action (deploy, rollback)
15
+ # data - Deployment parameters
16
+ # params - Extra parameters to payload (api_key, etc.), default: {}
17
+ # Could not contain 'capistrano' key. Will be removed if present.
18
+ #
19
+ def initialize(action, data, params={})
20
+ @action = action
21
+ @data = data.merge(:action => action)
22
+ @params = params
23
+
24
+ # Check if we have 'capistrano' keys (string or symbolic)
25
+ unless @params.empty?
26
+ @params.delete(:capistrano)
27
+ @params.delete('capistrano')
28
+ end
29
+ end
30
+
31
+ # Performs payload delivery
32
+ #
33
+ # url - Target url
34
+ #
35
+ def deliver(url)
36
+ payload = MultiJson.encode({:capistrano => @data}.merge(@params))
37
+ begin
38
+ RestClient.post(url, payload, :content_type => :json)
39
+ rescue Exception => ex
40
+ raise DeliveryError, ex.message
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,3 @@
1
+ module CapistranoPayload
2
+ VERSION = "0.1.0".freeze unless defined? ::CapistranoPayload::VERSION
3
+ end
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano-payload
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.1.0
6
+ platform: ruby
7
+ authors:
8
+ - Dan Sosedoff
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-07-21 00:00:00 -05:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: rspec
18
+ prerelease: false
19
+ requirement: &id001 !ruby/object:Gem::Requirement
20
+ none: false
21
+ requirements:
22
+ - - ~>
23
+ - !ruby/object:Gem::Version
24
+ version: "2.6"
25
+ type: :development
26
+ version_requirements: *id001
27
+ - !ruby/object:Gem::Dependency
28
+ name: capistrano
29
+ prerelease: false
30
+ requirement: &id002 !ruby/object:Gem::Requirement
31
+ none: false
32
+ requirements:
33
+ - - ~>
34
+ - !ruby/object:Gem::Version
35
+ version: "2.6"
36
+ type: :runtime
37
+ version_requirements: *id002
38
+ - !ruby/object:Gem::Dependency
39
+ name: rest-client
40
+ prerelease: false
41
+ requirement: &id003 !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ~>
45
+ - !ruby/object:Gem::Version
46
+ version: "1.6"
47
+ type: :runtime
48
+ version_requirements: *id003
49
+ - !ruby/object:Gem::Dependency
50
+ name: multi_json
51
+ prerelease: false
52
+ requirement: &id004 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ~>
56
+ - !ruby/object:Gem::Version
57
+ version: "1.0"
58
+ type: :runtime
59
+ version_requirements: *id004
60
+ description: Capistrano plugin that delivers JSON payload to the specified URL
61
+ email: dan.sosedoff@gmail.com
62
+ executables: []
63
+
64
+ extensions: []
65
+
66
+ extra_rdoc_files: []
67
+
68
+ files:
69
+ - .gitignore
70
+ - README.md
71
+ - capistrano-payload.gemspec
72
+ - lib/capistrano-payload.rb
73
+ - lib/capistrano-payload/capistrano_integration.rb
74
+ - lib/capistrano-payload/payload.rb
75
+ - lib/capistrano-payload/version.rb
76
+ has_rdoc: true
77
+ homepage: https://github.com/sosedoff/capistrano-payload
78
+ licenses: []
79
+
80
+ post_install_message:
81
+ rdoc_options: []
82
+
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: "0"
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ none: false
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: "0"
97
+ requirements: []
98
+
99
+ rubyforge_project:
100
+ rubygems_version: 1.6.2
101
+ signing_key:
102
+ specification_version: 3
103
+ summary: JSON webhook on capistrano deployments
104
+ test_files: []
105
+