captainu-chinook 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5e50abbbf391251d5cd09e71383b810c7c5b22d6
4
+ data.tar.gz: 02f105868f519e6577353bbff5afb95dab8feb71
5
+ SHA512:
6
+ metadata.gz: 765fb463ef4a0591d9d6f0c762b9b96c0e56ddf02f3052de094e0a01d87e7a1cfba3d0b08f33f89716bd89fe53c8b480970b5e5cacef0ccb2b4cf31369c1c9b8
7
+ data.tar.gz: e194e512cac75df42c89e169652683fa7d9de4bb74bf291250a7a205b2b00168ed78dbc9ede7619fd683f00528911a05b6e3248523a2a457bf2e67bc3ee9315a
data/.gitignore ADDED
@@ -0,0 +1,34 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /test/tmp/
9
+ /test/version_tmp/
10
+ /tmp/
11
+
12
+ ## Specific to RubyMotion:
13
+ .dat*
14
+ .repl_history
15
+ build/
16
+
17
+ ## Documentation cache and generated files:
18
+ /.yardoc/
19
+ /_yardoc/
20
+ /doc/
21
+ /rdoc/
22
+
23
+ ## Environment normalisation:
24
+ /.bundle/
25
+ /lib/bundler/man/
26
+
27
+ # for a library or gem, you might want to ignore these files since the code is
28
+ # intended to run in multiple environments; otherwise, check them in:
29
+ Gemfile.lock
30
+ .ruby-version
31
+ .ruby-gemset
32
+
33
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
34
+ .rvmrc
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in chinook.gemspec
4
+ gemspec
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/chinook.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'chinook/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'captainu-chinook'
8
+ spec.version = Chinook::VERSION
9
+ spec.authors = ['Ben Kreeger']
10
+ spec.email = ['ben@captainu.com']
11
+ spec.summary = %q{Abstraction of Capistrano v2 deployment tasks.}
12
+ spec.homepage = 'https://github.com/captainu/chinook'
13
+ spec.license = 'MIT'
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
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_runtime_dependency 'capistrano', '~> 2.15.5'
21
+ spec.add_runtime_dependency 'tinder', '~> 1.9.4'
22
+
23
+ spec.add_development_dependency 'bundler', '~> 1.5'
24
+ spec.add_development_dependency 'rake'
25
+ end
data/lib/chinook.rb ADDED
@@ -0,0 +1,5 @@
1
+ require 'chinook/version'
2
+
3
+ module Chinook
4
+ # Your code goes here...
5
+ end
@@ -0,0 +1,3 @@
1
+ module Chinook::Capistrano; end
2
+
3
+ %w(campfire passenger ping).each { |m| require "chinook/capistrano/#{m}" }
@@ -0,0 +1,57 @@
1
+ # Defines a task that will let a Campfire room know about a deploy.
2
+ require 'capistrano'
3
+ require 'tinder'
4
+
5
+ module Chinook::Capistrano
6
+ module Campfire
7
+ def self.load_into(configuration)
8
+ configuration.load do
9
+ namespace :chinook do
10
+ desc 'Lets a Campfire room know about a deploy that is about to start.'
11
+ task :campfire_start, except: { no_release: true } do
12
+ unless exists?(:campfire_room_name) && exists?(:campfire_token) && exists?(:campfire_account_name)
13
+ logger.info 'Cannot notify Campfire without :campfire_room_name, :campfire_token, and :campfire_account_name. Skipping task.'
14
+ next
15
+ end
16
+
17
+ project_name = fetch(:project_name, application)
18
+ git_username = `git config user.name`.chomp
19
+
20
+ message = "#{git_username} started a deploy of #{project_name} to #{stage} at #{Time.now.strftime('%r %Z')}."
21
+ room_name = fetch(:campfire_room_name)
22
+ token = fetch(:campfire_token)
23
+ account_name = fetch(:campfire_account_name)
24
+
25
+ campfire = Tinder::Campfire.new(account_name, token: token)
26
+ room = campfire.find_room_by_name(room_name)
27
+ room.speak(message)
28
+ end
29
+
30
+ desc 'Lets a Campfire room know about a deploy has finished.'
31
+ task :campfire_end, except: { no_release: true } do
32
+ unless exists?(:campfire_room_name) && exists?(:campfire_token) && exists?(:campfire_account_name)
33
+ logger.info 'Cannot notify Campfire without :campfire_room_name, :campfire_token, and :campfire_account_name. Skipping task.'
34
+ next
35
+ end
36
+
37
+ project_name = fetch(:project_name, application)
38
+ git_username = `git config user.name`.chomp
39
+
40
+ message = "#{git_username}'s deploy of #{project_name} to #{stage} finished at #{Time.now.strftime('%r %Z')}."
41
+ room_name = fetch(:campfire_room_name)
42
+ token = fetch(:campfire_token)
43
+ account_name = fetch(:campfire_account_name)
44
+
45
+ campfire = Tinder::Campfire.new(account_name, token: token)
46
+ room = campfire.find_room_by_name(room_name)
47
+ room.speak(message)
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
54
+
55
+ if Capistrano::Configuration.instance
56
+ Chinook::Capistrano::Campfire.load_into(Capistrano::Configuration.instance)
57
+ end
@@ -0,0 +1,21 @@
1
+ # Defines a task that will reboot passenger upon deploy.
2
+ require 'capistrano'
3
+
4
+ module Chinook::Capistrano
5
+ module Passenger
6
+ def self.load_into(configuration)
7
+ configuration.load do
8
+ namespace :deploy do
9
+ desc 'Restarts Passenger by touching tmp/restart.txt.'
10
+ task :restart, roles: :app, except: { no_release: true } do
11
+ run "touch #{current_path}/tmp/restart.txt"
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
18
+
19
+ if Capistrano::Configuration.instance
20
+ Chinook::Capistrano::Passenger.load_into(Capistrano::Configuration.instance)
21
+ end
@@ -0,0 +1,37 @@
1
+ # Defines a task that will ping the website after a Passenger restart.
2
+ require 'capistrano'
3
+
4
+ module Chinook::Capistrano
5
+ module Ping
6
+ def self.load_into(configuration)
7
+ configuration.load do
8
+ namespace :chinook do
9
+ desc 'Sends a basic curl request to the website to wake it up.'
10
+ task :ping, except: { no_release: true } do
11
+ unless exists?(:ping_url)
12
+ logger.info 'Cannot ping website without :ping_url defined. Skipping task.'
13
+ next
14
+ end
15
+
16
+ rails_env = fetch(:rails_env, 'production')
17
+ destination = fetch(:ping_url)
18
+ ping_command = "curl -LI #{destination}"
19
+
20
+ logger.info "Pinging website to wake it up at #{destination}"
21
+ if configuration.dry_run
22
+ logger.info "DRY RUN: Ping not sent."
23
+ else
24
+ result = ""
25
+ run(ping_command, once: true) { |ch, stream, data| result << data }
26
+ end
27
+ logger.info "Ping sent; site should now be awake and responsive."
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+
35
+ if Capistrano::Configuration.instance
36
+ Chinook::Capistrano::Ping.load_into(Capistrano::Configuration.instance)
37
+ end
@@ -0,0 +1,3 @@
1
+ module Chinook
2
+ VERSION = '0.1.0'
3
+ end
data/license.markdown ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 CaptainU, LLC.
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.markdown ADDED
@@ -0,0 +1,85 @@
1
+ # Chinook
2
+
3
+ Shared deployment tasks that we use at [CaptainU](http://captainu.com) for our Capistrano deploys. We noticed we've been using a lot of these duplicated tasks per project, so this is an attempt to shoehorn those all into a shared gem that we can add per-project, and with minimal effort, simplify our codebase.
4
+
5
+ ## Installation & Usage
6
+
7
+ Add this line to your application's `Gemfile`, preferrably in the `:development` group next to `capistrano`.
8
+
9
+ ``` ruby
10
+ group :development do
11
+ gem 'captainu-chinook'
12
+ # or from git:
13
+ # gem 'captainu-chinook', git: 'https://github.com/captainu/chinook.git'
14
+ end
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ ``` bash
20
+ $ bundle
21
+ ```
22
+
23
+ Each script will likely have its own set of configuration variables that you'll want to set, and many of them will be environment-specific. The format for these instructions is as follows:
24
+
25
+ ``` ruby
26
+ # ./config/deploy.rb
27
+ # Towards the top of your deploy.rb file, require the library.
28
+
29
+ require 'chinook/capistrano/some_task'
30
+ # Optionally, require the whole kitchen sink with 'chinook/capistrano'
31
+
32
+ # ... Set the necessary variables required by the script.
33
+
34
+ set :ping_url, 'http://some-url-to-ping.example.com'
35
+
36
+ # ... Down a little further, near your other hooks, add the script's deployment task hook.
37
+
38
+ after 'deploy', 'chinook:some_task'
39
+ ```
40
+
41
+ ### Campfire notification
42
+
43
+ Notifies [Campfire](https://campfirenow.com) when a deploy starts and/or stops. Uses the value of `git config user.name` for identifying the deploying user.
44
+
45
+ * Tasks:
46
+ - `chinook:campfire_start`
47
+ - `chinook:campfire_end`
48
+ * Hooks:
49
+ - `before 'deploy', 'chinook:campfire_start'`
50
+ - `after 'deploy', 'chinook:campfire_end'`
51
+ * Settings:
52
+ - `:campfire_room_name`: the room where notifications will be posted.
53
+ - `:campfire_token`: the API token of the user that this task will post as.
54
+ - `:campfire_account_name`: the subdomain of your Campfire account (**this-part**.campfirenow.com).
55
+ - `:project_name`: the name of your project as it will show up in the notifications. *Optional; if not supplied, the value of `:application` will be used.*
56
+
57
+ ### Passenger restart
58
+
59
+ Restarts [Passenger](https://phusionpassenger.com) after deploy by touching the file at `tmp/restart.txt` on the receiving server.
60
+
61
+ * Task: `deploy:restart`
62
+ * Hook: None needed; automatically included
63
+ * Settings: None needed
64
+
65
+ ### Ping
66
+
67
+ Pings the site after a [Passenger](phusionpassenger.com) deploy to ensure that it's immediately up and running following a restart task.
68
+
69
+ * Task: `chinook:ping`
70
+ * Hook: `after 'deploy:restart', 'chinook:ping'`
71
+ * Settings:
72
+ - `:ping_url`: the URL you'd like to ping to wake up. *Environment specific.*
73
+
74
+ ## Contributing
75
+
76
+ 1. [Fork it](https://github.com/captainu/chinook/fork).
77
+ 2. Create your feature branch (`git checkout -b my-new-feature`).
78
+ 3. Commit your changes (`git commit -am 'Add some feature'`).
79
+ 4. Push to the branch (`git push origin my-new-feature`).
80
+ 5. Create a new Pull Request for it and we'll review it!
81
+
82
+ ## Contributors
83
+
84
+ - [Ben Kreeger](https://github.com/kreeger)
85
+ - [Mike Admire](https://github.com/mikeadmire)
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: captainu-chinook
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ben Kreeger
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-03-06 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: 2.15.5
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 2.15.5
27
+ - !ruby/object:Gem::Dependency
28
+ name: tinder
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 1.9.4
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 1.9.4
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.5'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.5'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description:
70
+ email:
71
+ - ben@captainu.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - Gemfile
78
+ - Rakefile
79
+ - chinook.gemspec
80
+ - lib/chinook.rb
81
+ - lib/chinook/capistrano.rb
82
+ - lib/chinook/capistrano/campfire.rb
83
+ - lib/chinook/capistrano/passenger.rb
84
+ - lib/chinook/capistrano/ping.rb
85
+ - lib/chinook/version.rb
86
+ - license.markdown
87
+ - readme.markdown
88
+ homepage: https://github.com/captainu/chinook
89
+ licenses:
90
+ - MIT
91
+ metadata: {}
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubyforge_project:
108
+ rubygems_version: 2.2.0
109
+ signing_key:
110
+ specification_version: 4
111
+ summary: Abstraction of Capistrano v2 deployment tasks.
112
+ test_files: []