heroku-helper 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.
data/History.txt ADDED
@@ -0,0 +1,4 @@
1
+ === 0.0.1 2010-03-05
2
+
3
+ * 1 major enhancement:
4
+ * Initial release
data/Manifest.txt ADDED
@@ -0,0 +1,8 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.rdoc
4
+ Rakefile
5
+ bin/heroku-helper
6
+ lib/heroku-helper.rb
7
+ lib/heroku-helper/cli.rb
8
+ lib/heroku-helper/heroku.rb
data/README.rdoc ADDED
@@ -0,0 +1,64 @@
1
+ = heroku-helper
2
+
3
+ * http://rubygems.org/gems/heroku-helper
4
+
5
+ == DESCRIPTION:
6
+
7
+ Heroku deployment helper
8
+
9
+ == SYNOPSIS:
10
+
11
+ $ heroku-deploy -c share -e staging
12
+ $ heroku-deploy -c deploy -e production
13
+
14
+ heroku_deploy.rb format:
15
+
16
+ environment :production do
17
+ set :app_name, 'heroku-application-name'
18
+ set :domain, 'example.com'
19
+ set :contributors, %w(dev1@example.com dev2@example.com)
20
+ set :environment_variables, {
21
+ 'REDIS_URL' => 'redis://localhost:6379/0'
22
+ }
23
+ set :addons, [
24
+ 'custom_domains',
25
+ 'gmail_smtp email=foo@bar.com password=sekret'
26
+ ]
27
+
28
+ hook :before, :share do
29
+ puts 'hello before share'
30
+ end
31
+
32
+ hook :after, :deploy do
33
+ puts 'hello after deploy'
34
+ end
35
+ end
36
+
37
+ == INSTALL:
38
+
39
+ * [sudo] gem install heroku-helper
40
+
41
+ == LICENSE:
42
+
43
+ (The MIT License)
44
+
45
+ Copyright (c) 2010 ELC Technologies
46
+
47
+ Permission is hereby granted, free of charge, to any person obtaining
48
+ a copy of this software and associated documentation files (the
49
+ 'Software'), to deal in the Software without restriction, including
50
+ without limitation the rights to use, copy, modify, merge, publish,
51
+ distribute, sublicense, and/or sell copies of the Software, and to
52
+ permit persons to whom the Software is furnished to do so, subject to
53
+ the following conditions:
54
+
55
+ The above copyright notice and this permission notice shall be
56
+ included in all copies or substantial portions of the Software.
57
+
58
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
59
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
60
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
61
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
62
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
63
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
64
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,21 @@
1
+ require 'rubygems'
2
+ gem 'hoe', '>= 2.1.0'
3
+ require 'hoe'
4
+ require 'fileutils'
5
+ require './lib/heroku-helper'
6
+
7
+ Hoe.plugin :newgem
8
+ # Hoe.plugin :website
9
+ # Hoe.plugin :cucumberfeatures
10
+
11
+ # Generate all the Rake tasks
12
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
13
+ $hoe = Hoe.spec 'heroku-helper' do
14
+ self.developer 'ELC Technologies', 'hchoroomi@elctech.com'
15
+ self.rubyforge_name = self.name
16
+ # self.extra_deps = [['activesupport','>= 2.0.2']]
17
+
18
+ end
19
+
20
+ #require 'newgem/tasks'
21
+ #Dir['tasks/**/*.rake'].each { |t| load t }
data/bin/heroku-helper ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Created on 2010-3-5.
4
+ # Copyright (c) ELC Technologies 2010. All rights reserved.
5
+
6
+ require 'rubygems'
7
+ require File.expand_path(File.dirname(__FILE__) + "/../lib/heroku-helper")
8
+ require "heroku-helper/cli"
9
+ require "heroku-helper/deployment_configuration"
10
+ require "heroku-helper/heroku"
11
+
12
+ HerokuHelper::CLI.execute(STDOUT, ARGV)
@@ -0,0 +1,43 @@
1
+ require 'optparse'
2
+
3
+ module HerokuHelper
4
+ class CLI
5
+ def self.execute(stdout, arguments=[])
6
+ options = {
7
+ :env => 'production',
8
+ :command => 'deploy'
9
+ }
10
+ available_commands = %w(deploy share restart set_vars add_addons)
11
+ mandatory_options = %w( )
12
+
13
+ parser = OptionParser.new do |opts|
14
+ opts.banner = <<-BANNER.gsub(/^ /,'')
15
+ Heroku deployment helper
16
+
17
+ Usage: #{File.basename($0)} [options]
18
+
19
+ Options are:
20
+ BANNER
21
+ opts.separator ""
22
+ opts.on("-e", "--env=ENV", String,
23
+ "Set environment. Default is production.") { |arg| options[:env] = arg }
24
+ opts.on("-c", "--command=COMMAND", String,
25
+ "Heroku command to run. Default is deploy.",
26
+ "Available commands: #{available_commands.join(', ')}") { |arg| options[:command] = arg }
27
+ opts.on("-f", "--format",
28
+ "Shows deploy.yml file format.") { stdout.puts DeploymentConfiguration.configuration_format; exit }
29
+ opts.on("-v", "--version",
30
+ "Show the #{File.basename($0)} version number and quit.") { stdout.puts "#{File.basename($0)} #{HerokuHelper::VERSION}"; exit }
31
+ opts.on("-h", "--help", "Show this help message.") { stdout.puts opts; exit }
32
+ opts.parse!(arguments)
33
+
34
+ if mandatory_options && mandatory_options.find { |option| options[option.to_sym].nil? }
35
+ stdout.puts opts; exit
36
+ end
37
+ end
38
+
39
+ raise "Command '#{options[:command]}' not found" unless available_commands.include?(options[:command])
40
+ Heroku.new(options[:env]).run(options[:command])
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,107 @@
1
+ module HerokuHelper
2
+ class Heroku
3
+
4
+ attr_accessor :environment
5
+
6
+ def initialize(env)
7
+ @environment = env.intern
8
+ load_configuration
9
+ puts "#{application_name} - #{environment}\n"
10
+ end
11
+
12
+ def deploy
13
+ remote = cmd("git remote add git-remote-for-#{application_name} git@heroku.com:#{application_name}.git 2>&1")
14
+ if remote !~ /remote git-remote-for-#{application_name} already exists/
15
+ cmd("git push git-remote-for-#{application_name} master")
16
+ else
17
+ cmd("git push -f git-remote-for-#{application_name}")
18
+ end
19
+ end
20
+
21
+ def share
22
+ contributors.each do |dev|
23
+ cmd 'heroku sharing:add', dev, '--app', application_name
24
+ end
25
+ end
26
+
27
+ def restart
28
+ cmd 'heroku restart', '--app', application_name
29
+ end
30
+
31
+ def set_vars
32
+ environment_variables.each do |key, value|
33
+ cmd 'heroku config:add', "#{key}=#{value}", '--app', application_name
34
+ end
35
+ end
36
+
37
+ def add_addons
38
+ addons.each do |addon|
39
+ cmd 'heroku addons:add', addon, '--app', application_name
40
+ end
41
+ end
42
+
43
+ def run(command)
44
+ command = command.intern
45
+ run_before_hook(command)
46
+ send(command)
47
+ run_after_hook(command)
48
+ end
49
+
50
+ private
51
+
52
+ def load_configuration
53
+ deployment_configuration = 'heroku_deploy.rb'
54
+ if File.exist?(deployment_configuration)
55
+ DeploymentConfiguration.configure(deployment_configuration)
56
+ @config = DeploymentConfiguration.configuration
57
+ else
58
+ puts "No deployment configuration found (looking for: #{deployment_configuration})"
59
+ puts "Run #{File.basename($0)} -f for more information."
60
+ exit(1)
61
+ end
62
+ end
63
+
64
+ def config(key)
65
+ key = key.intern
66
+ raise 'Cannot find specified key in the deployment file' unless @config[environment].has_key?(key)
67
+ @config[environment][key]
68
+ end
69
+
70
+ def application_name
71
+ config('app_name')
72
+ end
73
+
74
+ def contributors
75
+ config('contributors')
76
+ end
77
+
78
+ def environment_variables
79
+ config('environment_variables')
80
+ end
81
+
82
+ def addons
83
+ config('addons')
84
+ end
85
+
86
+ def cmd(*command)
87
+ command = command.join(' ')
88
+ puts "Executing: #{command}"
89
+ `#{command}`
90
+ end
91
+
92
+ def run_before_hook(command)
93
+ run_hook :before, command
94
+ end
95
+
96
+ def run_after_hook(command)
97
+ run_hook :after, command
98
+ end
99
+
100
+ def run_hook(stage, command)
101
+ if config('hooks') && config('hooks')[command] && config('hooks')[command][stage]
102
+ config('hooks')[command][stage].call
103
+ end
104
+ end
105
+
106
+ end
107
+ end
@@ -0,0 +1,6 @@
1
+ $:.unshift(File.dirname(__FILE__)) unless
2
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
+
4
+ module HerokuHelper
5
+ VERSION = '0.1.0'
6
+ end
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: heroku-helper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - ELC Technologies
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-03-08 00:00:00 +08:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rubyforge
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 2.0.3
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: gemcutter
27
+ type: :development
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.3.0
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: hoe
37
+ type: :development
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 2.5.0
44
+ version:
45
+ description: Heroku deployment helper
46
+ email:
47
+ - hchoroomi@elctech.com
48
+ executables:
49
+ - heroku-helper
50
+ extensions: []
51
+
52
+ extra_rdoc_files:
53
+ - History.txt
54
+ - Manifest.txt
55
+ files:
56
+ - History.txt
57
+ - Manifest.txt
58
+ - README.rdoc
59
+ - Rakefile
60
+ - bin/heroku-helper
61
+ - lib/heroku-helper.rb
62
+ - lib/heroku-helper/cli.rb
63
+ - lib/heroku-helper/heroku.rb
64
+ has_rdoc: true
65
+ homepage: http://rubygems.org/gems/heroku-helper
66
+ licenses: []
67
+
68
+ post_install_message:
69
+ rdoc_options:
70
+ - --main
71
+ - README.rdoc
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: "0"
79
+ version:
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: "0"
85
+ version:
86
+ requirements: []
87
+
88
+ rubyforge_project: heroku-helper
89
+ rubygems_version: 1.3.5
90
+ signing_key:
91
+ specification_version: 3
92
+ summary: Heroku deployment helper
93
+ test_files: []
94
+