deploy_hooks 0.0.1
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.
- data/.gitignore +17 -0
- data/CHANGELOG.md +3 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +22 -0
- data/README.md +51 -0
- data/Rakefile +1 -0
- data/deploy_hooks.gemspec +25 -0
- data/lib/deploy_hooks.rb +9 -0
- data/lib/deploy_hooks/config.rb +44 -0
- data/lib/deploy_hooks/railtie.rb +12 -0
- data/lib/deploy_hooks/version.rb +3 -0
- data/tasks/deploy.rake +50 -0
- metadata +113 -0
data/.gitignore
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Alex Chernyshev
|
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,51 @@
|
|
1
|
+
# DeployHooks
|
2
|
+
|
3
|
+
This tiny gem allows to define tasks which will start before and/or after deployment app to heroku.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'deploy_hooks', github: 'kenjione/deploy_hooks'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
|
17
|
+
At first u should have rake or thor tasks that will be used as hooks.
|
18
|
+
You need to define your hooks in initializer `initializers/deploy_hooks.rb` like that:
|
19
|
+
|
20
|
+
```ruby
|
21
|
+
DeployHooks.config do |config|
|
22
|
+
config.environments = { stage: 'your-appname-at-stage', production: 'your-appname-at-production' }
|
23
|
+
config.before_deploy = { rake: %w[ your_rake_task ], thor: %w[ your_thor_task ] }
|
24
|
+
config.after_deploy = { rake: %w[ db:migrate another_your_rake_task ], thor: %w[ another_your_thor_task ] }
|
25
|
+
end
|
26
|
+
```
|
27
|
+
|
28
|
+
Also make sure that `[push] default = tracking` has been added to `.git/config` in `your_project_folder`
|
29
|
+
|
30
|
+
After that, you can execute `rake deploy:<environment>` (for example `rake deploy:stage`) for pushing your app to heroku with before_deploy and/or after_deploy hooks.
|
31
|
+
|
32
|
+
## Notice
|
33
|
+
|
34
|
+
This gem was created for personal educational purposes and I'll be glad if it could find application in any other projects.
|
35
|
+
|
36
|
+
## Gratitude
|
37
|
+
|
38
|
+
Thanks to Michael Dwan and his [Article][1]
|
39
|
+
Thanks to [ExReanimator][2] for guiding
|
40
|
+
|
41
|
+
## Contributing
|
42
|
+
|
43
|
+
1. Fork it
|
44
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
45
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
46
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
47
|
+
5. Create new Pull Request
|
48
|
+
|
49
|
+
|
50
|
+
[1]: http://michaeldwan.com/writings/customize-your-heroku-deployment.html "Article"
|
51
|
+
[2]: https://github.com/exreanimator
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -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 'deploy_hooks/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "deploy_hooks"
|
8
|
+
spec.version = DeployHooks::VERSION
|
9
|
+
spec.authors = ["Alex Chernyshev"]
|
10
|
+
spec.email = ["alex.kenjione@gmail.com"]
|
11
|
+
spec.description = %q{User can define tasks which will start before or after deployment}
|
12
|
+
spec.summary = %q{Heroku deployment hooks}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib", "tasks"]
|
20
|
+
|
21
|
+
spec.add_dependency "heroku"
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
24
|
+
spec.add_development_dependency "rake"
|
25
|
+
end
|
data/lib/deploy_hooks.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
module DeployHooks
|
2
|
+
module Config
|
3
|
+
class << self
|
4
|
+
%w(environments before_deploy after_deploy).each do |method|
|
5
|
+
define_method method do
|
6
|
+
instance_eval "@#{method} ||= {}"
|
7
|
+
end
|
8
|
+
|
9
|
+
define_method "#{method}=" do |hash|
|
10
|
+
puts 'needs a hash params' && return unless hash.is_a?(Hash)
|
11
|
+
instance_eval "@#{method} = hash"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
# That means:
|
16
|
+
|
17
|
+
# def environments=(hash)
|
18
|
+
# @environments = hash
|
19
|
+
# end
|
20
|
+
|
21
|
+
# def environments
|
22
|
+
# @environments ||= {}
|
23
|
+
# end
|
24
|
+
|
25
|
+
# def before_deploy=(hash)
|
26
|
+
# @before_deploy = hash
|
27
|
+
# end
|
28
|
+
|
29
|
+
# def before_deploy
|
30
|
+
# @before_deploy ||= {}
|
31
|
+
# end
|
32
|
+
|
33
|
+
# def after_deploy(hash)
|
34
|
+
# @after_deploy = hash
|
35
|
+
# end
|
36
|
+
|
37
|
+
# def after_deploy
|
38
|
+
# @after_deploy ||= {}
|
39
|
+
# end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'deploy_hooks'
|
2
|
+
require 'rails'
|
3
|
+
module DeployHooks
|
4
|
+
class Railtie < Rails::Railtie
|
5
|
+
railtie_name :deploy_hooks
|
6
|
+
|
7
|
+
rake_tasks do
|
8
|
+
spec = Gem::Specification.find_by_name 'deploy_hooks'
|
9
|
+
load "#{spec.gem_dir}/tasks/deploy.rake"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
data/tasks/deploy.rake
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
# List of environments and their heroku git remotes
|
2
|
+
|
3
|
+
require File.expand_path('config/initializers/deploy_hooks.rb')
|
4
|
+
|
5
|
+
ENVIRONMENTS = DeployHooks::Config.environments
|
6
|
+
|
7
|
+
namespace :deploy do
|
8
|
+
ENVIRONMENTS.keys.each do |env|
|
9
|
+
desc "Deploy to #{env}"
|
10
|
+
task env do
|
11
|
+
current_branch = `git branch | grep ^* | awk '{ print $2 }'`.strip
|
12
|
+
|
13
|
+
Rake::Task['deploy:before_deploy'].invoke(env, current_branch)
|
14
|
+
Rake::Task['deploy:update_code'].invoke(env, current_branch)
|
15
|
+
Rake::Task['deploy:after_deploy'].invoke(env, current_branch)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
task :before_deploy, :env, :branch do |t, args|
|
20
|
+
|
21
|
+
DeployHooks::Config.before_deploy.each do |tool, tasks|
|
22
|
+
puts "### Running before_deploy #{tool} tasks ###"
|
23
|
+
tasks.each { |task| puts `heroku run #{tool} #{task} --app #{ENVIRONMENTS[args[:env]]}` }
|
24
|
+
end
|
25
|
+
|
26
|
+
puts "Deploying #{args[:branch]} to #{args[:env]}..."
|
27
|
+
end
|
28
|
+
|
29
|
+
task :after_deploy, :env, :branch do |t, args|
|
30
|
+
puts "Deployment Complete! Now I need time for some make up"
|
31
|
+
|
32
|
+
DeployHooks::Config.after_deploy.each do |tool, tasks|
|
33
|
+
puts "### Running after_deploy #{tool} tasks ###"
|
34
|
+
tasks.each { |task| puts `heroku run #{tool} #{task} --app #{ENVIRONMENTS[args[:env]]}` }
|
35
|
+
end
|
36
|
+
|
37
|
+
puts 'Restarting application...'
|
38
|
+
puts `heroku restart --app #{ENVIRONMENTS[args[:env]]}`
|
39
|
+
|
40
|
+
puts 'Done! Enjoy.'
|
41
|
+
end
|
42
|
+
|
43
|
+
task :update_code, :env, :branch do |t, args|
|
44
|
+
FileUtils.cd Rails.root do
|
45
|
+
puts "Updating #{ENVIRONMENTS[args[:env]]} with branch #{args[:branch]}"
|
46
|
+
`git push` # if using "[push] default = tracking" in .git/config
|
47
|
+
#`git push #{ENVIRONMENTS[args[:env]]} +#{args[:branch]}:master`
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
metadata
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: deploy_hooks
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Alex Chernyshev
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-12-09 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: heroku
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: bundler
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '1.3'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '1.3'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rake
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
description: User can define tasks which will start before or after deployment
|
63
|
+
email:
|
64
|
+
- alex.kenjione@gmail.com
|
65
|
+
executables: []
|
66
|
+
extensions: []
|
67
|
+
extra_rdoc_files: []
|
68
|
+
files:
|
69
|
+
- .gitignore
|
70
|
+
- CHANGELOG.md
|
71
|
+
- Gemfile
|
72
|
+
- LICENSE.txt
|
73
|
+
- README.md
|
74
|
+
- Rakefile
|
75
|
+
- deploy_hooks.gemspec
|
76
|
+
- lib/deploy_hooks.rb
|
77
|
+
- lib/deploy_hooks/config.rb
|
78
|
+
- lib/deploy_hooks/railtie.rb
|
79
|
+
- lib/deploy_hooks/version.rb
|
80
|
+
- tasks/deploy.rake
|
81
|
+
homepage: ''
|
82
|
+
licenses:
|
83
|
+
- MIT
|
84
|
+
post_install_message:
|
85
|
+
rdoc_options: []
|
86
|
+
require_paths:
|
87
|
+
- lib
|
88
|
+
- tasks
|
89
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
90
|
+
none: false
|
91
|
+
requirements:
|
92
|
+
- - ! '>='
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
segments:
|
96
|
+
- 0
|
97
|
+
hash: 3348323427534766840
|
98
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
|
+
none: false
|
100
|
+
requirements:
|
101
|
+
- - ! '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
segments:
|
105
|
+
- 0
|
106
|
+
hash: 3348323427534766840
|
107
|
+
requirements: []
|
108
|
+
rubyforge_project:
|
109
|
+
rubygems_version: 1.8.25
|
110
|
+
signing_key:
|
111
|
+
specification_version: 3
|
112
|
+
summary: Heroku deployment hooks
|
113
|
+
test_files: []
|