instapusher 0.0.26 → 0.0.27

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: 426e46111055230895ec30e82a657e934052fe8e
4
+ data.tar.gz: 77de92ae3a4b52db6650fef22972b31867f72d94
5
+ SHA512:
6
+ metadata.gz: b61bdf4d1767f991afeb2da2d44211f0285deaa812acf7094f1c90f205cbc3f99d6a9b837ae96f75ab7cbbd7117065d8f5a62ae72a6b4958887f3e1da39f888c
7
+ data.tar.gz: e5259eda99002e337dbbb6a42afbb88898280e652732937cae55de96ca4b5c927701fa02b3b8a09db093b5b58cb83d6512a47cb153f0213623998dacf9b3df54
data/README.md CHANGED
@@ -6,20 +6,20 @@ Makes it easy to push to heroku.
6
6
 
7
7
  gem install instapusher
8
8
 
9
- ## Usage
9
+ ## Setting up account
10
10
 
11
- instapusher
11
+ * Login at instapusher.com .
12
+ * visit http://instapusher.com/my/api_key and click on the link that says ".instapusher". Save this file at ~.
12
13
 
13
- It detects a project name and a branch from the git repo. Else you can specify it from the command line like:
14
+ ## Usage
14
15
 
15
- instapusher rails master
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.
16
18
 
19
+ instapusher
17
20
 
18
- After installing the gem you should register in the `http://instapusher.com`.
19
- Setup a project using the user and project name from the github. And create a config file `.instapusher` with api key.
20
- Example:
21
+ It detects project name and a branch from the git repo and starts deploying your project.
21
22
 
22
- api_key: 123123123
23
23
 
24
24
  ## Setup Instapusher server
25
25
 
@@ -5,8 +5,6 @@ require 'uri'
5
5
  module Instapusher
6
6
  class Commands
7
7
 
8
- DEFAULT_HOSTNAME = 'instapusher.com'
9
-
10
8
  attr_reader :debug, :api_key, :branch_name, :project_name
11
9
 
12
10
  def initialize init_options = {}
@@ -19,6 +17,23 @@ module Instapusher
19
17
  @project_name = init_options[:branch_name] || ENV['INSTAPUSHER_PROJECT'] || git.project_name
20
18
  end
21
19
 
20
+ def deploy
21
+ verify_api_key
22
+ SpecialInstructionForProduction.new.run if production?
23
+
24
+ submission = JobSubmission.new(debug, options)
25
+ submission.submit_the_job
26
+
27
+ if submission.success?
28
+ submission.feedback_to_user
29
+ TagTheRelease.new(branch_name, debug).tagit if production?
30
+ else
31
+ puts submission.error_message
32
+ end
33
+ end
34
+
35
+ private
36
+
22
37
  def options
23
38
  @options ||= begin
