dont_deploy_debug 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ZGM1OTAxZWEwM2M2Y2VlOGQ2MDI0MjE5OTA0Y2VkMmM1NzczODAwZg==
5
+ data.tar.gz: !binary |-
6
+ MTRmY2JlODhmNTRjYzkwZmE0MjRkMjY2ZWJkZGNlZTcwYjdiYmNlNQ==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ MDZkZDFhNjA2ZmU0OTA2NzQ3YzdiM2Y3MGVjODI1M2ViOWQwMThmMmEzZTFj
10
+ MzNiMzUzN2M4YjJkMTJiZGFlZDNkMWJjMjgxZjU2ODc0YWU3ZTAxMDgzNjk2
11
+ ZWQ3MDc4NDkyNTYyNzQ2MTIyNWY5MzQ5MmM2ZGI0MjA3Y2FkMjc=
12
+ data.tar.gz: !binary |-
13
+ MzZlYjM5NzE5YWFhNWJiYWM0ZmI1NGI3ZjRmMjg4NTY0YTI0YThjNTAxZTQ2
14
+ ODI3OWY3ZjdmOWI2OTg2NWVmYTk2OTZlYTZhNjZkYjEyNjFmMjFmMzNkMjgy
15
+ NTc4Y2JiMDIwMGQ5NzJjZGE3MmI1MDNjZDFkZDFmY2RhZmI3ODI=
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Matthew Nielsen
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,200 @@
1
+ # DontDeployDebug
2
+ ## A gem against brain-farts.
3
+
4
+ How many times have you accidentally committed a debug statement and deployed
5
+ it? To production? Ugh! I've been there, brothers and sisters! I've done it
6
+ more times than I care to remember. So many that I finally decided to do
7
+ something about it.
8
+
9
+ ## What?
10
+
11
+ It prevents code that has debug statements included from being deployed by
12
+ Capistrano, along with a message about what was found and where to find it.
13
+
14
+ Example:
15
+
16
+ ```
17
+ triggering after callbacks for `deploy:finalize_update'
18
+ * 2013-11-05 16:38:44 executing `deploy:find_ruby_breakpoints'
19
+ * executing "find /home/deploy/app/releases/20131105233842 -name \"*.rb\" -exec grep -Hn --regex \"[debugger|binding\\.pry]\" {} \\;"
20
+ servers: ["server.example.org"]
21
+ [server.example.org] executing command
22
+ command finished in 621ms
23
+
24
+ *** Ruby debugger breakpoint found in deployed code. Deploy halted. ***
25
+
26
+ There was code found that contains debugging breakpoints:
27
+
28
+ /testfile.rb:3:require 'ruby-debug'; debugger
29
+
30
+ Please remove the code, commit the change and try your deploy again.
31
+ If you feel you have reached this message in error, please consult
32
+ https://github.com/xunker/dont_deploy_debug to learn how to exclude
33
+ certain files, or how to tune the detection parameters. To override
34
+ this check, set the 'IGNORE_RUBY_BREAKPOINTS' variable to true:
35
+
36
+ $ IGNORE_RUBY_BREAKPOINTS=true cap <environment> deploy
37
+
38
+ *** [deploy:update_code] rolling back
39
+ * executing "rm -rf /home/deploy/app/releases/20131105233842; true"
40
+ servers: ["server.example.org"]
41
+ [server.example.org] executing command
42
+ command finished in 159ms
43
+ ```
44
+
45
+ ## Why?
46
+
47
+ Because even the rockstar-iest of ninjas sometimes forget to remove a 'debug'.
48
+
49
+ ## How?
50
+
51
+ It's a gem that hooks in to your Capistrano deploy process. After the code is
52
+ updated on the server, but before it's made "live", the gem scans the release
53
+ path for ruby source files that have "debug" statements in them. If any are
54
+ found, the deploy is halted and rolled back, and a list of the offending files
55
+ is displayed to the user.
56
+
57
+ By default, the gem looks for statements in `*.rb` that are like:
58
+
59
+ ```ruby
60
+ require 'ruby-debug'; debugger
61
+
62
+ require 'ruby-debug'
63
+ debugger
64
+
65
+ debugger;
66
+
67
+ binding.pry
68
+ ```
69
+
70
+ The gem will ignore `test/*`, `spec/*`, `features/*` and `config/deploy.rb`.
71
+
72
+ ## Ruby only?
73
+
74
+ Yes, for now. But if there is any interest it could be easily modified for
75
+ any language where the source was parsable on the deployment server.
76
+
77
+ ## Installation
78
+
79
+ Add this line to your application's Gemfile:
80
+
81
+ gem 'dont_deploy_debug', :require => false
82
+
83
+ Or from the command line if you aren't using bunder:
84
+
85
+ $ gem install dont_deploy_debug
86
+
87
+ Then, add the following to your Capistrano `deploy.rb`:
88
+
89
+ require 'capistrano/dont_deploy_debug'
90
+
91
+ For basic usage, this is all that is required.
92
+
93
+ ## Configuration
94
+
95
+ ### Enable or disable the check
96
+
97
+ Be default, every deploy will be checked regardless of environment. This can
98
+ be set programmatically by altering the 'skip_ruby_breakpoint_check' setting
99
+ in your deloy.rb file:
100
+
101
+ ```ruby
102
+ # turn off for all
103
+ set :skip_ruby_breakpoint_check, true
104
+
105
+ # skip on stage
106
+ set :skip_ruby_breakpoint_check, (fetch(:rails_env) == 'stage')
107
+
108
+ # on for everyone (default)
109
+ set :skip_ruby_breakpoint_check, false
110
+ ```
111
+
112
+ ### Files to exclude from check
113
+
114
+ By default, `test/*`, `spec/*`, `features/*` and `config/deploy.rb` are
115
+ ignored. You can modify this behaviour by changing the
116
+ 'exclude_from_ruby_breakpoint_check' setting in your deploy.rb and adding or
117
+ removing regular expressions:
118
+
119
+ ```ruby
120
+ set :exclude_from_ruby_breakpoint_check, [
121
+ /^\.\/config\/deploy\.rb$/,
122
+ /^\.\/spec\//,
123
+ /^\.\/test\//,
124
+ /^\.\/features\//,
125
+ /^\.\/something_else_here\//,
126
+ ]
127
+ ```
128
+
129
+ ### Breakpoint patterns
130
+
131
+ By default, the gem will look for variations of:
132
+
133
+ ```ruby
134
+ require 'ruby-debug'; debugger
135
+
136
+ binding.pry
137
+ ```
138
+
139
+ This can be changed by altering the "ruby_breakpoint_patterns" setting in your
140
+ `deploy.rb` and adding or removing regular expressions:
141
+
142
+ ```ruby
143
+ set :ruby_breakpoint_patterns, [
144
+ /require [\'\"]ruby-debug[\'\"][;\n]\s*debugger/,
145
+ /^\s*debugger[;\n]/,
146
+ /^\s*debugger\s*$/,
147
+ /\bbinding\.pry\b/,
148
+ /some_other_debugger/
149
+ ]
150
+ ```
151
+
152
+ ### Server-side grep command
153
+
154
+ To first find the files, the gem executes a grep() of the release path to get
155
+ "coarse" list of files and then lets ruby do the actual check. The command
156
+ used by default is:
157
+
158
+ ```
159
+ find #{release_path} -name "*.rb" -exec grep -Hn --regex "[debugger|binding\.pry]" {} \\;
160
+ ```
161
+
162
+ A find() and grep() is used instead of a recursive grep because I have no way
163
+ of knowing if you are deploying to system with BSD, SYSV or GNU style tools.
164
+
165
+ You can change this command in your `deploy.rb` with the
166
+ "ruby_breakpoint_grep_command" setting:
167
+
168
+ ```ruby
169
+ # default value is:
170
+ # Proc.new { "find #{release_path} -name \"*.rb\" -exec grep -Hn #{fetch(:ruby_breakpoint_trigger)} {} \\;" }
171
+
172
+ # pass it a Proc object so we can read release_path and other variables
173
+ # It MUST return a string
174
+ set :ruby_breakpoint_grep_command, Proc.new { "some better grep here" }
175
+ ```
176
+
177
+ If you only want to change the pattern that grep() uses, you can set
178
+ "ruby_breakpoint_trigger" instead:
179
+
180
+ ```ruby
181
+ # default value is '--regex "[debugger|binding\.pry]"'
182
+ set :ruby_breakpoint_trigger, "some_other_pattern"
183
+ ```
184
+
185
+ ### Skipping check from command line
186
+
187
+ Finally, if you just want to deploy the damn'ed thing and skip the check
188
+ temporarily, you can set the "IGNORE_RUBY_BREAKPOINTS" shell variable:
189
+
190
+ ```
191
+ $ IGNORE_RUBY_BREAKPOINTS=true cap <environment> deploy
192
+ ```
193
+
194
+ ## Caveats
195
+
196
+ This gem has not been throughly tested in any way. Like seriously. I use it,
197
+ but I'm the only one so far. I know it works on Redhat linux and it will likely
198
+ work in most linuxes. It *should* work on any BSD system, but YMMV.
199
+
200
+ If you find a case where it doesn't work please let me know.
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "dont_deploy_debug"
7
+ spec.version = "0.1.1"
8
+ spec.authors = ["Matthew Nielsen"]
9
+ spec.email = ["xunker@pyxidis.org"]
10
+ spec.description = %q{Don't allow a capistrano deploy if code contains ruby debug statements}
11
+ spec.summary = %q{Don't allow a capistrano deploy if code contains ruby debug statements}
12
+ spec.homepage = "https://github.com/xunker/dont_deploy_debug"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files`.split($/)
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_dependency 'capistrano'
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ end
@@ -0,0 +1,92 @@
1
+ require 'capistrano'
2
+
3
+ module Capistrano
4
+ module DontDeployDebug
5
+ def contains_ruby_breakpoint?(ruby_code)
6
+ ruby_code = ruby_code.split('#').first.strip
7
+ return false if ruby_code.size < 1
8
+ fetch(:ruby_breakpoint_patterns).each do |pattern|
9
+ return true if ruby_code =~ pattern
10
+ end
11
+ false
12
+ end
13
+
14
+ def exclude_from_ruby_breakpint_check?(file_path)
15
+ fetch(:exclude_from_ruby_breakpoint_check).each do |pattern|
16
+ return true if file_path =~ pattern
17
+ end
18
+ false
19
+ end
20
+ end
21
+ end
22
+
23
+ include Capistrano::DontDeployDebug
24
+
25
+ configuration = Capistrano::Configuration.respond_to?(:instance) ?
26
+ Capistrano::Configuration.instance(:must_exist) :
27
+ Capistrano.configuration(:must_exist)
28
+
29
+ configuration.load do
30
+
31
+ set :exclude_from_ruby_breakpoint_check, [
32
+ /^\.\/config\/deploy\.rb$/,
33
+ /^\.\/spec\//,
34
+ /^\.\/test\//,
35
+ /^\.\/features\//
36
+ ]
37
+
38
+ set :ruby_breakpoint_patterns, [
39
+ /require [\'\"]ruby-debug[\'\"][;\n]\s*debugger/,
40
+ /^\s*debugger[;\n]/,
41
+ /^\s*debugger\s*$/,
42
+ /\bbinding\.pry\b/
43
+ ]
44
+
45
+ set :ruby_breakpoint_trigger, '--regex "[debugger|binding\.pry]"'
46
+
47
+ set :ruby_breakpoint_grep_command, Proc.new { "find #{release_path} -name \"*.rb\" -exec grep -Hn #{fetch(:ruby_breakpoint_trigger)} {} \\;" }
48
+
49
+ set :skip_ruby_breakpoint_check, false
50
+
51
+ after "deploy:finalize_update", "deploy:find_ruby_breakpoints"
52
+
53
+ namespace :deploy do
54
+ task :find_ruby_breakpoints do
55
+ if fetch(:skip_ruby_breakpoint_check) || ENV['IGNORE_RUBY_BREAKPOINTS'].to_s != "true"
56
+ files = capture(fetch(:ruby_breakpoint_grep_command)).to_s.split("\n")
57
+ found = []
58
+ files.each do |f|
59
+ (file_path, line_number, ruby_code) = f.split(':', 3)
60
+ next if exclude_from_ruby_breakpint_check?(file_path)
61
+ next unless contains_ruby_breakpoint?(ruby_code)
62
+ found << [file_path.sub(release_path,''), line_number, ruby_code]
63
+ end
64
+
65
+ if found.size>0
66
+ message = [
67
+ "",
68
+ "*** Ruby debugger breakpoint found in deployed code. Deploy halted. ***",
69
+ "",
70
+ "There was code found that contains debugging breakpoints:",
71
+ ""
72
+ ]
73
+ found.each { |f| message << "\t#{f.join(':')}" }
74
+ message += [
75
+ "",
76
+ "Please remove the code, commit the change and try your deploy again.",
77
+ "If you feel you have reached this message in error, please consult",
78
+ "https://github.com/xunker/dont_deploy_debug to learn how to exclude",
79
+ "certain files, or how to tune the detection parameters. To override",
80
+ "this check, set the 'IGNORE_RUBY_BREAKPOINTS' variable to true:",
81
+ "",
82
+ "\t$ IGNORE_RUBY_BREAKPOINTS=true cap <environment> deploy",
83
+ "\n"
84
+ ]
85
+ abort(message.join("\n"))
86
+ end
87
+ end
88
+
89
+ abort("You're testing. I'm stopping now.") if ENV['TESTING_DDD']
90
+ end
91
+ end
92
+ end
@@ -0,0 +1 @@
1
+ require 'capistrano/dont_deploy_debug'
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dont_deploy_debug
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Matthew Nielsen
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-11-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: capistrano
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ! '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ! '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Don't allow a capistrano deploy if code contains ruby debug statements
56
+ email:
57
+ - xunker@pyxidis.org
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - dont_deploy_debug.gemspec
68
+ - lib/capistrano/dont_deploy_debug.rb
69
+ - lib/dont_deploy_debug.rb
70
+ homepage: https://github.com/xunker/dont_deploy_debug
71
+ licenses:
72
+ - MIT
73
+ metadata: {}
74
+ post_install_message:
75
+ rdoc_options: []
76
+ require_paths:
77
+ - lib
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ requirements: []
89
+ rubyforge_project:
90
+ rubygems_version: 2.1.10
91
+ signing_key:
92
+ specification_version: 4
93
+ summary: Don't allow a capistrano deploy if code contains ruby debug statements
94
+ test_files: []