awspusher 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 70c118fbd016155d7712fe4ef46cecc55b9f2363
4
+ data.tar.gz: f13806bb8001708ec2aeb66400ead306720926b9
5
+ SHA512:
6
+ metadata.gz: 6705c1330f9618e2d75e4f64d138ed4f63f388b797ef1f1fa722949f3b63e38b976dd6dfc97f28f9438531604794bfd19119999016096d3f11d64aa3f2970310
7
+ data.tar.gz: 4aff5c871b02573cf97c76584d53b2c6afba7e47888f01f82948b1f63e759eb988970f9e1f4f8c2faa695ab97bfa15adc1f8af00ea78ef9934cf67f5c1bf010e
@@ -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
@@ -0,0 +1 @@
1
+ 2.1.5
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.
@@ -0,0 +1,28 @@
1
+ # AWSPusher
2
+
3
+ Makes it easy to push an application to heroku.
4
+
5
+ ### Installation
6
+
7
+ gem install awspusher
8
+
9
+ ## Setting up account
10
+
11
+ * Login at [awspusher.com](http://awspusher.com).
12
+ * Execute `awspusher --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
+ awspusher
21
+ ```
22
+
23
+ It detects project name and a branch from the git repo and starts deploying your project.
24
+
25
+
26
+ ### License
27
+
28
+ `awspusher` is released under MIT License.
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../lib/awspusher'
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("--local", "Hit localhost:3000") do |v|
15
+ options[:local] = v
16
+ end
17
+
18
+ opts.on("--staging", "Hit awspusher.net") do |v|
19
+ options[:staging] = 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", "Set AWSpusher api key") do |v|
27
+ options[:api_key] = v
28
+ end
29
+
30
+ end.parse!
31
+
32
+ if options[:version]
33
+ puts Awspusher::VERSION
34
+
35
+ elsif options[:api_key]
36
+ Awspusher::Configuration.ask_for_and_write_api_key
37
+
38
+ else
39
+ Awspusher::Commands.new(options).deploy
40
+ end
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/awspusher/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Neeraj Singh"]
6
+ gem.email = ["neeraj@bigbinary.com"]
7
+ gem.description = %q{AWSpusher makes it easy to deploy to EC2}
8
+ gem.summary = %q{AWSpusher gem makes it easy to deploy to EC2}
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 = "awspusher"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Awspusher::VERSION
17
+
18
+ gem.add_dependency("hashr", ">= 0.0.19")
19
+ gem.add_dependency("json")
20
+ end
@@ -0,0 +1,11 @@
1
+ require_relative './awspusher/git'
2
+ require_relative './awspusher/commands'
3
+ require_relative './awspusher/version'
4
+ require_relative './awspusher/configuration'
5
+ require_relative './awspusher/job_submission'
6
+ require_relative './awspusher/special_instruction_for_production'
7
+ require_relative './awspusher/tag_the_release'
8
+ require 'json'
9
+
10
+ module Awspusher
11
+ end
@@ -0,0 +1,88 @@
1
+ require_relative "../awspusher"
2
+ require 'net/http'
3
+ require 'uri'
4
+
5
+ module Awspusher
6
+ class Commands
7
+
8
+ attr_reader :debug, :api_key, :branch_name, :project_name, :staging, :local
9
+
10
+ def initialize init_options
11
+ @debug = init_options[:debug]
12
+ @staging = init_options[:staging]
13
+ @local = init_options[:local]
14
+ @branch_name = get_branch_name
15
+ @project_name = get_project_name
16
+
17
+ detect_api_key
18
+ end
19
+
20
+ def deploy
21
+ verify_api_key
22
+ #SpecialInstructionForProduction.new.run if production?
23
+
24
+ job_submission = JobSubmission.new(debug, job_submission_parameters)
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? || staging?)
30
+ else
31
+ puts job_submission.error_message
32
+ end
33
+ end
34
+
35
+ private
36
+
37
+ def job_submission_parameters
38
+ { project: project_name,
39
+ local: local,
40
+ branch: branch_name,
41
+ owner: repo_owner,
42
+ version: VERSION,
43
+ staging: staging,
44
+ api_key: api_key }
45
+ end
46
+
47
+ def repo_owner
48
+ git.repo_owner
49
+ end
50
+
51
+ def verify_api_key
52
+ if @api_key.to_s.length == 0
53
+ puts ''
54
+ abort "No awspusher API key was found. Please execute awspusher --api-key to setup awspusher API key."
55
+ end
56
+ end
57
+
58
+ def detect_api_key
59
+ @api_key = ENV['API_KEY'] || Awspusher::Configuration.api_key(debug) || ""
60
+ log "api_key is #{@api_key}"
61
+ end
62
+
63
+ def production?
64
+ branch_name.intern == :production
65
+ end
66
+
67
+ def staging?
68
+ branch_name.intern == :staging
69
+ end
70
+
71
+ def log msg
72
+ puts msg if debug
73
+ end
74
+
75
+ def get_branch_name
76
+ ENV['AWSPUSHER_BRANCH'] || git.current_branch
77
+ end
78
+
79
+ def get_project_name
80
+ ENV['AWSPUSHER_PROJECT'] || git.project_name
81
+ end
82
+
83
+ def git
84
+ @_git ||= Git.new
85
+ end
86
+
87
+ end
88
+ end
@@ -0,0 +1,58 @@
1
+ require 'yaml'
2
+
3
+ # used to read api_key
4
+ module Awspusher
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'], awspusher_file_name)
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 awspusher API key is available at http://www.awspusher.com/my/api_key"
27
+ puts ""
28
+ puts "Enter your AWSpusher 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
+ awspusher_config = {"api_key" => api_key}
36
+ File.open(File.join(Dir.home, awspusher_file_name), "w") do |file|
37
+ file.write awspusher_config.to_yaml
38
+ end
39
+
40
+ puts ""
41
+ puts "You are all set. Start using awspusher."
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
+
53
+ def awspusher_file_name
54
+ '.awspusher'
55
+ end
56
+
57
+ end
58
+ end
@@ -0,0 +1,59 @@
1
+ module Awspusher
2
+
3
+ class RepoOwnerIdentifierService
4
+
5
+ attr_reader :string
6
+
7
+ def initialize string
8
+ @string = string
9
+ end
10
+
11
+ def process
12
+ string.include?('git@github.com') ? handle_ssh_version : handle_https_version
13
+ end
14
+
15
+ private
16
+
17
+ def handle_ssh_version
18
+ regex = /.*:(.*)\/.*/
19
+ match_data = string.match(regex)
20
+ match_data.to_a.last
21
+ end
22
+
23
+ def handle_https_version
24
+ regex = /.*:\/\/github\.com\/(.*)\/.*/
25
+ match_data = string.match(regex)
26
+ match_data.to_a.last
27
+ end
28
+
29
+ end
30
+
31
+ class Git
32
+ def current_branch
33
+ result = %x{git branch}.split("\n")
34
+ if result.empty?
35
+ raise "It seems your app is not a git repository. Please check."
36
+ else
37
+ result.select { |b| b =~ /^\*/ }.first.split(" ").last.strip
38
+ end
39
+ end
40
+
41
+ def current_user
42
+ `git config user.name`.chop!
43
+ end
44
+
45
+ def project_name
46
+ result = `git config remote.origin.url`.chop!.scan(/\/([^\/]+)?$/).flatten.first
47
+ result.sub!(/\.git$/, '') if result
48
+ result ||= File.basename(Dir.getwd)
49
+ result
50
+ end
51
+
52
+ def repo_owner
53
+ string = `git remote -v | grep fetch | grep origin`
54
+ RepoOwnerIdentifierService.new(string).process
55
+ end
56
+
57
+ end
58
+ end
59
+
@@ -0,0 +1,71 @@
1
+ module Awspusher
2
+ class JobSubmission
3
+
4
+ attr_reader :options, :debug, :job_status_url, :response_body
5
+
6
+ DEFAULT_HOSTNAME = 'awspusher.com'
7
+
8
+ def initialize debug, options
9
+ @debug = debug
10
+ @options = options
11
+
12
+ log "options is #{options.inspect}"
13
+ end
14
+
15
+ def success?
16
+ job_status_url && job_status_url != ""
17
+ end
18
+
19
+ def pre_submission_feedback_to_user
20
+ log "url to hit: #{url_to_submit_job.inspect}"
21
+ log "options being passed to the url: #{options.inspect}"
22
+ log "connecting to #{url_to_submit_job} to send data"
23
+ end
24
+
25
+ def feedback_to_user
26
+ puts 'The application will be deployed to: ' + response_body['heroku_app_url']
27
+ puts 'Monitor the job status at: ' + job_status_url
28
+ cmd = "open #{job_status_url}"
29
+ `#{cmd}`
30
+ end
31
+
32
+ def error_message
33
+ response_body['error']
34
+ end
35
+
36
+ def submit_the_job
37
+ pre_submission_feedback_to_user
38
+
39
+ response = Net::HTTP.post_form URI.parse(url_to_submit_job), options
40
+ raw_body = response.body
41
+ log "response raw body: #{raw_body}"
42
+
43
+ @response_body = ::JSON.parse(raw_body)
44
+ log "JSON parsed response raw body: #{response_body.inspect}"
45
+ @job_status_url = response_body['status_url']
46
+ end
47
+
48
+ def url_to_submit_job
49
+ @url ||= begin
50
+ hostname = if options[:local]
51
+ "localhost:3000"
52
+ elsif options[:staging]
53
+ "awspusher.net"
54
+ else
55
+ ENV['AWSPUSHER_HOST'] || DEFAULT_HOSTNAME
56
+ end
57
+ protocol = use_ssl? ? 'https' : 'http'
58
+ "#{protocol}://#{hostname}/api/v1/jobs.json"
59
+ end
60
+ end
61
+
62
+ def use_ssl?
63
+ !(ENV['AWSPUSHER_HOST'] || options[:local])
64
+ end
65
+
66
+ def log msg
67
+ puts msg if debug
68
+ end
69
+
70
+ end
71
+ end
@@ -0,0 +1,16 @@
1
+ require 'rails/engine'
2
+
3
+ module Awspusher
4
+ class Engine < Rails::Engine
5
+
6
+ rake_tasks do
7
+ require 'awspusher/commands'
8
+
9
+ desc "pushes to heroku"
10
+ task :awspusher do
11
+ Awspusher::Commands.deploy
12
+ end
13
+ end
14
+
15
+ end
16
+ end
@@ -0,0 +1,21 @@
1
+ module Awspusher
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 Awspusher
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 Awspusher
2
+ VERSION = "1.0.0"
3
+ end
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: awspusher
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Neeraj Singh
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-09-05 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
+ description: AWSpusher makes it easy to deploy to EC2
42
+ email:
43
+ - neeraj@bigbinary.com
44
+ executables:
45
+ - awspusher
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".gitignore"
50
+ - ".ruby-version"
51
+ - Gemfile
52
+ - LICENSE
53
+ - README.md
54
+ - Rakefile
55
+ - bin/awspusher
56
+ - instapusher.gemspec
57
+ - lib/awspusher.rb
58
+ - lib/awspusher/commands.rb
59
+ - lib/awspusher/configuration.rb
60
+ - lib/awspusher/git.rb
61
+ - lib/awspusher/job_submission.rb
62
+ - lib/awspusher/railtie.rb
63
+ - lib/awspusher/special_instruction_for_production.rb
64
+ - lib/awspusher/tag_the_release.rb
65
+ - lib/awspusher/version.rb
66
+ homepage: http://bigbinary.com
67
+ licenses: []
68
+ metadata: {}
69
+ post_install_message:
70
+ rdoc_options: []
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ requirements: []
84
+ rubyforge_project:
85
+ rubygems_version: 2.4.8
86
+ signing_key:
87
+ specification_version: 4
88
+ summary: AWSpusher gem makes it easy to deploy to EC2
89
+ test_files: []