instapusher2 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e7ebb292c110fdb9d84d44aaab283eb2865aacfb
4
+ data.tar.gz: 9bd5020b8fdfc2961530828b75be70197f229cbc
5
+ SHA512:
6
+ metadata.gz: 62bbba92fbe34b0180f160d351a73a588194e3d7deb8670e12d48bfd9a229573bc37831d32a73d05bf74243bb967692542ad3d3be8a30605bc04132c9dd54bfc
7
+ data.tar.gz: fc89c9933644db324e2326be2b1d0b36a01dcb0bd1c97275b0963d534005898a8b315065c9f4c43a18b7d09f9df6574d8c9324e446f762db5e5c525255dd20d2
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,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem 'rake'
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Neeraj Singh
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,82 @@
1
+ # Instapusher
2
+
3
+ Makes it easy to push to heroku.
4
+
5
+ ## Installation
6
+
7
+ gem install instapusher
8
+
9
+ ## Setting up account
10
+
11
+ * Login at instapusher.com .
12
+ * Execute `instapusher --api-key` on local machine .
13
+
14
+ ## Usage
15
+
16
+ In order to deploy your code first make sure that you are in the branch that you want to deploy.
17
+ Then execute this command.
18
+
19
+ ```
20
+ instapusher
21
+ ```
22
+
23
+ It detects project name and a branch from the git repo and starts deploying your project.
24
+
25
+ ### Running background jobs and other rake tasks
26
+
27
+ Instapusher does not create workers on heroku for your project.
28
+ Background jobs or rake tasks should be run manually from the console.
29
+
30
+ ``` sh
31
+ heroku run rake <TASK_NAME> --app <APP_NAME_GIVEN_BY_INSTAPUSHER>
32
+ ```
33
+
34
+ For eg. to run delayed job workers
35
+
36
+ ``` sh
37
+ heroku run rake jobs:work --app my-awesome-app-42-add-devise-authentication-ip
38
+ ```
39
+
40
+ ## Setup Instapusher server
41
+
42
+ You can provide the env variable `LOCAL` like:
43
+
44
+ instapusher --local
45
+
46
+ To enable debug messages do
47
+
48
+ instapusher --debug
49
+
50
+ Pass host info like this
51
+
52
+ INSTAPUSHER_HOST=instapusher.com instapusher
53
+
54
+ Also there are other env variables like `INSTAPUSHER_PROJECT` and `INSTAPUSHER_BRANCH`.
55
+
56
+ INSTAPUSHER_HOST=instapusher.com INSTAPUSHER_PROJECT=rails INSTAPUSHER_BRANCH=master instapusher
57
+
58
+ ALSO you can pass your `api_key`
59
+
60
+ API_KEY=xxxx instapusher
61
+
62
+ ## What problem it solves
63
+
64
+ Here at BigBinary we create a separate branch for each feature we work
65
+ on. Let's say that I am working on `authentication with facebook`.
66
+ When I am done with the feature then I send pull request to my team
67
+ members to review. However in order to review the work all the team
68
+ members need to pull down the branch and fire up `rails server` and then
69
+ review.
70
+
71
+ We like to see things working. So we developed `instapusher` to push a
72
+ feature branch to heroku instantly with one command. Executing
73
+ `instapusher` prints a url and we put that url in the pull request so
74
+ that team members can actually test the feature.
75
+
76
+ ## Here is how it works
77
+
78
+ A video is coming up.
79
+
80
+ ## License
81
+
82
+ `instapusher` is released under MIT License.
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
data/bin/instapusher2 ADDED
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../lib/instapusher2'
4
+
5
+ require 'optparse'
6
+
7
+ options = {}
8
+ OptionParser.new do |opts|
9
+
10
+ opts.on("-v", "--version", "show version") do |v|
11
+ options[:version] = v
12
+ end
13
+
14
+ opts.on("--quick", "Run quickly") do |v|
15
+ options[:quick] = v
16
+ end
17
+
18
+ opts.on("--local", "Run locally") do |v|
19
+ options[:local] = v
20
+ end
21
+
22
+ opts.on("--debug", "Show debug messages") do |v|
23
+ options[:debug] = v
24
+ end
25
+
26
+ opts.on("--api-key", "Setup Instapusher api key") do |v|
27
+ options[:api_key] = v
28
+ end
29
+
30
+ end.parse!
31
+
32
+ if options[:version]
33
+ puts Instapusher2::VERSION
34
+
35
+ elsif options[:api_key]
36
+ Instapusher2::Configuration.ask_for_and_write_api_key
37
+
38
+ else
39
+ Instapusher2::Commands.new(options).deploy
40
+ end
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/instapusher2/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Neeraj Singh"]
6
+ gem.email = ["neeraj@bigbinary.com"]
7
+ gem.description = %q{instapusher makes it easy to push code to heroku}
8
+ gem.summary = %q{instapusher gem makes it easy to push code to heroku}
9
+ gem.homepage = "http://bigbinary.com"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "instapusher2"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Instapusher2::VERSION
17
+
18
+ gem.add_dependency("hashr", ">= 0.0.19")
19
+ gem.add_dependency("json")
20
+ gem.add_dependency("activesupport")
21
+ end
@@ -0,0 +1,12 @@
1
+ require_relative './instapusher2/git'
2
+ require_relative './instapusher2/commands'
3
+ require_relative './instapusher2/version'
4
+ require_relative './instapusher2/configuration'
5
+ require_relative './instapusher2/job_submission'
6
+ require_relative './instapusher2/special_instruction_for_production'
7
+ require_relative './instapusher2/tag_the_release'
8
+ require 'active_support/all'
9
+ require 'json'
10
+
11
+ module Instapusher2
12
+ end
@@ -0,0 +1,65 @@
1
+ require_relative "../instapusher2"
2
+ require 'net/http'
3
+ require 'uri'
4
+
5
+ module Instapusher2
6
+ class Commands
7
+
8
+ attr_reader :debug, :api_key, :branch_name, :project_name
9
+
10
+ def initialize init_options = {}
11
+ @debug = init_options[:debug]
12
+ @quick = init_options[:quick]
13
+ @local = init_options[:local]
14
+
15
+ git = Git.new
16
+ @branch_name = init_options[:project_name] || ENV['INSTAPUSHER_BRANCH'] || git.current_branch
17
+ @project_name = init_options[:branch_name] || ENV['INSTAPUSHER_PROJECT'] || git.project_name
18
+ end
19
+
20
+ def deploy
21
+ verify_api_key
22
+ #SpecialInstructionForProduction.new.run if production?
23
+
24
+ job_submission = JobSubmission.new(debug, options)
25
+ job_submission.submit_the_job
26
+
27
+ if job_submission.success?
28
+ job_submission.feedback_to_user
29
+ TagTheRelease.new(branch_name, debug).tagit if production?
30
+ else
31
+ puts job_submission.error_message
32
+ end
33
+ end
34
+
35
+ private
36
+
37
+ def options
38
+ @options ||= begin
39
+ { project: project_name,
40
+ branch: branch_name,
41
+ owner: Git.new.repo_owner,
42
+ quick: @quick,
43
+ local: @local,
44
+ api_key: api_key }
45
+ end
46
+ end
47
+
48
+ def verify_api_key
49
+ @api_key = ENV['API_KEY'] || Instapusher::Configuration.api_key(debug) || ""
50
+
51
+ if @api_key.to_s.length == 0
52
+ puts ''
53
+ abort "No instapusher API key was found. Please execute instapusher --api-key to setup instapusher API key."
54
+
55
+ elsif debug
56
+ puts "api_key is #{@api_key}"
57
+ end
58
+ end
59
+
60
+ def production?
61
+ branch_name.intern == :production
62
+ end
63
+
64
+ end
65
+ end
@@ -0,0 +1,53 @@
1
+ require 'yaml'
2
+
3
+ # used to read api_key
4
+ module Instapusher2
5
+ module Configuration
6
+ extend self
7
+ @_settings = {}
8
+ attr_reader :_settings
9
+
10
+ def load(debug = false, filename=nil)
11
+ filename ||= File.join(ENV['HOME'], '.instapusher')
12
+
13
+ unless File.exist? filename
14
+ File.new(filename, File::CREAT|File::TRUNC|File::RDWR, 0644).close
15
+ end
16
+
17
+ @_settings = YAML::load_file(filename) || {}
18
+
19
+ if debug
20
+ puts @_settings.inspect
21
+ end
22
+ end
23
+
24
+ def ask_for_api_key
25
+ puts ""
26
+ puts "Note: Your instapusher API key is available at http://www.instapusher.com/my/api_key"
27
+ puts ""
28
+ puts "Enter your Instapusher API key:"
29
+ api_key = ask
30
+ api_key
31
+ end
32
+
33
+ def ask_for_and_write_api_key
34
+ api_key = ask_for_api_key
35
+ instapusher_config = {"api_key" => api_key}
36
+ File.open(File.join(Dir.home, ".instapusher2"), "w") do |file|
37
+ file.write instapusher_config.to_yaml
38
+ end
39
+
40
+ puts ""
41
+ puts "You are all set. Start using instapusher2."
42
+ end
43
+
44
+ def ask
45
+ $stdin.gets.to_s.strip
46
+ end
47
+
48
+ def method_missing(name, *args, &block)
49
+ self.load
50
+ @_settings[name.to_s]
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,31 @@
1
+ module Instapusher2
2
+ class Git
3
+ def current_branch
4
+ result = %x{git branch}.split("\n")
5
+ if result.empty?
6
+ raise "It seems your app is not a git repo"
7
+ else
8
+ result.select { |b| b =~ /^\*/ }.first.split(" ").last.strip
9
+ end
10
+ end
11
+
12
+ def current_user
13
+ `git config user.name`.chop!
14
+ end
15
+
16
+ def project_name
17
+ result = `git config remote.origin.url`.chop!.scan(/\/([^\/]+)?$/).flatten.first
18
+ result.sub!(/\.git$/, '') if result
19
+ result ||= File.basename(Dir.getwd)
20
+ result
21
+ end
22
+
23
+ def repo_owner
24
+ string = `git remote -v | grep fetch | grep origin`
25
+ regex = /.*:(.*)\/.*/
26
+ match_data = string.match(regex)
27
+ match_data.to_a.last
28
+ end
29
+
30
+ end
31
+ end
@@ -0,0 +1,54 @@
1
+ module Instapusher2
2
+ class JobSubmission
3
+
4
+ attr_reader :options, :debug, :job_status_url, :response_body
5
+
6
+ DEFAULT_HOSTNAME = 'instapusher.com'
7
+
8
+ def initialize debug, options
9
+ @debug = debug
10
+ @options = options
11
+ end
12
+
13
+ def success?
14
+ job_status_url && job_status_url != ""
15
+ end
16
+
17
+ def pre_submission_feedback_to_user
18
+ puts "url to hit: #{url_to_submit_job.inspect}"
19
+ puts "options being passed to the url: #{options.inspect}"
20
+ puts "connecting to #{url_to_submit_job} to send data"
21
+ end
22
+
23
+ def feedback_to_user
24
+ puts 'The application will be deployed to: ' + response_body['heroku_url']
25
+ puts 'Monitor the job status at: ' + job_status_url
26
+ cmd = "open #{job_status_url}"
27
+ `#{cmd}`
28
+ end
29
+
30
+ def error_message
31
+ response_body['error']
32
+ end
33
+
34
+ def submit_the_job
35
+ pre_submission_feedback_to_user if debug
36
+
37
+ response = Net::HTTP.post_form URI.parse(url_to_submit_job), options
38
+ @response_body = ::JSON.parse(response.body)
39
+ puts "response_body: #{response_body.inspect}" if debug
40
+ @job_status_url = response_body['status'] || response_body['job_status_url']
41
+ end
42
+
43
+ def url_to_submit_job
44
+ @url ||= begin
45
+ hostname = if options[:local]
46
+ "localhost:3000"
47
+ else
48
+ ENV['INSTAPUSHER_HOST'] || DEFAULT_HOSTNAME
49
+ end
50
+ "http://#{hostname}/heroku.json"
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,16 @@
1
+ require 'rails/engine'
2
+
3
+ module Instapusher2
4
+ class Engine < Rails::Engine
5
+
6
+ rake_tasks do
7
+ require 'instapusher2/commands'
8
+
9
+ desc "pushes to heroku"
10
+ task :instapusher2 do
11
+ Instapusher::Commands.deploy
12
+ end
13
+ end
14
+
15
+ end
16
+ end
@@ -0,0 +1,21 @@
1
+ module Instapusher2
2
+ class SpecialInstructionForProduction
3
+
4
+ def run
5
+ question = "You are deploying to production. Did you take backup? If not then execute rake handy:heroku:backup_production and then come back. "
6
+ STDOUT.puts question
7
+ STDOUT.puts "Answer 'yes' or 'no' "
8
+
9
+ input = STDIN.gets.chomp.downcase
10
+
11
+ if %w(yes y).include?(input)
12
+ #do nothing
13
+ elsif %w(no n).include?(input)
14
+ abort "Please try again when you have taken the backup"
15
+ else
16
+ abort "Please answer yes or no"
17
+ end
18
+ end
19
+
20
+ end
21
+ end
@@ -0,0 +1,25 @@
1
+ module Instapusher2
2
+ class TagTheRelease
3
+
4
+ attr_reader :branch_name, :debug
5
+
6
+ def initialize branch_name, debug
7
+ @branch_name = branch_name
8
+ @debug = debug
9
+ end
10
+
11
+ def tagit
12
+ version_number = Time.current.to_s.parameterize
13
+ tag_name = "#{branch_name}-#{version_number}"
14
+
15
+ cmd = "git tag -a -m \"Version #{tag_name}\" #{tag_name}"
16
+ puts cmd if debug
17
+ system cmd
18
+
19
+ cmd = "git push --tags"
20
+ puts cmd if debug
21
+ system cmd
22
+ end
23
+
24
+ end
25
+ end
@@ -0,0 +1,3 @@
1
+ module Instapusher2
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: instapusher2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Neeraj Singh
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-04-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: hashr
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: 0.0.19
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: 0.0.19
27
+ - !ruby/object:Gem::Dependency
28
+ name: json
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: activesupport
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: instapusher makes it easy to push code to heroku
56
+ email:
57
+ - neeraj@bigbinary.com
58
+ executables:
59
+ - instapusher2
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - .gitignore
64
+ - Gemfile
65
+ - LICENSE
66
+ - README.md
67
+ - Rakefile
68
+ - bin/instapusher2
69
+ - instapusher2.gemspec
70
+ - lib/instapusher2.rb
71
+ - lib/instapusher2/commands.rb
72
+ - lib/instapusher2/configuration.rb
73
+ - lib/instapusher2/git.rb
74
+ - lib/instapusher2/job_submission.rb
75
+ - lib/instapusher2/railtie.rb
76
+ - lib/instapusher2/special_instruction_for_production.rb
77
+ - lib/instapusher2/tag_the_release.rb
78
+ - lib/instapusher2/version.rb
79
+ homepage: http://bigbinary.com
80
+ licenses: []
81
+ metadata: {}
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - '>='
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - '>='
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubyforge_project:
98
+ rubygems_version: 2.0.3
99
+ signing_key:
100
+ specification_version: 4
101
+ summary: instapusher gem makes it easy to push code to heroku
102
+ test_files: []