hanzo 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 64381bee684fd114a882b859e6644acd287fac50
4
- data.tar.gz: c77a084d6964695cd883debc99d151b28d99f4f1
3
+ metadata.gz: d4dd9200a8d88659c8accc46e154849db3ac8a12
4
+ data.tar.gz: 62bf3a0b5730c9082addf3bcfc7f2230562758e8
5
5
  SHA512:
6
- metadata.gz: ed85ac64caafb368bae582e79b0c1386efb2b92451f4d72cdceb9de4728b9ffaae6d2cbe569d770ad700aa75d8b62e80c840ccfd9cf7c8030481633d2c1e1aeb
7
- data.tar.gz: 79deca5c298c4065f8f32bdfaf89eca3ea5db9cf129a79fdfd02351dac3bd33a1b23a15c80fb5aa67d1b6ebc7f16caa9b2fdbb51b53234044eea67f7f5caafc5
6
+ metadata.gz: ce471c50737fad8ca3e6d21ef63fc8b8264d68bd9fc595ba4031501ae2781e737389cf75e772620448d1bb48fb755e8e47c2471b11285a9ec23a15f4fd341f56
7
+ data.tar.gz: 6b5b063877217dac5bf84e59076042debe6462237166adebaddfc599bc84657d63d40c9b9d725c810cb377c82e60b3f688df40d045208de234723de73de71e7a
data/LICENSE.md ADDED
@@ -0,0 +1,26 @@
1
+ Copyright (c) 2013, Mirego
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions are met:
6
+
7
+ - Redistributions of source code must retain the above copyright notice,
8
+ this list of conditions and the following disclaimer.
9
+ - Redistributions in binary form must reproduce the above copyright notice,
10
+ this list of conditions and the following disclaimer in the documentation
11
+ and/or other materials provided with the distribution.
12
+ - Neither the name of the Mirego nor the names of its contributors may
13
+ be used to endorse or promote products derived from this software without
14
+ specific prior written permission.
15
+
16
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26
+ POSSIBILITY OF SUCH DAMAGE.
data/README.md CHANGED
@@ -1,29 +1,69 @@
1
1
  # Hanzo
2
2
 
3
- TODO: Write a gem description
3
+ Hanzo is a Ruby library that allows a team to easily share environment endpoints for Heroku apps.
4
4
 
5
5
  ## Installation
6
6
 
7
- Add this line to your application's Gemfile:
7
+ Add this line to your applications Gemfile:
8
8
 
9
- gem 'hanzo'
9
+ ```ruby
10
+ gem 'hanzo'
11
+ ```
10
12
 
11
- And then execute:
13
+ ## Usage
12
14
 
13
- $ bundle
15
+ Create an `.heroku-remotes` file at the root of your app.
14
16
 
15
- Or install it yourself as:
17
+ ```yaml
18
+ qa: heroku-app-name-qa
19
+ staging: heroku-app-name-staging
20
+ production: heroku-app-name-production
21
+ ```
16
22
 
17
- $ gem install hanzo
23
+ ### Install remotes
18
24
 
