falcon-deploy 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c7fd9615428f431856772761ff23f41ab91e0a69
4
+ data.tar.gz: 579b582c62dbdb5d46b1e5aa0517a76f7d6b3d7e
5
+ SHA512:
6
+ metadata.gz: 31fb8b50d13fe8083cc60a19ba0f893ab8f8a74dae230b5bc53000fb211e9f53671b4b57172961589939af024466cb3a12aeb7caa25160b8a360b8323ed740ca
7
+ data.tar.gz: 570e348a90ae096f74d98d40e80217f1e01b78bc5b8cb7963a46ec368f500c40f525375f3600169d7a5faf19f8cfb0a7dbfdbfeadf8c5d54d909681707c9f5b2
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in falcon.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Sasha Klein
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,68 @@
1
+ # Falcon Deploy
2
+
3
+ A simple wrapper to make it easier and less nerve-wracking to deploy to Heroku and roll code back when you mess things up.
4
+
5
+ ![falcon](http://static3.businessinsider.com/image/547378e869bedd312b36685a/landing.gif)
6
+
7
+ Inspired by Space X's awesome Falcon rocket, which is working towards the first combined take-off and safe landing, and drawn from [this gist](https://gist.github.com/guapolo/28729b95a7ef6b1aacf5).
8
+
9
+ Falcon aims to be a simple, pared-down, easy-to-use (and easy-to-maintain) solution to a very specific problem.
10
+
11
+ ## Installation
12
+
13
+ > Note: This gem is built to use Heroku Toolbelt. It won't do anything if you don't have the Toolbelt installed.
14
+
15
+ Add to your Gemfile (`:development` group is fine):
16
+
17
+ ```ruby
18
+ gem 'falcon-deploy'
19
+ ```
20
+
21
+ And then execute:
22
+
23
+ $ bundle
24
+
25
+ ## Usage
26
+
27
+ Falcon is run from the command line. It takes two arguments, `appname` and `command`, and an optional `--force` (or `-f`) flag.
28
+
29
+ The commands are:
30
+
31
+ - `deploy` - Deploy code to your app.
32
+ - `migrations` - Deploy code to your app, turn on maintenance mode, run accompanying migrations, and turn maintenance off.
33
+ - `rollback` - Roll back the most recent deploy. This will *not* reverse migrations, so as the instructions stipulate, run `rake db:rollback` before this command as necessary.
34
+
35
+ The optional `-f` flag disables the above rollback warning.
36
+
37
+ Some examples:
38
+
39
+ ```bash
40
+ falcon staging-appname deploy
41
+ # => Deploy code to your staging app
42
+
43
+ falcon my-prod-app migrations
44
+ # => Deploy code to production app, turn on maintenance mode, run accompanying migrations, and turn maintenance off
45
+
46
+
47
+ falcon app-name rollback -f
48
+ # => You will not be warned about migrations; falcon will go ahead and reverse the previous deploy
49
+
50
+ falcon help
51
+ # => ?
52
+ ```
53
+
54
+ ## Development
55
+
56
+ The usual:
57
+
58
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
59
+
60
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
61
+
62
+ ## Contributing
63
+
64
+ 1. Fork it ( https://github.com/sashafklein/falcon/fork )
65
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
66
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
67
+ 4. Push to the branch (`git push origin my-new-feature`)
68
+ 5. Create a new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+
5
+ # You can add fixtures and/or initialization code here to make experimenting
6
+ # with your gem easier. You can also use a different console, if you like.
7
+
8
+ # (If you use this, don't forget to add pry to your Gemfile!)
9
+ # require "pry"
10
+ # Pry.start
11
+
12
+ require "irb"
13
+ IRB.start
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "falcon"
4
+ require 'trollop'
5
+
6
+ input = ARGV
7
+
8
+ opts = Trollop::options do
9
+ opt :force, "Ignore warnings", short: :f
10
+ end
11
+
12
+ appname, command = input[0], input[1]
13
+
14
+ if input.length != 2 || !%w( deploy migrations rollback).include?( command )
15
+ puts Falcon::Deploy.help
16
+ else
17
+ Falcon::Deploy.new( appname, opts[:force] ).run( command )
18
+ end
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'falcon/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "falcon-deploy"
8
+ spec.version = Falcon::VERSION
9
+ spec.authors = ["Sasha Klein"]
10
+ spec.email = ["sashafklein@gmail.com"]
11
+
12
+ spec.summary = %q{A Heroku wrapper to simplify and de-risk app deployment, migrations, and rollbacks.}
13
+ spec.homepage = "http://www.sashafklein.com/portfolio#falcon"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.executables = ['falcon']
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.test_files = spec.files.grep(%r{^(spec)/})
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.9"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "binding_of_caller"
25
+ spec.add_runtime_dependency "trollop", '2.1.2'
26
+ end
@@ -0,0 +1,72 @@
1
+ require "falcon/version"
2
+ require 'heroku_deployer'
3
+
4
+ module Falcon
5
+
6
+ class Deploy
7
+
8
+ attr_reader :env, :appname, :force
9
+ def initialize(appname, force=false)
10
+ @appname = appname
11
+ @force = force
12
+ end
13
+
14
+ def self.help
15
+ %Q{
16
+ USAGE: `falcon [appname] [command] [flags]`
17
+ APPNAME: Your Heroku app name
18
+ COMMANDS:
19
+ - `deploy` - deploy the code
20
+ - `migrations` - deploy and run migrations
21
+ - `rollback` - reverse the latest code deploy (does NOT reverse migrations)
22
+ FLAGS
23
+ - `-f`, `--force` - force rollback etc
24
+ }
25
+ end
26
+
27
+ def run(command)
28
+ if respond_to? command
29
+ send command
30
+ else
31
+ puts "The command '#{command}' is not valid.\n"
32
+ puts self.class.help
33
+ end
34
+ end
35
+
36
+ def deploy
37
+ deployer.deploy
38
+ end
39
+
40
+ def migrations
41
+ deployer.migrations
42
+ end
43
+
44
+ def rollback
45
+ unless force
46
+ puts rollback_warning
47
+
48
+ answer = STDIN.gets.strip
49
+
50
+ return (puts "Rollback cancelled.") unless %w( y yes ).include?( answer.downcase )
51
+ end
52
+
53
+ deployer.rollback
54
+ end
55
+
56
+ def deployer
57
+ @deployer ||= HerokuDeployer.new( appname )
58
+ end
59
+
60
+ def rollback_warning
61
+ %Q{
62
+ This command does NOT reverse migrations.
63
+ If you want to reverse a migration, please do so manually:
64
+ `heroku run rake db:rollback`
65
+ Then run this command again.
66
+
67
+ Continue (without DB rollback)? Y/N
68
+ }
69
+ end
70
+ end
71
+
72
+ end
@@ -0,0 +1,3 @@
1
+ module Falcon
2
+ VERSION = "0.1.1"
3
+ end
@@ -0,0 +1,108 @@
1
+ class HerokuDeployer
2
+
3
+ attr_reader :app
4
+ def initialize(app)
5
+ @app = app
6
+ raise "No app flag configured!" unless @app
7
+ end
8
+
9
+ def migrations
10
+ push; turn_app_off; migrate; restart; turn_app_on; tag;
11
+ end
12
+
13
+ def deploy
14
+ push; restart; tag;
15
+ end
16
+
17
+ def rollback
18
+ turn_app_off; push_previous; restart; turn_app_on;
19
+ end
20
+
21
+ private
22
+
23
+ def push
24
+ current_branch = `git rev-parse --abbrev-ref HEAD`.chomp
25
+ branch_to_branch = (current_branch.length > 0) ? "#{current_branch}:master" : ""
26
+ puts "Deploying site to Heroku (#{@app}) ..."
27
+ puts "git push -f git@heroku.com:#{@app}.git #{branch_to_branch}"
28
+ puts `git push -f git@heroku.com:#{@app}.git #{branch_to_branch}`
29
+ end
30
+
31
+ def restart
32
+ puts 'Restarting app servers ...'
33
+ Bundler.with_clean_env { run_and_log(`heroku restart --app #{@app}`) }
34
+ end
35
+
36
+ def tag
37
+ release_name = "#{@app}_release-#{Time.now.utc.strftime("%Y%m%d%H%M%S")}"
38
+ puts "Tagging release as '#{release_name}'"
39
+ puts `git tag -a #{release_name} -m 'Tagged release'`
40
+ puts `git push --tags git@heroku.com:#{@app}.git`
41
+ end
42
+
43
+ def migrate
44
+ puts 'Running database migrations ...'
45
+ Bundler.with_clean_env { run_and_log(`heroku run 'bundle exec rake db:migrate' --app #{@app}`) }
46
+ end
47
+
48
+ def turn_app_off
49
+ puts 'Putting the app into maintenance mode ...'
50
+ Bundler.with_clean_env { run_and_log(`heroku maintenance:on --app #{@app}`) }
51
+ end
52
+
53
+ def turn_app_on
54
+ puts 'Taking the app out of maintenance mode ...'
55
+ Bundler.with_clean_env { puts `heroku maintenance:off --app #{@app}` }
56
+ end
57
+
58
+ def push_previous
59
+ prefix = "#{@app}_release-"
60
+ releases = `git tag`.split("\n").select { |t| t[0..prefix.length-1] == prefix }.sort
61
+ current_release = releases.last
62
+ previous_release = releases[-2] if releases.length >= 2
63
+ if previous_release
64
+ puts "Rolling back to '#{previous_release}' ..."
65
+
66
+ puts "Checking out '#{previous_release}' in a new branch on local git repo ..."
67
+ puts `git checkout #{previous_release}`
68
+ puts `git checkout -b #{previous_release}`
69
+
70
+ puts "Removing tagged version '#{previous_release}' (now transformed in branch) ..."
71
+ puts `git tag -d #{previous_release}`
72
+ puts `git push git@heroku.com:#{@app}.git :refs/tags/#{previous_release}`
73
+
74
+ puts "Pushing '#{previous_release}' to Heroku master ..."
75
+ puts `git push git@heroku.com:#{@app}.git +#{previous_release}:master --force`
76
+
77
+ puts "Deleting rollbacked release '#{current_release}' ..."
78
+ puts `git tag -d #{current_release}`
79
+ puts `git push git@heroku.com:#{@app}.git :refs/tags/#{current_release}`
80
+
81
+ puts "Retagging release '#{previous_release}' in case to repeat this process (other rollbacks)..."
82
+ puts `git tag -a #{previous_release} -m 'Tagged release'`
83
+ puts `git push --tags git@heroku.com:#{@app}.git`
84
+
85
+ puts "Turning local repo checked out on master ..."
86
+ puts `git checkout master`
87
+ puts 'All done!'
88
+ else
89
+ puts "No release tags found - can't roll back!"
90
+ puts releases
91
+ end
92
+ end
93
+
94
+ private
95
+
96
+ def run_and_log(command, instance = 1, cap=20)
97
+ response = command
98
+ return (puts "Gave up after #{cap} seconds.") if instance >= cap
99
+
100
+ if response.include?("Heroku Toolbelt is currently updating")
101
+ puts "Stalling to allow for Heroku Toolbelt update. Attempt \##{instance}..."
102
+ sleep 1
103
+ run_and_log(command, instance + 1)
104
+ else
105
+ puts response
106
+ end
107
+ end
108
+ end
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: falcon-deploy
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Sasha Klein
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-11-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.9'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.9'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: binding_of_caller
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
+ - !ruby/object:Gem::Dependency
56
+ name: trollop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '='
60
+ - !ruby/object:Gem::Version
61
+ version: 2.1.2
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '='
67
+ - !ruby/object:Gem::Version
68
+ version: 2.1.2
69
+ description:
70
+ email:
71
+ - sashafklein@gmail.com
72
+ executables:
73
+ - falcon
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - ".rspec"
79
+ - ".travis.yml"
80
+ - CODE_OF_CONDUCT.md
81
+ - Gemfile
82
+ - LICENSE.txt
83
+ - README.md
84
+ - Rakefile
85
+ - bin/console
86
+ - bin/falcon
87
+ - bin/setup
88
+ - falcon.gemspec
89
+ - lib/falcon.rb
90
+ - lib/falcon/version.rb
91
+ - lib/heroku_deployer.rb
92
+ homepage: http://www.sashafklein.com/portfolio#falcon
93
+ licenses:
94
+ - MIT
95
+ metadata: {}
96
+ post_install_message:
97
+ rdoc_options: []
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ requirements: []
111
+ rubyforge_project:
112
+ rubygems_version: 2.4.6
113
+ signing_key:
114
+ specification_version: 4
115
+ summary: A Heroku wrapper to simplify and de-risk app deployment, migrations, and
116
+ rollbacks.
117
+ test_files: []