heroku_buddy 0.0.5

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 23f823e5b0df2adb859e6e73ebdff7c69cd967d5
4
+ data.tar.gz: 5e6225f140cf8ef5ee27b7154f7052c6e2fb3db2
5
+ SHA512:
6
+ metadata.gz: 21cebf7f3567f9cc2becc5c8daf69f4305acc43f7df5b800f9e91615ca1cdb50ab053cabfb6baee82446f32f3cba355319c501069bb254c8316dee949158a1b6
7
+ data.tar.gz: 4a2ee32bf7b502b9eb54d4e6948a7652d3b646653df6cfab48ea38975830ef9d1026429a18c865aa15189cbed898cea29f6e6021f9e9ed301db1a79d7ee07fca
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_buddy.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 David Furber
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,74 @@
1
+ # HerokuBuddy
2
+
3
+ This is the easy access script, named "h", for common Heroku interactions such as deploying, migration, opening a console, tailing logs, and sharing your application secrets.
4
+
5
+ The "secrets" feature depends on the "secretive" gem, which you can find at http://github.com/singlebrook/secretive.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'heroku_buddy', group: :development
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install heroku_buddy
20
+
21
+ ## Usage
22
+
23
+ The basic workflow is that you set your heroku application name like so:
24
+
25
+ $ h app app_name
26
+
27
+ And then you can run the other commands without having to specify your app name
28
+
29
+ Commit your current code and deploy to Heroku with a commit message:
30
+
31
+ $ h deploy MESSAGE
32
+
33
+ The deploy runs git add, commit, push to origin, and push to Heroku.
34
+
35
+ Share your applications secrets using the 'secretive' gem:
36
+
37
+ $ h secrets
38
+
39
+ Tail the Heroku log file plus the last 200 lines:
40
+
41
+ $ h log
42
+
43
+ Bring up the Rails console for your Heroku app:
44
+
45
+ $ h console
46
+
47
+ Run rake db:migrate in maintenance mode:
48
+
49
+ $ h migrate
50
+
51
+ Commit, push, deploy, and migrate in maintenance mode with a commit message:
52
+
53
+ $ h dm MESSAGE
54
+
55
+ Run a rake task:
56
+
57
+ $ h rake namespace:task
58
+
59
+ Sync your local database to your Heroku app's database:
60
+
61
+ $ h sync
62
+
63
+
64
+ ## TODO items:
65
+ 1. Run multiple rake tasks.
66
+ 2. Use dot env files for configuration.
67
+
68
+ ## Contributing
69
+
70
+ 1. Fork it
71
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
72
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
73
+ 4. Push to the branch (`git push origin my-new-feature`)
74
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/h ADDED
@@ -0,0 +1,168 @@
1
+ #!/usr/bin/env ruby_noexec_wrapper
2
+
3
+ require 'json'
4
+
5
+ command = ARGV.shift
6
+
7
+ config = { 'app_name' => nil }
8
+ dot_file_name = '.h_file'
9
+ if File.exists?(dot_file_name)
10
+ contents = File.open(dot_file_name).read
11
+ if contents.size > 0
12
+ config = JSON.parse contents
13
+ end
14
+ else
15
+ end
16
+
17
+ app_name = config['app_name']
18
+ git_branch = `git branch | sed -n '/\* /s///p'` || 'master'
19
+
20
+ def exec_command_with_app_name(cmd, app_name)
21
+ cmd << " --app #{app_name}" if app_name
22
+ system cmd
23
+ end
24
+
25
+ def set_app
26
+ app_name = ARGV.shift
27
+ if app_name
28
+ config['app_name'] = app_name
29
+ puts "Set heroku app name to #{app_name}.\n"
30
+ else
31
+ config['app_name'] = nil
32
+ puts "Unset heroku app.\n"
33
+ end
34
+ File.open(dot_file_name, File::WRONLY|File::CREAT) { |file| file.write config.to_json }
35
+ end
36
+
37
+ def deploy
38
+ message = ARGV.shift || 'deploy to Heroku'
39
+ puts "Using branch #{git_branch}.\n"
40
+ puts "Adding new files to git...\n"
41
+ `git add .`
42
+ puts "Committing changes to git...\n"
43
+ `git commit -a -m '#{message}'`
44
+ puts "Pushing to source control...\n"
45
+ `git push origin #{git_branch}`
46
+ puts "Pushing to Heroku...\n"
47
+ `git push heroku #{git_branch}`
48
+ end
49
+
50
+ def migrate
51
+ puts "Migrating the database on Heroku...\n"
52
+ exec_command_with_app_name 'heroku maintenance:start', app_name
53
+ exec_command_with_app_name 'heroku run rake db:migrate', app_name
54
+ exec_command_with_app_name 'heroku maintenance:end', app_name
55
+ end
56
+
57
+ def seed
58
+ puts "Seeding the database on Heroku...\n"
59
+ exec_command_with_app_name 'heroku run rake db:seed', app_name
60
+ end
61
+
62
+ def share_secrets
63
+ puts "Sharing your app secrets with Heroku...\n"
64
+ require 'rubygems'
65
+ gem 'secretive'
66
+ require 'secretive'
67
+
68
+ if app_name.blank?
69
+ msg = "You must specify an app name either with --app APP or by running "
70
+ msg += "'h app APP' before running this command."
71
+ puts msg
72
+ exit
73
+ end
74
+
75
+ msg = "This task will sync ALL ENVIRONMENT VARIABLES in the `#{app_name}` app "
76
+ msg += "with the values defined in the `production` group of config/secrets.yml. "
77
+ msg += "Are you sure you want to proceed? (y/n)"
78
+ puts msg
79
+
80
+ confirmation = $stdin.gets.chomp
81
+ raise unless confirmation == "y"
82
+
83
+ exec "heroku config:add #{Secretive.for_heroku('production')} --app #{app_name}"
84
+ end
85
+
86
+ case command
87
+ when 'app'
88
+ set_app
89
+
90
+ when 'deploy'
91
+ deploy
92
+
93
+ when 'migrate'
94
+ migrate
95
+
96
+ when 'seed'
97
+ seed
98
+
99
+ when 'console'
100
+ puts "Running the console on Heroku...\n"
101
+ exec_command_with_app_name 'heroku run console', app_name
102
+
103
+ when 'log'
104
+ puts "Tailing the log on Heroku...\n"
105
+ exec_command_with_app_name 'heroku logs --source app --num 100 --tail', app_name
106
+
107
+ when 'secrets'
108
+ share_secrets
109
+
110
+ when 'dm'
111
+ puts "Running full deployment.\n"
112
+ exec_command_with_app_name 'heroku maintenance:on', app_name
113
+ deploy
114
+ migrate
115
+ exec_command_with_app_name 'heroku maintenance:off', app_name
116
+
117
+ when 'rake'
118
+ task = ARGV.shift
119
+ if !task || task == ''
120
+ puts "No rake task specified!\n"
121
+ else
122
+ exec_command_with_app_name "heroku run rake #{task}", app_name
123
+ end
124
+
125
+ when 'sync'
126
+ require 'yaml'
127
+ db_file = File.join `pwd`.chop, 'config', 'database.yml'
128
+ if File.exists?(db_file)
129
+ db_config = YAML.load open(db_file).read
130
+ dev_config = db_config['development']
131
+ if dev_config
132
+ db_name = dev_config['database']
133
+ db_host = dev_config['host'] || 'localhost'
134
+ db_user = dev_config['username']
135
+ db_pass = dev_config['password']
136
+ if !db_name or !db_host or !db_user or !db_pass
137
+ puts "Database configuration is incomplete.\n"
138
+ end
139
+ filename = 'latest.dump'
140
+ puts "Prepping the remote database.\n"
141
+ exec_command_with_app_name "heroku pgbackups:capture --expire", app_name
142
+ puts "Retrieving the remote database.\n"
143
+ exec_command_with_app_name "curl -o #{filename} `heroku pgbackups:url --app #{app_name}`", app_name
144
+ puts "Loading the data into your local database. You may be asked for a password.\n"
145
+ system "pg_restore --verbose --clean --no-acl --no-owner -h #{db_host} -U #{db_user} -d #{db_name} #{filename}"
146
+ puts "Deleting the downloaded database dump.\n"
147
+ system "rm -f #{filename}"
148
+ else
149
+ puts "Found database.yml file but cannot find development config."
150
+ end
151
+ else
152
+ puts "Unable to locate your database.yml file."
153
+ end
154
+
155
+ else
156
+ msg = "This is the easy access script for common Heroku commands. \nThe following commands are available: \n"
157
+ msg += "h app APP_NAME Set the app name for subsequent h commands\n"
158
+ msg += "h deploy MESSAGE Runs git add, commit, push origin master, and push heroku\n"
159
+ msg += "h secrets Shares your app secrets in config/secrets.yml with your Heroku app\n"
160
+ msg += "h log Tails the Heroku log file plus the last 200 lines\n"
161
+ msg += "h console Brings up the Rails console for your Heroku app\n"
162
+ msg += "h migrate Runs rake db:migrate on the Heroku database\n"
163
+ msg += "h seed Runs rake db:seed on the Heroku database\n"
164
+ msg += "h dm MESSAGE Runs deploy and migrate in maintenance mode\n"
165
+ msg += "h rake TASK Runs rake task\n"
166
+ msg += "h sync Syncs local database to fresh backup\n"
167
+ puts msg
168
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'heroku_buddy/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "heroku_buddy"
8
+ spec.version = HerokuBuddy::VERSION
9
+ spec.authors = ["David Furber"]
10
+ spec.email = ["furberd@gmail.com"]
11
+ spec.description = %q{Provides a binary called 'h' that gives access to common heroku tasks.}
12
+ spec.summary = %q{The 'h' command is your Heroku toolbelt buddy.}
13
+ spec.homepage = "http://github.com/dfurber/heroku-buddy"
14
+ spec.license = "MIT"
15
+ spec.executables = ["h"]
16
+
17
+ spec.files = `git ls-files`.split($/)
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency 'secretive'
23
+ end
@@ -0,0 +1,3 @@
1
+ module HerokuBuddy
2
+ VERSION = "0.0.5"
3
+ end
@@ -0,0 +1,5 @@
1
+ require "heroku_buddy/version"
2
+
3
+ module HerokuBuddy
4
+ # Your code goes here...
5
+ end
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: heroku_buddy
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.5
5
+ platform: ruby
6
+ authors:
7
+ - David Furber
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-11-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: secretive
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: Provides a binary called 'h' that gives access to common heroku tasks.
28
+ email:
29
+ - furberd@gmail.com
30
+ executables:
31
+ - h
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - .gitignore
36
+ - Gemfile
37
+ - LICENSE.txt
38
+ - README.md
39
+ - Rakefile
40
+ - bin/h
41
+ - heroku_buddy.gemspec
42
+ - lib/heroku_buddy.rb
43
+ - lib/heroku_buddy/version.rb
44
+ homepage: http://github.com/dfurber/heroku-buddy
45
+ licenses:
46
+ - MIT
47
+ metadata: {}
48
+ post_install_message:
49
+ rdoc_options: []
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - '>='
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ requirements: []
63
+ rubyforge_project:
64
+ rubygems_version: 2.0.6
65
+ signing_key:
66
+ specification_version: 4
67
+ summary: The 'h' command is your Heroku toolbelt buddy.
68
+ test_files: []