instapusher 0.0.1 → 0.0.2
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/README.md +53 -50
- data/bin/instapusher +5 -0
- data/instapusher.gemspec +5 -5
- data/lib/instapusher.rb +8 -0
- data/lib/instapusher/base.rb +72 -0
- data/lib/instapusher/command_builder.rb +62 -0
- data/lib/instapusher/commands.rb +45 -0
- data/lib/instapusher/executor.rb +57 -0
- data/lib/instapusher/git.rb +20 -0
- data/lib/{instapusher2 → instapusher}/railtie.rb +3 -3
- data/lib/instapusher/version.rb +3 -0
- metadata +43 -30
- checksums.yaml +0 -7
- data/bin/instapusher2 +0 -40
- data/lib/instapusher2.rb +0 -12
- data/lib/instapusher2/commands.rb +0 -65
- data/lib/instapusher2/configuration.rb +0 -53
- data/lib/instapusher2/git.rb +0 -31
- data/lib/instapusher2/job_submission.rb +0 -54
- data/lib/instapusher2/special_instruction_for_production.rb +0 -21
- data/lib/instapusher2/tag_the_release.rb +0 -25
- data/lib/instapusher2/version.rb +0 -3
data/README.md
CHANGED
@@ -4,79 +4,82 @@ Makes it easy to push to heroku.
|
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
7
|
-
|
7
|
+
Add this to Gemfile:
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
* Login at instapusher.com .
|
12
|
-
* Execute `instapusher --api-key` on local machine .
|
9
|
+
gem 'instapusher'
|
13
10
|
|
14
11
|
## Usage
|
15
12
|
|
16
|
-
|
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
|
-
```
|
13
|
+
rake instapusher
|
33
14
|
|
34
|
-
|
15
|
+
After installing the gem copy [this file](https://raw.github.com/gist/3098161/578dad8cd3933834712a8afdf33520221dbdb986/instapusher.yml) to `config/instapusher.yml` .
|
35
16
|
|
36
|
-
|
37
|
-
|
38
|
-
```
|
17
|
+
Change the contents of `config/instapusher.yml` as per your needs after
|
18
|
+
reading rest of README.
|
39
19
|
|
40
|
-
##
|
20
|
+
## What problem it solves
|
41
21
|
|
42
|
-
|
22
|
+
Here at BigBinary we create a separate branch for each feature we work
|
23
|
+
on. Let's say that I am working on `authentication with facebook`.
|
24
|
+
When I am done with the feature then I send pull request to my team
|
25
|
+
members to review. However in order to review the work all the team
|
26
|
+
members need to pull down the branch and fire up `rails server` and then
|
27
|
+
review.
|
43
28
|
|
44
|
-
|
29
|
+
We like to see things working. So we developed `push2heroku` to push a
|
30
|
+
feature branch to heroku instantly with one command. Executing
|
31
|
+
`push2heroku` prints a url and we put that url in the pull request so
|
32
|
+
that team members can actually test the feature.
|
45
33
|
|
46
|
-
|
34
|
+
## Here is how it works
|
47
35
|
|
48
|
-
|
36
|
+
`push2heroku` reads the `push2heroku.yml` and executes those commands.
|
37
|
+
It's that simple.
|
49
38
|
|
50
|
-
|
39
|
+
Lets say that I am working in a branch called
|
40
|
+
`76-facebook-authentication`. When I execute `push2heroku` then the
|
41
|
+
application name under which it will be deployed to heroku will be
|
42
|
+
`nimbleshop-76-facebook-neeraj`.
|
51
43
|
|
52
|
-
|
44
|
+
`nimbleshop` is the name of the project.
|
45
|
+
`76-facebook` is the first 10 letters of the branch name.
|
46
|
+
`neeraj` is the first 5 letters of my github user name.
|
53
47
|
|
54
|
-
|
48
|
+
So in this case the url of the application will be
|
49
|
+
`http://nimbleshop-76-facebook-neeraj.herokuapp.com` .
|
55
50
|
|
56
|
-
|
51
|
+
In the `push2heroku.yml` file the keys `production` and `staging`
|
52
|
+
are branch names. And these branches are special branches. For these
|
53
|
+
branches the url generated will be just the application name and the
|
54
|
+
branch name. For example if I execute `rake push2heroku` from `staging`
|
55
|
+
branch then the heroku url will be
|
56
|
+
`http://nimbleshop-staging.herokuapp.com`.
|
57
57
|
|
58
|
-
|
58
|
+
However if I delete `staging` key from `push2heroku.yml` then `staging`
|
59
|
+
is no longer a special branch and the heroku url would be
|
60
|
+
`http://nimbleshop-staging-neeraj.herokuapp.com` .
|
59
61
|
|
60
|
-
|
62
|
+
## Callbacks
|
61
63
|
|
62
|
-
|
64
|
+
The new design of `push2heroku` is very flexible. Let's say that Artem
|
65
|
+
wants to test something then he can add to `push2heroku.yml` something
|
66
|
+
like this
|
63
67
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
review.
|
68
|
+
```
|
69
|
+
regenerate_images:
|
70
|
+
- bundle exec heroku run rake db:regenerate_images --app <%=ENV['HEROKU_APP_NAME']%> --trace
|
71
|
+
- bundle exec heroku run rake db:post_image_cleanup --app <%=ENV['HEROKU_APP_NAME']%> --trace
|
72
|
+
```
|
70
73
|
|
71
|
-
|
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.
|
74
|
+
Now to execute all the commands under key `regenrate_images` all he has to do is
|
75
75
|
|
76
|
-
|
76
|
+
```
|
77
|
+
rake push2heroku CALLBACKS=reset_db_using_fixtures,regenerate_images
|
78
|
+
```
|
77
79
|
|
78
|
-
|
80
|
+
Just comma separate all the tasks. It's that simple. Now `push2heroku` gives all the control to the developer.
|
79
81
|
|
80
82
|
## License
|
81
83
|
|
82
84
|
`instapusher` is released under MIT License.
|
85
|
+
|
data/bin/instapusher
ADDED
data/instapusher.gemspec
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
require File.expand_path('../lib/
|
2
|
+
require File.expand_path('../lib/instapusher/version', __FILE__)
|
3
3
|
|
4
4
|
Gem::Specification.new do |gem|
|
5
5
|
gem.authors = ["Neeraj Singh"]
|
@@ -13,9 +13,9 @@ Gem::Specification.new do |gem|
|
|
13
13
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
14
|
gem.name = "instapusher"
|
15
15
|
gem.require_paths = ["lib"]
|
16
|
-
gem.version =
|
16
|
+
gem.version = Instapusher::VERSION
|
17
17
|
|
18
|
-
gem.add_dependency("hashr", "
|
19
|
-
gem.add_dependency("
|
20
|
-
gem.add_dependency("
|
18
|
+
gem.add_dependency("hashr", "~> 0.0.19")
|
19
|
+
gem.add_dependency("heroku", "~> 2.25.0")
|
20
|
+
gem.add_dependency("railties", ">= 3.1.0")
|
21
21
|
end
|
data/lib/instapusher.rb
ADDED
@@ -0,0 +1,72 @@
|
|
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
|
@@ -0,0 +1,62 @@
|
|
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
|
+
@base = base
|
13
|
+
@commands = []
|
14
|
+
end
|
15
|
+
|
16
|
+
def build
|
17
|
+
add_pre_config_commands
|
18
|
+
add_config_environment_commands
|
19
|
+
add_before_every_install_commands
|
20
|
+
add_callback_commands
|
21
|
+
add_after_every_install
|
22
|
+
|
23
|
+
commands.flatten!.compact!
|
24
|
+
feedback_to_user
|
25
|
+
commands
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def feedback_to_user
|
31
|
+
job.add_log 'Following commands will be executed:'
|
32
|
+
commands.each do |cmd|
|
33
|
+
job.add_log(' '*4 + cmd)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def add_after_every_install
|
38
|
+
commands << settings.post_config_commands.after_every_install
|
39
|
+
end
|
40
|
+
|
41
|
+
def add_callback_commands
|
42
|
+
callbacks.each do |callback|
|
43
|
+
commands << settings.post_config_commands[callback]
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def add_before_every_install_commands
|
48
|
+
commands << settings.post_config_commands.before_every_install
|
49
|
+
end
|
50
|
+
|
51
|
+
def add_pre_config_commands
|
52
|
+
commands << settings.pre_config_commands
|
53
|
+
end
|
54
|
+
|
55
|
+
def add_config_environment_commands
|
56
|
+
return unless settings.config
|
57
|
+
config_cmd = settings.config.map { |key, value| "#{key.upcase}=#{value}" }
|
58
|
+
commands << "bundle exec heroku config:add #{config_cmd.join(' ')} --app #{heroku_app_name}"
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'uri'
|
3
|
+
require 'multi_json'
|
4
|
+
require 'instapusher'
|
5
|
+
|
6
|
+
module Instapusher
|
7
|
+
class Commands
|
8
|
+
DEFAULT_HOSTNAME = 'instapusher.com'
|
9
|
+
|
10
|
+
def self.deploy
|
11
|
+
|
12
|
+
hostname = ENV['INSTAPUSHER_HOST'] || DEFAULT_HOSTNAME
|
13
|
+
|
14
|
+
#TODO: Remove this env and use host instead of duplication
|
15
|
+
if ENV['LOCAL']
|
16
|
+
hostname = "localhost:3000"
|
17
|
+
end
|
18
|
+
url = "http://#{hostname}/heroku"
|
19
|
+
|
20
|
+
|
21
|
+
git = Git.new
|
22
|
+
branch_name = git.current_branch
|
23
|
+
project_name = git.project_name
|
24
|
+
|
25
|
+
response = Net::HTTP.post_form(URI.parse(url),
|
26
|
+
{ project: project_name,
|
27
|
+
branch: branch_name,
|
28
|
+
local: ENV['LOCAL'],
|
29
|
+
'options[callbacks]' => ENV['CALLBACKS'] })
|
30
|
+
|
31
|
+
if response.code == '200'
|
32
|
+
response_body = MultiJson.load(response.body)
|
33
|
+
status_url = response_body['status']
|
34
|
+
|
35
|
+
status_url = status_url.gsub(DEFAULT_HOSTNAME, hostname) if ENV['LOCAL']
|
36
|
+
puts 'The appliction will be deployed to: ' + response_body['heroku_url']
|
37
|
+
puts 'Monitor the job status at: ' + status_url
|
38
|
+
cmd = "open #{status_url}"
|
39
|
+
`#{cmd}`
|
40
|
+
else
|
41
|
+
puts 'Something has gone wrong'
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module Instapusher
|
2
|
+
class Executor
|
3
|
+
|
4
|
+
attr_accessor :base
|
5
|
+
|
6
|
+
delegate :job, to: :base
|
7
|
+
|
8
|
+
def initialize base
|
9
|
+
@base = base
|
10
|
+
end
|
11
|
+
|
12
|
+
def execute cmd, index
|
13
|
+
job.add_log("executing: #{cmd}")
|
14
|
+
handle_error unless execute_using_popen3
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def handle_failure
|
20
|
+
job.update_attributes(ended_at: Time.now, status: :failed)
|
21
|
+
msg = "#{cmd} FAILED"
|
22
|
+
job.add_log(msg)
|
23
|
+
raise msg
|
24
|
+
end
|
25
|
+
|
26
|
+
# returns false if command fails
|
27
|
+
def execute_using_popen3
|
28
|
+
Open3.popen3(cmd) do |stdin, stdout, stderr, wait_thr|
|
29
|
+
while line = stdout.gets
|
30
|
+
job.add_log(line)
|
31
|
+
end
|
32
|
+
while line = stderr.gets
|
33
|
+
job.add_log(line)
|
34
|
+
end
|
35
|
+
|
36
|
+
exit_status = wait_thr.value
|
37
|
+
|
38
|
+
job.add_log("exist_status.success? is: #{exit_status.success?}")
|
39
|
+
job.add_log("index is: #{index}")
|
40
|
+
|
41
|
+
success = exit_status.success?
|
42
|
+
failure = !success
|
43
|
+
|
44
|
+
if failure && index == 1
|
45
|
+
cmd = "git remote add h#{branch_name} git@heroku.com:#{heroku_app_name}.git"
|
46
|
+
job.add_log(cmd)
|
47
|
+
return false unless system(cmd)
|
48
|
+
elsif failure && index != 1
|
49
|
+
return false
|
50
|
+
end
|
51
|
+
|
52
|
+
true
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Instapusher
|
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
|
+
`git config remote.origin.url`.chop!.scan(/\/([^\/]+).git$/).flatten.first
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -1,13 +1,13 @@
|
|
1
1
|
require 'rails/engine'
|
2
2
|
|
3
|
-
module
|
3
|
+
module Instapusher
|
4
4
|
class Engine < Rails::Engine
|
5
5
|
|
6
6
|
rake_tasks do
|
7
|
-
require '
|
7
|
+
require 'instapusher/commands'
|
8
8
|
|
9
9
|
desc "pushes to heroku"
|
10
|
-
task :
|
10
|
+
task :instapusher do
|
11
11
|
Instapusher::Commands.deploy
|
12
12
|
end
|
13
13
|
end
|
metadata
CHANGED
@@ -1,62 +1,69 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: instapusher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
|
+
prerelease:
|
5
6
|
platform: ruby
|
6
7
|
authors:
|
7
8
|
- Neeraj Singh
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date:
|
12
|
+
date: 2013-03-01 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: hashr
|
15
16
|
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
16
18
|
requirements:
|
17
|
-
- -
|
19
|
+
- - ~>
|
18
20
|
- !ruby/object:Gem::Version
|
19
21
|
version: 0.0.19
|
20
22
|
type: :runtime
|
21
23
|
prerelease: false
|
22
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
23
26
|
requirements:
|
24
|
-
- -
|
27
|
+
- - ~>
|
25
28
|
- !ruby/object:Gem::Version
|
26
29
|
version: 0.0.19
|
27
30
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
31
|
+
name: heroku
|
29
32
|
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
30
34
|
requirements:
|
31
|
-
- -
|
35
|
+
- - ~>
|
32
36
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
37
|
+
version: 2.25.0
|
34
38
|
type: :runtime
|
35
39
|
prerelease: false
|
36
40
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
37
42
|
requirements:
|
38
|
-
- -
|
43
|
+
- - ~>
|
39
44
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
45
|
+
version: 2.25.0
|
41
46
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
47
|
+
name: railties
|
43
48
|
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
44
50
|
requirements:
|
45
|
-
- - '>='
|
51
|
+
- - ! '>='
|
46
52
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
53
|
+
version: 3.1.0
|
48
54
|
type: :runtime
|
49
55
|
prerelease: false
|
50
56
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
51
58
|
requirements:
|
52
|
-
- - '>='
|
59
|
+
- - ! '>='
|
53
60
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
61
|
+
version: 3.1.0
|
55
62
|
description: instapusher makes it easy to push code to heroku
|
56
63
|
email:
|
57
64
|
- neeraj@bigbinary.com
|
58
65
|
executables:
|
59
|
-
-
|
66
|
+
- instapusher
|
60
67
|
extensions: []
|
61
68
|
extra_rdoc_files: []
|
62
69
|
files:
|
@@ -65,38 +72,44 @@ files:
|
|
65
72
|
- LICENSE
|
66
73
|
- README.md
|
67
74
|
- Rakefile
|
68
|
-
- bin/
|
75
|
+
- bin/instapusher
|
69
76
|
- instapusher.gemspec
|
70
|
-
- lib/
|
71
|
-
- lib/
|
72
|
-
- lib/
|
73
|
-
- lib/
|
74
|
-
- lib/
|
75
|
-
- lib/
|
76
|
-
- lib/
|
77
|
-
- lib/
|
78
|
-
- lib/instapusher2/version.rb
|
77
|
+
- lib/instapusher.rb
|
78
|
+
- lib/instapusher/base.rb
|
79
|
+
- lib/instapusher/command_builder.rb
|
80
|
+
- lib/instapusher/commands.rb
|
81
|
+
- lib/instapusher/executor.rb
|
82
|
+
- lib/instapusher/git.rb
|
83
|
+
- lib/instapusher/railtie.rb
|
84
|
+
- lib/instapusher/version.rb
|
79
85
|
homepage: http://bigbinary.com
|
80
86
|
licenses: []
|
81
|
-
metadata: {}
|
82
87
|
post_install_message:
|
83
88
|
rdoc_options: []
|
84
89
|
require_paths:
|
85
90
|
- lib
|
86
91
|
required_ruby_version: !ruby/object:Gem::Requirement
|
92
|
+
none: false
|
87
93
|
requirements:
|
88
|
-
- - '>='
|
94
|
+
- - ! '>='
|
89
95
|
- !ruby/object:Gem::Version
|
90
96
|
version: '0'
|
97
|
+
segments:
|
98
|
+
- 0
|
99
|
+
hash: -2089320010673045013
|
91
100
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
|
+
none: false
|
92
102
|
requirements:
|
93
|
-
- - '>='
|
103
|
+
- - ! '>='
|
94
104
|
- !ruby/object:Gem::Version
|
95
105
|
version: '0'
|
106
|
+
segments:
|
107
|
+
- 0
|
108
|
+
hash: -2089320010673045013
|
96
109
|
requirements: []
|
97
110
|
rubyforge_project:
|
98
|
-
rubygems_version:
|
111
|
+
rubygems_version: 1.8.23
|
99
112
|
signing_key:
|
100
|
-
specification_version:
|
113
|
+
specification_version: 3
|
101
114
|
summary: instapusher gem makes it easy to push code to heroku
|
102
115
|
test_files: []
|
checksums.yaml
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
---
|
2
|
-
SHA1:
|
3
|
-
metadata.gz: 7433c60ac1e70c23b055cb650bf71ba093cf9abf
|
4
|
-
data.tar.gz: 8d61b93297079ef691340adc607f213e52588657
|
5
|
-
SHA512:
|
6
|
-
metadata.gz: 01fd1afab40795944461e7453f05cdcdf508f5f607507ca6baaf81cc48c69d45683b6f4a4b026cb9d0f359921f325d69678fed3ab2e6a29869bd7579fbd10ea7
|
7
|
-
data.tar.gz: 7ef193a70158e245c84a13da8c87e4a6db15c5aeb7a8af6985358cd1594a7baba9f1b65e24a3d397966ca8553ad32e468f2f495995af3839d44d0e5fe4e69da8
|
data/bin/instapusher2
DELETED
@@ -1,40 +0,0 @@
|
|
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
|
data/lib/instapusher2.rb
DELETED
@@ -1,12 +0,0 @@
|
|
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
|
@@ -1,65 +0,0 @@
|
|
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
|
@@ -1,53 +0,0 @@
|
|
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
|
data/lib/instapusher2/git.rb
DELETED
@@ -1,31 +0,0 @@
|
|
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
|
@@ -1,54 +0,0 @@
|
|
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
|
@@ -1,21 +0,0 @@
|
|
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
|
@@ -1,25 +0,0 @@
|
|
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
|
data/lib/instapusher2/version.rb
DELETED