19
- ## Usage
25
+ ```bash
26
+ > bundle exec hanzo install
27
+
28
+ -----> Creating git remotes
29
+ Adding qa
30
+ Adding staging
31
+ Adding production
32
+ ```
33
+
34
+ ### Install labs
35
+
36
+ Once all your environments are activated, you might want to enable some
37
+ Heroku labs feature for all your environments.
38
+
39
+ ```bash
40
+ > be hanzo install labs
41
+
42
+ -----> Activating Heroku Labs
43
+ Add preboot? yes
44
+ - Enabled for qa
45
+ - Enabled for staging
46
+ - Enabled for production
47
+ Add user-env-compile? yes
48
+ - Enabled for qa
49
+ - Enabled for staging
50
+ - Enabled for production
51
+ ```
52
+
53
+ ### Deploy a branch or a tag
54
+
55
+ ```bash
56
+ > bundle exec hanzo deploy qa
57
+
58
+ -----> Branch to deploy: |HEAD|
59
+ ```
60
+
61
+ ## License
62
+
63
+ `Hanzo` is © 2013 [Mirego](http://www.mirego.com) and may be freely distributed under the [New BSD license](http://opensource.org/licenses/BSD-3-Clause). See the [`LICENSE.md`](https://github.com/mirego/hanzo/blob/master/LICENSE.md) file.
20
64
 
21
- TODO: Write usage instructions here
65
+ ## About Mirego
22
66
 
23
- ## Contributing
67
+ Mirego is a team of passionate people who believe that work is a place where you can innovate and have fun. We proudly build mobile applications for [iPhone](http://mirego.com/en/iphone-app-development/ "iPhone application development"), [iPad](http://mirego.com/en/ipad-app-development/ "iPad application development"), [Android](http://mirego.com/en/android-app-development/ "Android application development"), [Blackberry](http://mirego.com/en/blackberry-app-development/ "Blackberry application development"), [Windows Phone](http://mirego.com/en/windows-phone-app-development/ "Windows Phone application development") and [Windows 8](http://mirego.com/en/windows-8-app-development/ "Windows 8 application development") in beautiful Quebec City.
24
68
 
25
- 1. Fork it
26
- 2. Create your feature branch (`git checkout -b my-new-feature`)
27
- 3. Commit your changes (`git commit -am 'Add some feature'`)
28
- 4. Push to the branch (`git push origin my-new-feature`)
29
- 5. Create new Pull Request
69
+ We also love [open-source software](http://open.mirego.com/) and we try to extract as much code as possible from our projects to give back to the community.
data/Rakefile CHANGED
@@ -1 +1,3 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler'
2
+ require 'rake'
3
+ require 'bundler/gem_tasks'
data/bin/hanzo ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
4
+
5
+ require 'hanzo'
6
+
7
+ Hanzo::CLI.new(ARGV).run
data/hanzo.gemspec CHANGED
@@ -1,23 +1,28 @@
1
1
  # coding: utf-8
2
+
2
3
  lib = File.expand_path('../lib', __FILE__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
5
  require 'hanzo/version'
5
6
 
6
7
  Gem::Specification.new do |spec|
7
- spec.name = "hanzo"
8
+ spec.name = 'hanzo'
8
9
  spec.version = Hanzo::VERSION
9
- spec.authors = ["Samuel Garneau"]
10
- spec.email = ["sgarneau@mirego.com"]
11
- spec.description = %q{Write a gem description}
12
- spec.summary = %q{Write a gem summary}
13
- spec.homepage = ""
14
- spec.license = "MIT"
10
+ spec.authors = ['Samuel Garneau']
11
+ spec.email = ['sgarneau@mirego.com']
12
+ spec.description = 'Hanzo is a tool to handle deployments in multiple environments on Heroku.'
13
+ spec.summary = 'Hanzo is a tool to handle deployments in multiple environments on Heroku.'
14
+ spec.homepage = 'https://github.com/mirego/hanzo'
15
+ spec.license = 'BSD 3-Clause'
15
16
 
16
17
  spec.files = `git ls-files`.split($/)
17
18
  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"]
19
+ spec.test_files = spec.files.grep(%r{^(spec)/})
20
+ spec.require_paths = ['lib']
21
+
22
+ spec.add_development_dependency 'bundler', '~> 1.3'
23
+ spec.add_development_dependency 'rake'
24
+ spec.add_development_dependency 'rspec'
20
25
 
21
- spec.add_development_dependency "bundler", "~> 1.3"
22
- spec.add_development_dependency "rake"
26
+ spec.add_dependency 'highline'
27
+ spec.add_dependency 'heroku'
23
28
  end
data/lib/hanzo/base.rb ADDED
@@ -0,0 +1,17 @@
1
+ module Hanzo
2
+ class Base
3
+ attr_accessor :options
4
+
5
+ def initialize(args)
6
+ @args = args
7
+ @options = OptionParser.new
8
+
9
+ initialize_variables
10
+ initialize_cli
11
+ end
12
+
13
+ def extract_argument(index)
14
+ (@args[index] =~ /-/) ? nil : @args[index]
15
+ end
16
+ end
17
+ end
data/lib/hanzo/cli.rb ADDED
@@ -0,0 +1,37 @@
1
+ require 'hanzo/modules/deploy'
2
+ require 'hanzo/modules/install'
3
+
4
+ module Hanzo
5
+ class CLI < Base
6
+ def run
7
+ @options.parse!(@args) if @opts.respond_to? :parse!
8
+ puts @options unless @options.to_s == "Usage: hanzo [options]\n"
9
+ end
10
+
11
+ protected
12
+
13
+ def initialize_variables
14
+ @app = extract_argument(0)
15
+ end
16
+
17
+ def initialize_cli
18
+ initialize_help and return if @app.nil?
19
+
20
+ @options = Hanzo.const_get(@app.capitalize).new(@args).options
21
+ end
22
+
23
+ def initialize_help
24
+ @options.banner = <<-BANNER
25
+ Usage: hanzo action [options]
26
+
27
+ Available actions:
28
+ deploy — Deploy a branch or a tag
29
+ install — Install Hanzo configuration
30
+
31
+ Options:
32
+ BANNER
33
+ @options.on('-h', '--help', 'You\'re looking at it.') { puts @options }
34
+ @options.on('-v', '--version', 'Print version') { puts "Hanzo #{Hanzo::VERSION}" }
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,17 @@
1
+ module Hanzo
2
+ module Heroku
3
+ class << self
4
+
5
+ def available_labs
6
+ `bundle exec heroku labs`.each_line.to_a.inject([]) do |memo, line|
7
+ if line = /^\[\s\]\s+(?<name>\w+)\s+(?<description>.+)$/.match(line)
8
+ memo << [line[:name], line[:description]]
9
+ else
10
+ memo
11
+ end
12
+ end
13
+ end
14
+
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,34 @@
1
+ module Hanzo
2
+ class Deploy < Base
3
+
4
+ protected
5
+
6
+ def initialize_variables
7
+ @env = extract_argument(1)
8
+ end
9
+
10
+ def initialize_cli
11
+ initialize_help and return if @env.nil?
12
+
13
+ deploy
14
+ run_migrations
15
+ end
16
+
17
+ def initialize_help
18
+ @options.banner = "Usage: hanzo deploy ENVIRONMENT"
19
+ end
20
+
21
+ def deploy
22
+ branch = ask("-----> Branch to deploy in #{@env}: ") { |q| q.default = "HEAD" }
23
+
24
+ `git push -f #{@env} #{branch}:master`
25
+ end
26
+
27
+ def run_migrations
28
+ if Dir.exists?('db/migrate')
29
+ migration = agree("-----> Run migrations? ")
30
+ `bundle exec heroku run rake db:migrate --remote #{@env}` if migration
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,30 @@
1
+ require 'hanzo/modules/installers/remotes'
2
+ require 'hanzo/modules/installers/labs'
3
+
4
+ module Hanzo
5
+ class Install < Base
6
+ include Hanzo::Installers::Remotes
7
+ include Hanzo::Installers::Labs
8
+
9
+ protected
10
+
11
+ def initialize_variables
12
+ @type = extract_argument(1)
13
+ end
14
+
15
+ def initialize_cli
16
+ initialize_help and return if @type.nil?
17
+
18
+ send "install_#{@type}"
19
+ end
20
+
21
+ def initialize_help
22
+ @options.banner = <<-BANNER
23
+ Usage: hanzo install TYPE
24
+
25
+ Available install type:
26
+ remotes — Add git remotes to current repository
27
+ BANNER
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,22 @@
1
+ module Hanzo
2
+ module Installers
3
+ module Labs
4
+ def install_labs
5
+ puts '-----> Activating Heroku Labs'
6
+
7
+ Hanzo::Heroku.available_labs.each do |name, description|
8
+ if agree(" Add #{name}? ")
9
+ Hanzo::Installers::Remotes.environments.each_pair do |env, app|
10
+ Hanzo::Installers::Labs.enable(env, lab)
11
+ end
12
+ end
13
+ end
14
+ end
15
+
16
+ def self.enable(env, lab)
17
+ `bundle exec heroku labs:enable #{lab} --remote #{env}`
18
+ puts " - Enabled for #{env}"
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,27 @@
1
+ module Hanzo
2
+ module Installers
3
+ module Remotes
4
+ def install_remotes
5
+ puts '-----> Creating git remotes'
6
+
7
+ Hanzo::Installers::Remotes.environments.each_pair do |env, app|
8
+ Hanzo::Installers::Remotes.add_remote(app, env)
9
+ end
10
+ end
11
+
12
+ def self.add_remote(app, env)
13
+ puts " Adding #{env}"
14
+ `git remote rm #{env} 2>&1 > /dev/null`
15
+ `git remote add #{env} git@heroku.com:#{app}.git`
16
+ end
17
+
18
+ def self.environments
19
+ return YAML.load_file('.heroku-remotes') if File.exists?('.heroku-remotes')
20
+
21
+ puts ' Can\'t locate .heroku-remotes'
22
+ puts ' For more information, please read https://github.com/mirego/hanzo'
23
+ exit
24
+ end
25
+ end
26
+ end
27
+ end
data/lib/hanzo/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Hanzo
2
- VERSION = "0.0.1"
2
+ VERSION = '0.1.0'
3
3
  end
data/lib/hanzo.rb CHANGED
@@ -1,5 +1,8 @@
1
- require "hanzo/version"
1
+ require 'optparse'
2
+ require 'yaml'
3
+ require 'highline/import'
2
4
 
3
- module Hanzo
4
- # Your code goes here...
5
- end
5
+ require 'hanzo/base'
6
+ require 'hanzo/cli'
7
+ require 'hanzo/heroku'
8
+ require 'hanzo/version'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hanzo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Garneau
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-18 00:00:00.000000000 Z
11
+ date: 2013-07-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -38,24 +38,74 @@ dependencies:
38
38
  - - '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
- description: Write a gem description
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
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: highline
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: heroku
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Hanzo is a tool to handle deployments in multiple environments on Heroku.
42
84
  email:
43
85
  - sgarneau@mirego.com
44
- executables: []
86
+ executables:
87
+ - hanzo
45
88
  extensions: []
46
89
  extra_rdoc_files: []
47
90
  files:
48
91
  - .gitignore
49
- - Gemfile
50
- - LICENSE.txt
92
+ - LICENSE.md
51
93
  - README.md
52
94
  - Rakefile
95
+ - bin/hanzo
53
96
  - hanzo.gemspec
54
97
  - lib/hanzo.rb
98
+ - lib/hanzo/base.rb
99
+ - lib/hanzo/cli.rb
100
+ - lib/hanzo/heroku.rb
101
+ - lib/hanzo/modules/deploy.rb
102
+ - lib/hanzo/modules/install.rb
103
+ - lib/hanzo/modules/installers/labs.rb
104
+ - lib/hanzo/modules/installers/remotes.rb
55
105
  - lib/hanzo/version.rb
56
- homepage: ''
106
+ homepage: https://github.com/mirego/hanzo
57
107
  licenses:
58
- - MIT
108
+ - BSD 3-Clause
59
109
  metadata: {}
60
110
  post_install_message:
61
111
  rdoc_options: []
@@ -76,6 +126,5 @@ rubyforge_project:
76
126
  rubygems_version: 2.0.0
77
127
  signing_key:
78
128
  specification_version: 4
79
- summary: Write a gem summary
129
+ summary: Hanzo is a tool to handle deployments in multiple environments on Heroku.
80
130
  test_files: []
81
- has_rdoc:
data/Gemfile DELETED
@@ -1,4 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in hanzo.gemspec
4
- gemspec
data/LICENSE.txt DELETED
@@ -1,22 +0,0 @@
1
- Copyright (c) 2013 Samuel Garneau
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.