heroku-deploy 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
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,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in heroku-deploy.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Rodrigo Pinto
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,34 @@
1
+ # heroku-deploy
2
+
3
+ A collection of rake tasks that help deploy, backup and restore database for your heroku applications.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'heroku-deploy'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install heroku-deploy
18
+
19
+ ## Usage
20
+
21
+ Set production and staging app name to to the env
22
+
23
+ $ export PRODUCTION_APP=myapp
24
+ $ export STAGING_APP=myapp-staging
25
+
26
+ Now it is ready to use
27
+
28
+ ## Contributing
29
+
30
+ 1. Fork it
31
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
32
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
33
+ 4. Push to the branch (`git push origin my-new-feature`)
34
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'heroku-deploy/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "heroku-deploy"
8
+ gem.version = Heroku::Deploy::VERSION
9
+ gem.authors = ["Rodrigo Pinto"]
10
+ gem.email = ["rodrigopqn@gmail.com"]
11
+ gem.description = %q{A collection of rake tasks that help to deploy an application following a common way to every app.}
12
+ gem.summary = %q{A collection of rake tasks to make easy maintain a heroku application}
13
+ gem.homepage = ""
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_runtime_dependency('colored', '~> 1.2')
21
+ gem.add_runtime_dependency('git', '1.2.5')
22
+ end
@@ -0,0 +1,5 @@
1
+ module Heroku
2
+ module Deploy
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,12 @@
1
+ require "heroku-deploy/version"
2
+
3
+ module Heroku
4
+ module Deploy
5
+ end
6
+ end
7
+
8
+ def gem_path
9
+ Gem::Specification.find_by_name('heroku-deploy').full_gem_path
10
+ end
11
+
12
+ Dir["#{gem_path}/lib/tasks/*.rake"].each { |ext| load ext } if defined?(Rake)
@@ -0,0 +1,53 @@
1
+ namespace :heroku do
2
+ def run(*cmd)
3
+ system(*cmd)
4
+ raise "Command #{cmd.inspect} failed!" unless $?.success?
5
+ end
6
+
7
+ namespace :db do
8
+ namespace :backup do
9
+ def backup(app)
10
+ puts "-----> Backing-up #{app}...".yellow
11
+ run("heroku pgbackups:capture --app #{app} --expire")
12
+
13
+ puts "-----> Downloading backup...".yellow
14
+ run("curl -o #{app}-db-bkup `heroku pgbackups:url --app #{app}`")
15
+ end
16
+
17
+ desc "Copy database from production"
18
+ task :production => :environment do
19
+ backup(ENV["PRODUCTION_APP"])
20
+ end
21
+
22
+ desc "Copy database from staging"
23
+ task :staging => :environment do
24
+ backup(ENV["STAGING_APP"])
25
+ end
26
+ end
27
+
28
+ namespace :restore do
29
+ def dbname
30
+ config = Rails.configuration.database_configuration
31
+ config[Rails.env]["database"]
32
+ end
33
+
34
+ def restore(app)
35
+ puts "-----> Backup restoring...".yellow
36
+
37
+ run("pg_restore --verbose --clean --no-acl --no-owner -h localhost -U postgres -d #{dbname} #{app}-db-bkup")
38
+
39
+ puts "-----> Backup already restored...".green
40
+ end
41
+
42
+ desc "Restore heroku production database locally"
43
+ task :production => 'backup:production' do
44
+ restore(ENV["PRODUCTION_APP"])
45
+ end
46
+
47
+ desc "Restore heroku staging database locally"
48
+ task :staging => 'backup:staging' do
49
+ restore(ENV["STAGING_APP"])
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,121 @@
1
+ # -*- encoding : utf-8 -*-
2
+ namespace :heroku do
3
+ def run(*cmd)
4
+ system(*cmd)
5
+ raise "Command #{cmd.inspect} failed!" unless $?.success?
6
+ end
7
+
8
+ def confirm(message)
9
+ print "\n#{message}\nAre you sure? [Yn] ".red
10
+ raise 'Aborted' unless STDIN.gets.chomp.downcase == 'y'
11
+ end
12
+
13
+ namespace :deploy do
14
+ desc "Deploy application to staging"
15
+ task :staging do
16
+ APP = ENV["STAGING_APP"]
17
+
18
+ puts "-----> Backing up database via Heroku...".yellow
19
+ run "heroku pgbackups:capture --expire --app #{APP}"
20
+
21
+ puts "-----> Pushing application to heroku...".yellow
22
+ run "git push git@heroku.com:#{APP}.git HEAD:master -f"
23
+
24
+ puts "-----> Excuting migraitons...".yellow
25
+ run "heroku run rake db:migrate --app #{APP}"
26
+
27
+ puts "-----> Restarting...".yellow
28
+ run "heroku restart --app #{APP}"
29
+
30
+ puts "-----> Done! :)...".green
31
+ end
32
+
33
+ desc "Deploy application to production"
34
+ task :production do
35
+ APP = ENV["PRODUCTION_APP"]
36
+
37
+ current_branch = Git.open(File.expand_path(Rails.root)).current_branch
38
+ if current_branch != "production"
39
+ puts "-----> You can't do a deploy from '#{current_branch}'. Please use 'production' branch.".red
40
+ exit
41
+ end
42
+
43
+ if ENV['SKIP_TESTS'] != "true"
44
+ puts "-----> Running all specs...".yellow
45
+ Rake::Task['spec'].invoke
46
+ end
47
+
48
+ print "\nPut in maintenance mode? [Yn] ".red
49
+ maintenance = (ENV['MAINTENANCE'] == "true" or (STDIN.gets.chomp.downcase == 'y'))
50
+
51
+ if maintenance
52
+ puts "-----> Setting Maintenance on...".yellow
53
+ run "heroku maintenance:on --app #{APP}"
54
+
55
+ puts "-----> Restarting...".yellow
56
+ run "heroku restart --app #{APP}"
57
+
58
+ puts "-----> Waiting 20 seconds to app come back (in maintenance mode)...".yellow
59
+ sleep(20)
60
+ end
61
+
62
+ puts "-----> Backing up database via Heroku...".yellow
63
+ run "heroku pgbackups:capture --expire --app #{APP}"
64
+
65
+ iso_date = Time.now.strftime('%Y-%m-%dT%H%M%S')
66
+ tag_name = "production-#{iso_date}"
67
+ puts "-----> Tagging as #{tag_name}...".yellow
68
+ run "git tag #{tag_name} production"
69
+
70
+ puts "-----> Pushing...".yellow
71
+ run "git push origin #{tag_name}"
72
+ run "git push git@heroku.com:#{APP}.git #{tag_name}:master"
73
+
74
+ puts "-----> Migrating...".yellow
75
+ run "heroku run rake db:migrate --app #{APP}"
76
+
77
+ if maintenance
78
+ puts "Setting Maintenance off...".yellow
79
+ run "heroku maintenance:off --app #{APP}"
80
+ end
81
+
82
+ puts "-----> Restarting...".yellow
83
+ run "heroku restart --app #{APP}"
84
+
85
+ puts "-----> Done! :)...".green
86
+ end
87
+ end
88
+
89
+ namespace :integration do
90
+ APP = ENV["STAGING_APP"]
91
+
92
+ desc "Add heroku remote fork to git"
93
+ task :add_remote do
94
+ remote = `git remote |grep heroku`
95
+ sh "git remote add heroku git@heroku.com:#{APP}.git" if remote.strip.blank?
96
+ end
97
+
98
+ desc "Check if someone is already integration"
99
+ task :check do
100
+ var = `heroku config -s --app #{APP}|grep INTEGRATING_BY`
101
+ integrating_by = var.split('=')[1]
102
+ user = `whoami`
103
+
104
+ if !integrating_by.blank? and integrating_by != user
105
+ puts "Project is already being integrated by #{integrating_by}".red
106
+ exit
107
+ end
108
+ end
109
+
110
+ desc "Lock integration to the current user"
111
+ task :lock do
112
+ user = `whoami`
113
+ sh "heroku config:add INTEGRATING_BY=#{user}"
114
+ end
115
+
116
+ desc "Unlock integration"
117
+ task :unlock do
118
+ `heroku config:remove INTEGRATING_BY`
119
+ end
120
+ end
121
+ end
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: heroku-deploy
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Rodrigo Pinto
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-11-29 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: colored
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.2'
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: '1.2'
30
+ - !ruby/object:Gem::Dependency
31
+ name: git
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - '='
36
+ - !ruby/object:Gem::Version
37
+ version: 1.2.5
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - '='
44
+ - !ruby/object:Gem::Version
45
+ version: 1.2.5
46
+ description: A collection of rake tasks that help to deploy an application following
47
+ a common way to every app.
48
+ email:
49
+ - rodrigopqn@gmail.com
50
+ executables: []
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - .gitignore
55
+ - Gemfile
56
+ - LICENSE.txt
57
+ - README.md
58
+ - Rakefile
59
+ - heroku-deploy.gemspec
60
+ - lib/heroku-deploy.rb
61
+ - lib/heroku-deploy/version.rb
62
+ - lib/tasks/backup.rake
63
+ - lib/tasks/deploy.rake
64
+ homepage: ''
65
+ licenses: []
66
+ post_install_message:
67
+ rdoc_options: []
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ none: false
78
+ requirements:
79
+ - - ! '>='
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ requirements: []
83
+ rubyforge_project:
84
+ rubygems_version: 1.8.24
85
+ signing_key:
86
+ specification_version: 3
87
+ summary: A collection of rake tasks to make easy maintain a heroku application
88
+ test_files: []