24
39
  { project: project_name,
@@ -39,75 +54,9 @@ module Instapusher
39
54
  end
40
55
  end
41
56
 
42
- def url
43
- @url ||= begin
44
- hostname = if options[:local]
45
- "localhost:3000"
46
- else
47
- ENV['INSTAPUSHER_HOST'] || DEFAULT_HOSTNAME
48
- end
49
- "http://#{hostname}/heroku.json"
50
- end
51
- end
52
-
53
- def special_instructions_for_production
54
- question = "You are deploying to production. Did you take backup? If not then execute rake handy:heroku:backup_production and then come back. "
55
- STDOUT.puts question
56
- STDOUT.puts "Answer 'yes' or 'no' "
57
-
58
- input = STDIN.gets.chomp.downcase
59
-
60
- if %w(yes y).include?(input)
61
- #do nothing
62
- elsif %w(no n).include?(input)
63
- abort "Please try again when you have taken the backup"
64
- else
65
- abort "Please answer yes or no"
66
- end
67
- end
68
-
69
- def tag_release
70
- return if branch_name.intern != :production
71
-
72
- version_number = Time.current.to_s.parameterize
73
- tag_name = "#{branch_name}-#{version_number}"
74
-
75
- cmd = "git tag -a -m \"Version #{tag_name}\" #{tag_name}"
76
- puts cmd if debug
77
- system cmd
78
-
79
- cmd = "git push --tags"
80
- puts cmd if debug
81
- system cmd
57
+ def production?
58
+ branch_name.intern != :production
82
59
  end
83
60
 
84
- def deploy
85
- verify_api_key
86
- special_instructions_for_production if branch_name.intern == :production
87
-
88
- if debug
89
- puts "url to hit: #{url.inspect}"
90
- puts "options being passed to the url: #{options.inspect}"
91
- puts "connecting to #{url} to send data"
92
- end
93
-
94
- response = Net::HTTP.post_form URI.parse(url), options
95
- response_body = ::JSON.parse(response.body)
96
-
97
- puts "response_body: #{response_body.inspect}" if debug
98
-
99
- job_status_url = response_body['status'] || response_body['job_status_url']
100
-
101
- if job_status_url && job_status_url != ""
102
- puts 'The appliction will be deployed to: ' + response_body['heroku_url']
103
- puts 'Monitor the job status at: ' + job_status_url
104
- cmd = "open #{job_status_url}"
105
- `#{cmd}`
106
-
107
- tag_release
108
- else
109
- puts response_body['error']
110
- end
111
- end
112
61
  end
113
62
  end
@@ -0,0 +1,52 @@
1
+ class JobSubmission
2
+
3
+ attr_reader :options, :debug, :job_status_url
4
+
5
+ DEFAULT_HOSTNAME = 'instapusher.com'
6
+
7
+ def initialize debug, options
8
+ @debug = debug
9
+ @options = options
10
+ end
11
+
12
+ def success?
13
+ job_status_url && job_status_url != ""
14
+ end
15
+
16
+ def pre_submission_feedback_to_user
17
+ puts "url to hit: #{url_to_submit_job.inspect}"
18
+ puts "options being passed to the url: #{options.inspect}"
19
+ puts "connecting to #{url_to_submit_job} to send data"
20
+ end
21
+
22
+ def feedback_to_user
23
+ puts 'The appliction will be deployed to: ' + response_body['heroku_url']
24
+ puts 'Monitor the job status at: ' + job_status_url
25
+ cmd = "open #{job_status_url}"
26
+ `#{cmd}`
27
+ end
28
+
29
+ def error_message
30
+ response_body['error']
31
+ end
32
+
33
+ def submit_the_job
34
+ pre_submission_feedback_to_user if debug
35
+
36
+ response = Net::HTTP.post_form URI.parse(url_to_submit_job), options
37
+ @response_body = ::JSON.parse(response.body)
38
+ puts "response_body: #{response_body.inspect}" if debug
39
+ @job_status_url = response_body['status'] || response_body['job_status_url']
40
+ end
41
+
42
+ def url_to_submit_job
43
+ @url ||= begin
44
+ hostname = if options[:local]
45
+ "localhost:3000"
46
+ else
47
+ ENV['INSTAPUSHER_HOST'] || DEFAULT_HOSTNAME
48
+ end
49
+ "http://#{hostname}/heroku.json"
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,19 @@
1
+ class SpecialInstructionForProduction
2
+
3
+ def run
4
+ question = "You are deploying to production. Did you take backup? If not then execute rake handy:heroku:backup_production and then come back. "
5
+ STDOUT.puts question
6
+ STDOUT.puts "Answer 'yes' or 'no' "
7
+
8
+ input = STDIN.gets.chomp.downcase
9
+
10
+ if %w(yes y).include?(input)
11
+ #do nothing
12
+ elsif %w(no n).include?(input)
13
+ abort "Please try again when you have taken the backup"
14
+ else
15
+ abort "Please answer yes or no"
16
+ end
17
+ end
18
+
19
+ end
@@ -0,0 +1,21 @@
1
+ class TagTheRelease
2
+
3
+ def initialize branch_name, debug
4
+ @branch_name = branch_name
5
+ @debug = debug
6
+ end
7
+
8
+ def tagit
9
+ version_number = Time.current.to_s.parameterize
10
+ tag_name = "#{branch_name}-#{version_number}"
11
+
12
+ cmd = "git tag -a -m \"Version #{tag_name}\" #{tag_name}"
13
+ puts cmd if debug
14
+ system cmd
15
+
16
+ cmd = "git push --tags"
17
+ puts cmd if debug
18
+ system cmd
19
+ end
20
+
21
+ end
@@ -1,3 +1,3 @@
1
1
  module Instapusher
2
- VERSION = "0.0.26"
2
+ VERSION = "0.0.27"
3
3
  end
metadata CHANGED
@@ -1,20 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: instapusher
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.26
5
- prerelease:
4
+ version: 0.0.27
6
5
  platform: ruby
7
6
  authors:
8
7
  - Neeraj Singh
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-07-28 00:00:00.000000000 Z
11
+ date: 2013-12-24 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: hashr
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ~>
20
18
  - !ruby/object:Gem::Version
@@ -22,7 +20,6 @@ dependencies:
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ~>
28
25
  - !ruby/object:Gem::Version
@@ -30,33 +27,29 @@ dependencies:
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: json
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - '>='
36
32
  - !ruby/object:Gem::Version
37
33
  version: '0'
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - '>='
44
39
  - !ruby/object:Gem::Version
45
40
  version: '0'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: activesupport
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - '>='
52
46
  - !ruby/object:Gem::Version
53
47
  version: '0'
54
48
  type: :runtime
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - '>='
60
53
  - !ruby/object:Gem::Version
61
54
  version: '0'
62
55
  description: instapusher makes it easy to push code to heroku
@@ -75,42 +68,35 @@ files:
75
68
  - bin/instapusher
76
69
  - instapusher.gemspec
77
70
  - lib/instapusher.rb
78
- - lib/instapusher/base.rb
79
- - lib/instapusher/command_builder.rb
80
71
  - lib/instapusher/commands.rb
81
72
  - lib/instapusher/configuration.rb
82
- - lib/instapusher/executor.rb
83
73
  - lib/instapusher/git.rb
74
+ - lib/instapusher/job_submission.rb
84
75
  - lib/instapusher/railtie.rb
76
+ - lib/instapusher/special_instruction_for_production.rb
77
+ - lib/instapusher/tag_the_release.rb
85
78
  - lib/instapusher/version.rb
86
79
  homepage: http://bigbinary.com
87
80
  licenses: []
81
+ metadata: {}
88
82
  post_install_message:
89
83
  rdoc_options: []
90
84
  require_paths:
91
85
  - lib
92
86
  required_ruby_version: !ruby/object:Gem::Requirement
93
- none: false
94
87
  requirements:
95
- - - ! '>='
88
+ - - '>='
96
89
  - !ruby/object:Gem::Version
97
90
  version: '0'
98
- segments:
99
- - 0
100
- hash: -2795862304600486608
101
91
  required_rubygems_version: !ruby/object:Gem::Requirement
102
- none: false
103
92
  requirements:
104
- - - ! '>='
93
+ - - '>='
105
94
  - !ruby/object:Gem::Version
106
95
  version: '0'
107
- segments:
108
- - 0
109
- hash: -2795862304600486608
110
96
  requirements: []
111
97
  rubyforge_project:
112
- rubygems_version: 1.8.23
98
+ rubygems_version: 2.0.3
113
99
  signing_key:
114
- specification_version: 3
100
+ specification_version: 4
115
101
  summary: instapusher gem makes it easy to push code to heroku
116
102
  test_files: []
@@ -1,72 +0,0 @@
1
- require "open3"
2
-
3
- module Instapusher
4
- class Base
5
-
6
- attr_accessor :branch_name, :commands, :current_user, :settings, :named_branches, :job
7
- attr_reader :callbacks, :project_name, :heroku_app_name, :git, :config, :config_file
8
-
9
- def initialize(job_id, config_path, callbacks)
10
- @job = ::Job.find_by_id! job_id
11
- @callbacks = callbacks
12
-
13
- @git = Git.new
14
- @commands = []
15
- @config_file = File.join(config_path, 'instapusher.yml')
16
- @config = ConfigLoader.new(@config_file)
17
- @project_name = @job.project_name
18
- @branch_name = @job.branch_name
19
- after_initialize
20
- end
21
-
22
- def push
23
- CommandBuilder.new(self).build.each_with_index do |cmd, index|
24
- Executor.new(self).execute(cmd, index)
25
- end
26
- end
27
-
28
- private
29
-
30
- def after_initialize
31
- set_current_user_name
32
- set_named_branches
33
- set_settings
34
- set_heroku_app_name
35
- set_env
36
- reload_config
37
- end
38
-
39
- def set_env
40
- ENV['BRANCH_NAME'] = branch_name
41
- ENV['HEROKU_APP_NAME'] = heroku_app_name
42
- ENV['HEROKU_APP_URL'] = "http://#{heroku_app_name}.herokuapp.com"
43
- ENV['APP_URL'] = @settings.app_url ? @settings.app_url : ENV['HEROKU_APP_URL']
44
- end
45
-
46
- def set_current_user_name
47
- @current_user = git.current_user
48
- end
49
-
50
- def set_named_branches
51
- @named_branches = config.named_branches
52
- end
53
-
54
- def set_settings
55
- @settings = config.settings(branch_name)
56
- end
57
-
58
- def set_heroku_app_name
59
- @heroku_app_name = HerokuAppNameGenerator.new( project_name, branch_name).name
60
- end
61
-
62
- def reload_config
63
- @config = ConfigLoader.new(config_file)
64
- set_settings
65
- end
66
-
67
- def sanitized_user_name
68
- current_user || 'ip'
69
- end
70
-
71
- end
72
- end
@@ -1,64 +0,0 @@
1
- module Instapusher
2
- class CommandBuilder
3
-
4
- attr_reader :base
5
-
6
- delegate :setttings, to: :base
7
- delegate :heroku_app_name, to: :base
8
- delegate :callbacks, to: :base
9
- delegate :job, to: :base
10
-
11
- def initialize base
12
- raise 'boom'
13
-
14
- @base = base
15
- @commands = []
16
- end
17
-
18
- def build
19
- add_pre_config_commands
20
- add_config_environment_commands
21
- add_before_every_install_commands
22
- add_callback_commands
23
- add_after_every_install
24
-
25
- commands.flatten!.compact!
26
- feedback_to_user
27
- commands
28
- end
29
-
30
- private
31
-
32
- def feedback_to_user
33
- job.add_log 'Following commands will be executed:'
34
- commands.each do |cmd|
35
- job.add_log(' '*4 + cmd)
36
- end
37
- end
38
-
39
- def add_after_every_install
40
- commands << settings.post_config_commands.after_every_install
41
- end
42
-
43
- def add_callback_commands
44
- callbacks.each do |callback|
45
- commands << settings.post_config_commands[callback]
46
- end
47
- end
48
-
49
- def add_before_every_install_commands
50
- commands << settings.post_config_commands.before_every_install
51
- end
52
-
53
- def add_pre_config_commands
54
- commands << settings.pre_config_commands
55
- end
56
-
57
- def add_config_environment_commands
58
- return unless settings.config
59
- config_cmd = settings.config.map { |key, value| "#{key.upcase}=#{value}" }
60
- commands << "bundle exec heroku config:add #{config_cmd.join(' ')} --app #{heroku_app_name}"
61
- end
62
-
63
- end
64
- end
@@ -1,58 +0,0 @@
1
- module Instapusher
2
- class Executor
3
-
4
- attr_accessor :base
5
-
6
- delegate :job, to: :base
7
-
8
- def initialize base
9
- raise 'boom'
10
- @base = base
11
- end
12
-
13
- def execute cmd, index
14
- job.add_log("executing: #{cmd}")
15
- handle_error unless execute_using_popen3
16
- end
17
-
18
- private
19
-
20
- def handle_failure
21
- job.update_attributes(ended_at: Time.now, status: :failed)
22
- msg = "#{cmd} FAILED"
23
- job.add_log(msg)
24
- raise msg
25
- end
26
-
27
- # returns false if command fails
28
- def execute_using_popen3
29
- Open3.popen3(cmd) do |stdin, stdout, stderr, wait_thr|
30
- while line = stdout.gets
31
- job.add_log(line)
32
- end
33
- while line = stderr.gets
34
- job.add_log(line)
35
- end
36
-
37
- exit_status = wait_thr.value
38
-
39
- job.add_log("exist_status.success? is: #{exit_status.success?}")
40
- job.add_log("index is: #{index}")
41
-
42
- success = exit_status.success?
43
- failure = !success
44
-
45
- if failure && index == 1
46
- cmd = "git remote add h#{branch_name} git@heroku.com:#{heroku_app_name}.git"
47
- job.add_log(cmd)
48
- return false unless system(cmd)
49
- elsif failure && index != 1
50
- return false
51
- end
52
-
53
- true
54
- end
55
- end
56
-
57
- end
58
- end