herkko 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: 879673de11ce7eb529e4356895103ed89a184a13
4
+ data.tar.gz: fc9394e4eb03e2e4e339d28951dc4445f775c54c
5
+ SHA512:
6
+ metadata.gz: 48b3fb77e95574d6ae9bb71968740eb895c9aaf6a548407d6ecf1c430a6ba76449f47112ffc1657787c3e4673674b84004d36f0b4cfc2f409d85f873719bdc4d
7
+ data.tar.gz: 2154638e81b8eccb4bfe9a15cc0ef6038e2dda666cb417ea9effedf36611594d36111a368511b8860f0e30ed613ab83ba56c244fc05bbedd432ece18f4124597
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in herkko.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Vesa Vänskä
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,34 @@
1
+ # Herkko
2
+
3
+ Herkko is a deployment tool for Heroku. It's highly opinionated and might not suit your needs. It has certain conventions you need to follow, but it also provides great user experience based on those conventions.
4
+
5
+ ## Installation
6
+
7
+ Install the gem with:
8
+
9
+ $ gem install herkko
10
+
11
+ ## Usage
12
+
13
+ Herkko uses the git remote names to identify the applications. Usually you have production and staging.
14
+
15
+ TODO: How to setup project for Herkko
16
+
17
+ ## Commands
18
+
19
+ deploy
20
+
21
+ You can add a file in `doc/after_deployment.{md, txt, rdoc, whatever}` and it
22
+ will be printed after a succesful deployment. It can have for example:
23
+
24
+ * Open the site in the browser and see that it loads.
25
+ * Stay alert for a while for exceptions.
26
+ * Inform the client if it is needed (Basecamp, email, SMS...)
27
+
28
+ ## Contributing
29
+
30
+ 1. Fork it ( https://github.com/vesan/herkko/fork )
31
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
32
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
33
+ 4. Push to the branch (`git push origin my-new-feature`)
34
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/bin/herkko ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.expand_path(File.join(File.dirname(__FILE__), "..", "lib", "herkko"))
4
+
5
+ Herkko::Runner.new(ARGV).run
6
+
data/herkko.gemspec ADDED
@@ -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 'herkko/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "herkko"
8
+ spec.version = Herkko::VERSION
9
+ spec.authors = ["Vesa Vänskä"]
10
+ spec.email = ["vesa@vesavanska.com"]
11
+ spec.summary = %q{Herkko is a deployment tool for Heroku.}
12
+ spec.description = %q{It's highly opinionated and might not suit your needs. It has certain conventions you need to follow, but it also provides great user experience based on those conventions.}
13
+ spec.homepage = "https://github.com/vesan/herkko"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ end
@@ -0,0 +1,114 @@
1
+ require "herkko/travis"
2
+ require "open3"
3
+
4
+ module Herkko
5
+ class Runner
6
+ attr_reader :environment, :command, :arguments
7
+
8
+ def initialize(argv)
9
+ argv.dup.tap do |arguments|
10
+ @environment = arguments.shift
11
+ @command = arguments.shift
12
+ @arguments = arguments unless arguments.empty?
13
+ end
14
+ end
15
+
16
+ def run
17
+ return print_usage if environment.nil? || command.nil?
18
+
19
+ if respond_to?(command)
20
+ send(command, *arguments)
21
+ else
22
+ Herkko.run_and_puts("heroku", arguments + ["-r#{environment}"])
23
+ end
24
+ end
25
+
26
+ def print_usage
27
+ Herkko.info "TODO: Usage instructions"
28
+ end
29
+
30
+ def deploy
31
+ Herkko.info "Doing deployment to #{environment}..."
32
+ fetch_currently_deployed_version
33
+
34
+ Herkko.info("Deploying changes:")
35
+
36
+ puts changelog
37
+
38
+ if check_ci == :green
39
+ Herkko.info "CI is green. Deploying..."
40
+
41
+ run_migrations = migrations_needed?
42
+ push_new_code
43
+
44
+ if run_migrations
45
+ migrate
46
+ else
47
+ Herkko.info "No need to migrate."
48
+ end
49
+
50
+ if seed_file_changed?
51
+ Herkko.info "NOTE: Seed file seem the have changed. Make sure to run it if needed."
52
+ end
53
+
54
+ # TODO: puts "Print the after deployment checklist from a file"
55
+ else
56
+ Herkko.info "CI is red. Fix it!"
57
+ end
58
+ end
59
+
60
+ def check_ci
61
+ Herkko.info "Checking CI..."
62
+ Herkko::Travis.status_for(current_branch)
63
+ end
64
+
65
+ def migrate
66
+ Herkko.info "Migrating database..."
67
+ Herkko.run_and_puts %{
68
+ heroku run rake db:migrate -r #{environment} &&
69
+ heroku restart -r #{environment}
70
+ }
71
+ end
72
+
73
+ def push_new_code
74
+ Herkko.info "Pushing code to Heroku..."
75
+ Herkko.run_and_puts("git", "push", environment)
76
+ end
77
+
78
+ private
79
+
80
+ def current_branch
81
+ Herkko.run("git", "rev-parse", "--abbrev-ref", "HEAD")[0].strip
82
+ end
83
+
84
+ def migrations_needed?
85
+ file_changed?("db/migrate")
86
+ end
87
+
88
+ def seed_file_changed?
89
+ file_changed?("db/seeds.rb")
90
+ end
91
+
92
+ def currently_deployed_to(environment)
93
+ Herkko.run("git", "rev-parse", "#{environment}/master")[0].strip
94
+ end
95
+
96
+ def to_be_deployed_sha
97
+ Herkko.run("git", "rev-parse", "HEAD")[0].strip
98
+ end
99
+
100
+ def file_changed?(file_path)
101
+ files = Herkko.run("git", "diff", "--name-only", currently_deployed_to(environment), to_be_deployed_sha)[0]
102
+
103
+ files.split("\n").any? {|filename| filename.match(Regex.new(file_path)) }
104
+ end
105
+
106
+ def fetch_currently_deployed_version
107
+ Herkko.run_and_puts("git", "fetch", environment)
108
+ end
109
+
110
+ def changelog
111
+ Herkko.run("git", "log", "--name-only", "#{currently_deployed_to(environment)}..#{to_be_deployed_sha}")[0]
112
+ end
113
+ end
114
+ end
@@ -0,0 +1,25 @@
1
+ # travis login --pro
2
+ # travis history -l1 -bmaster
3
+ module Herkko
4
+ class Travis
5
+ def self.status_for(branch)
6
+ status = fetch_status(branch)
7
+ if status[1].length > 0
8
+ Herkko.info "There was an error with checking Travis: #{status[1]}"
9
+ :red
10
+ else
11
+ if status[0].match(/passed/)
12
+ :green
13
+ else
14
+ :red
15
+ end
16
+ end
17
+ end
18
+
19
+ private
20
+
21
+ def self.fetch_status(branch)
22
+ Herkko.run("travis", "history", "-l", "1", "-b", branch)
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,3 @@
1
+ module Herkko
2
+ VERSION = "0.0.1"
3
+ end
data/lib/herkko.rb ADDED
@@ -0,0 +1,26 @@
1
+ require "herkko/version"
2
+ require "herkko/runner"
3
+
4
+ module Herkko
5
+ @@debug = false
6
+
7
+ def self.info(text)
8
+ puts "-> " + text
9
+ end
10
+
11
+ def self.run(*command)
12
+ if @@debug
13
+ puts "--> #{command.join(" ")}"
14
+ end
15
+
16
+ Open3.capture3(*command)
17
+ end
18
+
19
+ def self.run_and_puts(*command)
20
+ if @@debug
21
+ puts "--> #{command.join(" ")}"
22
+ end
23
+
24
+ Kernel.system(*command)
25
+ end
26
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: herkko
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Vesa Vänskä
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: It's highly opinionated and might not suit your needs. It has certain
42
+ conventions you need to follow, but it also provides great user experience based
43
+ on those conventions.
44
+ email:
45
+ - vesa@vesavanska.com
46
+ executables:
47
+ - herkko
48
+ extensions: []
49
+ extra_rdoc_files: []
50
+ files:
51
+ - ".gitignore"
52
+ - Gemfile
53
+ - LICENSE.txt
54
+ - README.md
55
+ - Rakefile
56
+ - bin/herkko
57
+ - herkko.gemspec
58
+ - lib/herkko.rb
59
+ - lib/herkko/runner.rb
60
+ - lib/herkko/travis.rb
61
+ - lib/herkko/version.rb
62
+ homepage: https://github.com/vesan/herkko
63
+ licenses:
64
+ - MIT
65
+ metadata: {}
66
+ post_install_message:
67
+ rdoc_options: []
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubyforge_project:
82
+ rubygems_version: 2.2.2
83
+ signing_key:
84
+ specification_version: 4
85
+ summary: Herkko is a deployment tool for Heroku.
86
+ test_files: []